Skip to content

Commit

Permalink
Reset cookie policy in test (JabRef#7452)
Browse files Browse the repository at this point in the history
Sets a new system-wide cookie manager if there is none, and sets the cookie policy
to ACCEPT_NONE after each test.
  • Loading branch information
kittytinythai authored and grundb committed Mar 4, 2021
1 parent 85e8f8d commit 0f5a819
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 0f5a819

Please sign in to comment.