-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BibEntryRelationsRepositoryTest (#10983)
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
.../java/org/jabref/gui/entryeditor/citationrelationtab/BibEntryRelationsRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.jabref.gui.entryeditor.citationrelationtab; | ||
|
||
import java.util.List; | ||
|
||
import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.SemanticScholarFetcher; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.StandardField; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class BibEntryRelationsRepositoryTest { | ||
|
||
private List<BibEntry> getCitedBy(BibEntry entry) { | ||
return List.of(createCitingBibEntry(entry)); | ||
} | ||
|
||
private BibEntry createBibEntry(int i) { | ||
return new BibEntry() | ||
.withCitationKey("entry" + i) | ||
.withField(StandardField.DOI, "10.1234/5678" + i); | ||
} | ||
|
||
private BibEntry createCitingBibEntry(Integer i) { | ||
return new BibEntry() | ||
.withCitationKey("citing_entry" + i) | ||
.withField(StandardField.DOI, "10.2345/6789" + i); | ||
} | ||
|
||
private BibEntry createCitingBibEntry(BibEntry citedEntry) { | ||
return createCitingBibEntry(Integer.valueOf(citedEntry.getCitationKey().get().substring(5))); | ||
} | ||
|
||
@Test | ||
void getCitations() throws Exception { | ||
SemanticScholarFetcher semanticScholarFetcher = mock(SemanticScholarFetcher.class); | ||
when(semanticScholarFetcher.searchCitedBy(any(BibEntry.class))).thenAnswer(invocation -> { | ||
BibEntry entry = invocation.getArgument(0); | ||
return getCitedBy(entry); | ||
}); | ||
BibEntryRelationsCache bibEntryRelationsCache = new BibEntryRelationsCache(); | ||
|
||
BibEntryRelationsRepository bibEntryRelationsRepository = new BibEntryRelationsRepository(semanticScholarFetcher, bibEntryRelationsCache); | ||
|
||
for (int i = 0; i < 150; i++) { | ||
BibEntry entry = createBibEntry(i); | ||
List<BibEntry> citations = bibEntryRelationsRepository.getCitations(entry); | ||
assertEquals(getCitedBy(entry), citations); | ||
} | ||
|
||
for (int i = 0; i < 150; i++) { | ||
BibEntry entry = createBibEntry(i); | ||
List<BibEntry> citations = bibEntryRelationsRepository.getCitations(entry); | ||
assertEquals(getCitedBy(entry), citations); | ||
} | ||
} | ||
} |