From 0f5a81905681af39f5c712b103e397038985c280 Mon Sep 17 00:00:00 2001 From: kittyt Date: Wed, 3 Mar 2021 16:22:57 +0100 Subject: [PATCH] Reset cookie policy in test (#7452) Sets a new system-wide cookie manager if there is none, and sets the cookie policy to ACCEPT_NONE after each test. --- .../gui/fieldeditors/LinkedFileViewModelTest.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java b/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java index 7417ebc248e..b13b19bd46e 100644 --- a/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java +++ b/src/test/java/org/jabref/gui/fieldeditors/LinkedFileViewModelTest.java @@ -56,6 +56,7 @@ class LinkedFileViewModelTest { private final ExternalFileTypes externalFileType = mock(ExternalFileTypes.class); private final FilePreferences filePreferences = mock(FilePreferences.class); private final XmpPreferences xmpPreferences = mock(XmpPreferences.class); + private CookieManager cookieManager; @BeforeEach void setUp(@TempDir Path tempFolder) throws Exception { @@ -73,14 +74,19 @@ void setUp(@TempDir Path tempFolder) throws Exception { tempFile = tempFolder.resolve("temporaryFile"); Files.createFile(tempFile); - CookieManager cookieManager = new CookieManager(); - CookieHandler.setDefault(cookieManager); + // Check if there exists a system wide cookie handler + if (CookieHandler.getDefault() == null) { + cookieManager = new CookieManager(); + CookieHandler.setDefault(cookieManager); + } else { + cookieManager = (CookieManager) CookieHandler.getDefault(); + } cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); } @AfterEach void tearDown() { - CookieManager.setDefault(null); + cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_NONE); } @Test @@ -211,7 +217,7 @@ void downloadDoesNotOverwriteFileTypeExtension() throws MalformedURLException { } @Test - void downloadHtmlWhenLinkedFilePointsToHtml(@TempDir Path tempDir) throws MalformedURLException{ + void downloadHtmlWhenLinkedFilePointsToHtml() throws MalformedURLException{ // the link mentioned in issue #7452 String url = "https://onlinelibrary.wiley.com/doi/abs/10.1002/0470862106.ia615"; String fileType = StandardExternalFileType.URL.getName();