diff --git a/src/main/java/org/jabref/logic/importer/FulltextFetchers.java b/src/main/java/org/jabref/logic/importer/FulltextFetchers.java index a7579573dac..57ad3f6c187 100644 --- a/src/main/java/org/jabref/logic/importer/FulltextFetchers.java +++ b/src/main/java/org/jabref/logic/importer/FulltextFetchers.java @@ -28,6 +28,8 @@ /** * Utility class for trying to resolve URLs to full-text PDF for articles. + * + * Combines multiple {@link FulltextFetcher}s together. Each fetcher is invoked, the "best" result (sorted by the fetcher trust level) is returned. */ public class FulltextFetchers { private static final Logger LOGGER = LoggerFactory.getLogger(FulltextFetchers.class); @@ -59,7 +61,7 @@ public Optional findFullTextPDF(BibEntry entry) { BibEntry clonedEntry = (BibEntry) entry.clone(); Optional doi = clonedEntry.getField(StandardField.DOI).flatMap(DOI::parse); - if (!doi.isPresent()) { + if (doi.isEmpty()) { findDoiForEntry(clonedEntry); } diff --git a/src/test/java/org/jabref/logic/importer/FulltextFetchersTest.java b/src/test/java/org/jabref/logic/importer/FulltextFetchersTest.java index 724c0b52c80..47308002d0b 100644 --- a/src/test/java/org/jabref/logic/importer/FulltextFetchersTest.java +++ b/src/test/java/org/jabref/logic/importer/FulltextFetchersTest.java @@ -8,10 +8,9 @@ import org.jabref.logic.importer.fetcher.TrustLevel; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; import org.jabref.testutils.category.FetcherTest; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -20,17 +19,8 @@ @FetcherTest public class FulltextFetchersTest { - private BibEntry entry; - @BeforeEach - public void setUp() { - entry = new BibEntry(); - } - - @AfterEach - public void tearDown() { - entry = null; - } + private BibEntry entry = new BibEntry(); @Test public void acceptPdfUrls() throws MalformedURLException { @@ -60,18 +50,21 @@ public void noTrustLevel() throws MalformedURLException { @Test public void higherTrustLevelWins() throws IOException, FetcherException { - final URL lowUrl = new URL("http://docs.oasis-open.org/opencsa/sca-bpel/sca-bpel-1.1-spec-cd-01.pdf"); + FulltextFetcher finderHigh = mock(FulltextFetcher.class); + when(finderHigh.getTrustLevel()).thenReturn(TrustLevel.SOURCE); final URL highUrl = new URL("http://docs.oasis-open.org/wsbpel/2.0/OS/wsbpel-v2.0-OS.pdf"); + when(finderHigh.findFullText(entry)).thenReturn(Optional.of(highUrl)); - FulltextFetcher finderHigh = mock(FulltextFetcher.class); FulltextFetcher finderLow = mock(FulltextFetcher.class); - when(finderHigh.getTrustLevel()).thenReturn(TrustLevel.SOURCE); when(finderLow.getTrustLevel()).thenReturn(TrustLevel.UNKNOWN); - when(finderHigh.findFullText(entry)).thenReturn(Optional.of(highUrl)); + final URL lowUrl = new URL("http://docs.oasis-open.org/opencsa/sca-bpel/sca-bpel-1.1-spec-cd-01.pdf"); when(finderLow.findFullText(entry)).thenReturn(Optional.of(lowUrl)); FulltextFetchers fetcher = new FulltextFetchers(Set.of(finderLow, finderHigh)); + // set an (arbitrary) DOI to the test entry to skip side effects inside the "findFullTextPDF" method + entry.setField(StandardField.DOI, "10.5220/0007903201120130"); + assertEquals(Optional.of(highUrl), fetcher.findFullTextPDF(entry)); } }