Skip to content

Commit

Permalink
Add tests for getCoverImage in BibEntryTest
Browse files Browse the repository at this point in the history
  • Loading branch information
damgam0288 committed Nov 30, 2024
1 parent 80cdf05 commit b85aab9
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions src/test/java/org/jabref/model/entry/BibEntryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -820,14 +820,76 @@ void getCoverImageReturnsCorrectImage() {
LinkedFile cover2 = new LinkedFile("", Paths.get("JabRef-icon-64.png"), "PNG image");
LinkedFile cover3 = new LinkedFile("cover", Paths.get("wallpaper.jpg"), "JPG image");
BibEntry entry = new BibEntry(StandardEntryType.Book).withField(StandardField.AUTHOR, "value");

entry.addFile(cover1);
entry.addFile(cover2);
entry.addFile(cover3);

assertEquals(Optional.of(cover3), entry.getCoverImageFile());
}

@Test
void getCoverImageReturnsEmptyIfNoFiles() {
entry = new BibEntry(StandardEntryType.Book).withField(StandardField.AUTHOR, "value");
assertEquals(Optional.empty(), entry.getCoverImageFile());
}

@Test
void getCoverImageReturnsEmptyIfNoImageFiles() {
LinkedFile pdf = new LinkedFile("", Paths.get("Baldoni2002.pdf").toAbsolutePath().toString(), "pdf");
LinkedFile markdown = new LinkedFile("", "readme.md", "md");
entry = new BibEntry(StandardEntryType.Book).withField(StandardField.AUTHOR, "value");
entry.addFile(markdown);
entry.addFile(pdf);
assertEquals(Optional.empty(), entry.getCoverImageFile());
}

@ParameterizedTest
@MethodSource("nonCoverableEntryTypes")
void getCoverImageReturnsEmptyIfEntryIsNotCoverable(StandardEntryType entryType) {
BibEntry entry = new BibEntry(entryType).withField(StandardField.AUTHOR, "value");
assertEquals(Optional.empty(), entry.getCoverImageFile());
}

static Stream<StandardEntryType> nonCoverableEntryTypes() {
return Stream.of(
StandardEntryType.Proceedings,
StandardEntryType.Dataset,
StandardEntryType.Software
);
}

@ParameterizedTest
@MethodSource("imagesWithoutCoverDescription")
void getCoverImageDoesNotReturnImagesWithoutCoverDescription(LinkedFile image) {
entry = new BibEntry(StandardEntryType.Book).withField(StandardField.AUTHOR, "value");
entry.addFile(image);
assertEquals(Optional.empty(), entry.getCoverImageFile());
}

static Stream<LinkedFile> imagesWithoutCoverDescription() {
return Stream.of(
new LinkedFile("", Paths.get("JabRef-icon-128.png"), "PNG image"),
new LinkedFile("", Paths.get("JabRef-icon-64.png"), "PNG image"),
new LinkedFile("", Paths.get("JabRef-icon-32.png"), "PNG image")
);
}

@ParameterizedTest
@MethodSource("docsWithCoverDescription")
void getCoverImageDoesNotReturnDocumentsWithCoverDescription(LinkedFile file) {
entry = new BibEntry(StandardEntryType.Book).withField(StandardField.AUTHOR, "value");
entry.addFile(file);
assertEquals(Optional.empty(), entry.getCoverImageFile());
}

static Stream<LinkedFile> docsWithCoverDescription() {
return Stream.of(
new LinkedFile("cover", Paths.get("Baldoni2002.pdf"), "pdf"),
new LinkedFile("cover", Paths.get("readme.md"), "md"),
new LinkedFile("cover", Paths.get("BiblioscapeImporterTestArticleST.txt"), "txt"),
new LinkedFile("cover", Paths.get("emptyFile.xml"), "xml")
);
}

public static Stream<BibEntry> isEmpty() {
return Stream.of(
new BibEntry(),
Expand Down

0 comments on commit b85aab9

Please sign in to comment.