-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Citations Relations Tab (#11189)
* Move repository, cache, and fetcher to logic package * Move citations model to model/citations/semanticscholar package
- Loading branch information
1 parent
e395853
commit 3785cb1
Showing
15 changed files
with
159 additions
and
91 deletions.
There are no files selected for viewing
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
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
6 changes: 2 additions & 4 deletions
6
...onrelationtab/BibEntryRelationsCache.java → ...on/repository/BibEntryRelationsCache.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
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
2 changes: 1 addition & 1 deletion
2
...ntab/semanticscholar/CitationFetcher.java → ...gic/importer/fetcher/CitationFetcher.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
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
2 changes: 1 addition & 1 deletion
2
...ontab/semanticscholar/AuthorResponse.java → ...ation/semanticscholar/AuthorResponse.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
2 changes: 1 addition & 1 deletion
2
...tab/semanticscholar/CitationDataItem.java → ...ion/semanticscholar/CitationDataItem.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
2 changes: 1 addition & 1 deletion
2
...ab/semanticscholar/CitationsResponse.java → ...on/semanticscholar/CitationsResponse.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
2 changes: 1 addition & 1 deletion
2
...tiontab/semanticscholar/PaperDetails.java → ...itation/semanticscholar/PaperDetails.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
2 changes: 1 addition & 1 deletion
2
...ab/semanticscholar/ReferenceDataItem.java → ...on/semanticscholar/ReferenceDataItem.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
2 changes: 1 addition & 1 deletion
2
...b/semanticscholar/ReferencesResponse.java → ...n/semanticscholar/ReferencesResponse.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
61 changes: 0 additions & 61 deletions
61
.../java/org/jabref/gui/entryeditor/citationrelationtab/BibEntryRelationsRepositoryTest.java
This file was deleted.
Oops, something went wrong.
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
128 changes: 128 additions & 0 deletions
128
src/test/java/org/jabref/logic/citation/repository/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,128 @@ | ||
package org.jabref.logic.citation.repository; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
import java.util.function.Function; | ||
import java.util.stream.IntStream; | ||
import java.util.stream.Stream; | ||
import org.jabref.logic.importer.FetcherException; | ||
import org.jabref.logic.importer.fetcher.CitationFetcher; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.StandardField; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
class BibEntryRelationsRepositoryTest { | ||
|
||
private static Stream<BibEntry> createBibEntries() { | ||
return IntStream | ||
.range(0, 150) | ||
.mapToObj(BibEntryRelationsRepositoryTest::createBibEntry); | ||
} | ||
|
||
private static List<BibEntry> getCitedBy(BibEntry entry) { | ||
return List.of(BibEntryRelationsRepositoryTest.createCitingBibEntry(entry)); | ||
} | ||
|
||
private static BibEntry createBibEntry(int i) { | ||
return new BibEntry() | ||
.withCitationKey("entry" + i) | ||
.withField(StandardField.DOI, "10.1234/5678" + i); | ||
} | ||
|
||
private static BibEntry createCitingBibEntry(Integer i) { | ||
return new BibEntry() | ||
.withCitationKey("citing_entry" + i) | ||
.withField(StandardField.DOI, "10.2345/6789" + i); | ||
} | ||
|
||
private static BibEntry createCitingBibEntry(BibEntry citedEntry) { | ||
return createCitingBibEntry( | ||
Integer.valueOf(citedEntry.getCitationKey().orElseThrow().substring(5)) | ||
); | ||
} | ||
|
||
/** | ||
* Simple mock to avoid using Mockito (reduce overall complexity) | ||
*/ | ||
private record CitationFetcherMock( | ||
Function<BibEntry, List<BibEntry>> searchCiteByDelegate, | ||
Function<BibEntry, List<BibEntry>> searchCitingDelegate, | ||
String name | ||
) implements CitationFetcher { | ||
|
||
@Override | ||
public List<BibEntry> searchCitedBy(BibEntry entry) throws FetcherException { | ||
return this.searchCiteByDelegate.apply(entry); | ||
} | ||
|
||
@Override | ||
public List<BibEntry> searchCiting(BibEntry entry) throws FetcherException { | ||
return this.searchCitingDelegate.apply(entry); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return this.name; | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("createBibEntries") | ||
@DisplayName( | ||
"Given a new bib entry when reading citations for it should call the fetcher" | ||
) | ||
void givenANewEntryWhenReadingCitationsForItShouldCallTheFetcher(BibEntry bibEntry) { | ||
// GIVEN | ||
var entryCaptor = new HashSet<BibEntry>(); | ||
var citationFetcherMock = new CitationFetcherMock( | ||
entry -> { | ||
entryCaptor.add(entry); | ||
return BibEntryRelationsRepositoryTest.getCitedBy(entry); | ||
}, | ||
null, | ||
null | ||
); | ||
var bibEntryRelationsCache = new BibEntryRelationsCache(); | ||
var bibEntryRelationsRepository = new BibEntryRelationsRepository( | ||
citationFetcherMock, bibEntryRelationsCache | ||
); | ||
|
||
// WHEN | ||
var citations = bibEntryRelationsRepository.getCitations(bibEntry); | ||
|
||
// THEN | ||
Assertions.assertFalse(citations.isEmpty()); | ||
Assertions.assertTrue(entryCaptor.contains(bibEntry)); | ||
} | ||
|
||
@Test | ||
@DisplayName( | ||
"Given an empty cache for a valid entry when reading the citations should populate cache" | ||
) | ||
void givenAnEmptyCacheAndAValidBibEntryWhenReadingCitationsShouldPopulateTheCache() { | ||
// GIVEN | ||
var citationFetcherMock = new CitationFetcherMock( | ||
BibEntryRelationsRepositoryTest::getCitedBy, null, null | ||
); | ||
var bibEntryRelationsCache = new BibEntryRelationsCache(); | ||
var bibEntryRelationsRepository = new BibEntryRelationsRepository( | ||
citationFetcherMock, bibEntryRelationsCache | ||
); | ||
var bibEntry = BibEntryRelationsRepositoryTest.createBibEntry(1); | ||
|
||
// WHEN | ||
Assertions.assertEquals(List.of(), bibEntryRelationsCache.getCitations(bibEntry)); | ||
var citations = bibEntryRelationsRepository.getCitations(bibEntry); | ||
var fromCacheCitations = bibEntryRelationsCache.getCitations(bibEntry); | ||
|
||
// THEN | ||
Assertions.assertFalse(fromCacheCitations.isEmpty()); | ||
Assertions.assertEquals(citations, fromCacheCitations); | ||
} | ||
} |