Skip to content

Commit

Permalink
Fix test "higherTrustLevelWins()" (#7866)
Browse files Browse the repository at this point in the history
Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
Co-authored-by: Benedikt Tutzer <btut@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 1, 2021
1 parent fc54b2d commit be41c40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -59,7 +61,7 @@ public Optional<URL> findFullTextPDF(BibEntry entry) {
BibEntry clonedEntry = (BibEntry) entry.clone();
Optional<DOI> doi = clonedEntry.getField(StandardField.DOI).flatMap(DOI::parse);

if (!doi.isPresent()) {
if (doi.isEmpty()) {
findDoiForEntry(clonedEntry);
}

Expand Down
25 changes: 9 additions & 16 deletions src/test/java/org/jabref/logic/importer/FulltextFetchersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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));
}
}

0 comments on commit be41c40

Please sign in to comment.