From fd3d2f5fd7ea3f060ab22bfdaa6a4c1104a36aee Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 7 Sep 2024 19:54:54 +0200 Subject: [PATCH 1/2] Refine ACS test code --- .../logic/importer/fetcher/ACSTest.java | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ACSTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ACSTest.java index 2552b5cc735..dca2cb16424 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ACSTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ACSTest.java @@ -1,56 +1,47 @@ package org.jabref.logic.importer.fetcher; -import java.io.IOException; import java.net.URL; import java.util.Optional; +import org.jabref.logic.importer.FulltextFetcher; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.support.DisabledOnCIServer; import org.jabref.testutils.category.FetcherTest; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @FetcherTest class ACSTest { - private ACS finder; - private BibEntry entry; - - @BeforeEach - void setUp() { - finder = new ACS(); - entry = new BibEntry(); - } + private FulltextFetcher fetcher = new ACS(); @Test @DisabledOnCIServer("CI server is unreliable") - void findByDOI() throws IOException { - entry.setField(StandardField.DOI, "10.1021/bk-2006-STYG.ch014"); - + void findByDOI() throws Exception { + // DOI randomly chosen from https://pubs.acs.org/toc/acscii/0/0 + BibEntry entry = new BibEntry().withField(StandardField.DOI, "10.1021/acscentsci.4c00971"); assertEquals( - Optional.of(new URL("https://pubs.acs.org/doi/pdf/10.1021/bk-2006-STYG.ch014")), - finder.findFullText(entry) + Optional.of(new URL("https://pubs.acs.org/doi/pdf/10.1021/acscentsci.4c00971")), + fetcher.findFullText(entry) ); } @Test @DisabledOnCIServer("CI server is unreliable") - void notFoundByDOI() throws IOException { - entry.setField(StandardField.DOI, "10.1021/bk-2006-WWW.ch014"); - - assertEquals(Optional.empty(), finder.findFullText(entry)); + void notFoundByDOI() throws Exception { + BibEntry entry = new BibEntry().withField(StandardField.DOI, "10.1021/bk-2006-WWW.ch014"); + assertEquals(Optional.empty(), fetcher.findFullText(entry)); } @Test - void entityWithoutDoi() throws IOException { - assertEquals(Optional.empty(), finder.findFullText(entry)); + void entityWithoutDoi() throws Exception { + assertEquals(Optional.empty(), fetcher.findFullText(new BibEntry())); } @Test void trustLevel() { - assertEquals(TrustLevel.PUBLISHER, finder.getTrustLevel()); + assertEquals(TrustLevel.PUBLISHER, fetcher.getTrustLevel()); } } From f1a8ecbe4db4a7fa6dd52234033c91eddd88007b Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 7 Sep 2024 20:03:22 +0200 Subject: [PATCH 2/2] Minor improvements --- build.gradle | 2 ++ src/main/java/module-info.java | 6 +++--- src/main/java/org/jabref/logic/importer/fetcher/ACS.java | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index fd199a8b667..9bd82d66fb8 100644 --- a/build.gradle +++ b/build.gradle @@ -255,10 +255,12 @@ dependencies { implementation 'org.controlsfx:controlsfx:11.2.1' + // region HTTP clients implementation 'org.jsoup:jsoup:1.18.1' implementation 'com.konghq:unirest-java-core:4.4.4' implementation 'com.konghq:unirest-modules-gson:4.4.4' implementation 'org.apache.httpcomponents.client5:httpclient5:5.3.1' + // endregion implementation 'org.slf4j:slf4j-api:2.0.16' implementation 'org.tinylog:tinylog-api:2.7.0' diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 040717bf907..2c5685ffe5e 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -89,11 +89,11 @@ // dependency injection using HK2 requires org.glassfish.hk2.api; - // region: http clients - requires unirest.java.core; - requires unirest.modules.gson; + // region HTTP clients requires org.apache.httpcomponents.core5.httpcore5; requires org.jsoup; + requires unirest.java.core; + requires unirest.modules.gson; // endregion // region: SQL databases diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ACS.java b/src/main/java/org/jabref/logic/importer/fetcher/ACS.java index 3c81d89db2a..e185b6fece2 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ACS.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ACS.java @@ -17,7 +17,7 @@ import org.slf4j.LoggerFactory; /** - * FulltextFetcher implementation that attempts to find a PDF URL at ACS. + * FulltextFetcher implementation that attempts to find a PDF URL at ACS. */ public class ACS implements FulltextFetcher { private static final Logger LOGGER = LoggerFactory.getLogger(ACS.class);