diff --git a/src/test/java/org/jabref/model/entry/BibEntryTest.java b/src/test/java/org/jabref/model/entry/BibEntryTest.java index e228c79f387..3dbd7f28741 100644 --- a/src/test/java/org/jabref/model/entry/BibEntryTest.java +++ b/src/test/java/org/jabref/model/entry/BibEntryTest.java @@ -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 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 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 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 isEmpty() { return Stream.of( new BibEntry(),