From dbb986e729dac4a1ed571a91bed10d31285f01a6 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 31 Mar 2025 23:07:09 +0200 Subject: [PATCH 1/4] Disable test not working on Windows --- .../gui/linkedfile/LinkedFileEditDialogViewModelTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/gui/linkedfile/LinkedFileEditDialogViewModelTest.java b/src/test/java/org/jabref/gui/linkedfile/LinkedFileEditDialogViewModelTest.java index d19c5d9cbb0..7ef06876ed2 100644 --- a/src/test/java/org/jabref/gui/linkedfile/LinkedFileEditDialogViewModelTest.java +++ b/src/test/java/org/jabref/gui/linkedfile/LinkedFileEditDialogViewModelTest.java @@ -16,6 +16,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.api.io.TempDir; import org.mockito.Answers; @@ -39,8 +41,8 @@ void setup() { } @Test + @DisabledOnOs(value = OS.WINDOWS, disabledReason = "? is an invalid filename character in Windows") void badFilenameCharWillBeReplacedByUnderscore(@TempDir Path tempDir) throws Exception { - Path invalidFile = tempDir.resolve("?invalid.pdf"); Files.createFile(invalidFile); when(dialogService.showConfirmationDialogAndWait(any(), any(), any())).thenReturn(true); From a10d7e4933a70b3cefdac4c982b09ab02e57ec29 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 31 Mar 2025 23:07:28 +0200 Subject: [PATCH 2/4] Use withers --- .../indexing/LinkedFilesIndexerTest.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/test/java/org/jabref/logic/search/indexing/LinkedFilesIndexerTest.java b/src/test/java/org/jabref/logic/search/indexing/LinkedFilesIndexerTest.java index 220f53d4bf3..2419fd7f080 100644 --- a/src/test/java/org/jabref/logic/search/indexing/LinkedFilesIndexerTest.java +++ b/src/test/java/org/jabref/logic/search/indexing/LinkedFilesIndexerTest.java @@ -48,8 +48,8 @@ void setUp(@TempDir Path indexDir) throws IOException { @Test void exampleThesisIndex() throws IOException { // given - BibEntry entry = new BibEntry(StandardEntryType.PhdThesis); - entry.setFiles(Collections.singletonList(new LinkedFile("Example Thesis", "thesis-example.pdf", StandardFileType.PDF.getName()))); + BibEntry entry = new BibEntry(StandardEntryType.PhdThesis) + .withFiles(List.of(new LinkedFile("Example Thesis", "thesis-example.pdf", StandardFileType.PDF.getName()))); // when indexer.addToIndex(List.of(entry), mock(BackgroundTask.class)); @@ -64,8 +64,8 @@ void exampleThesisIndex() throws IOException { @Test void dontIndexNonPdf() throws IOException { // given - BibEntry entry = new BibEntry(StandardEntryType.PhdThesis); - entry.setFiles(Collections.singletonList(new LinkedFile("Example Thesis", "thesis-example.pdf", StandardFileType.AUX.getName()))); + BibEntry entry = new BibEntry(StandardEntryType.PhdThesis) + .withFiles(List.of(new LinkedFile("Example Thesis", "thesis-example.pdf", StandardFileType.AUX.getName()))); // when indexer.addToIndex(List.of(entry), mock(BackgroundTask.class)); @@ -80,8 +80,8 @@ void dontIndexNonPdf() throws IOException { @Test void dontIndexOnlineLinks() throws IOException { // given - BibEntry entry = new BibEntry(StandardEntryType.PhdThesis); - entry.setFiles(Collections.singletonList(new LinkedFile("Example Thesis", "https://raw.githubusercontent.com/JabRef/jabref/main/src/test/resources/pdfs/thesis-example.pdf", StandardFileType.PDF.getName()))); + BibEntry entry = new BibEntry(StandardEntryType.PhdThesis) + .withFiles(List.of(new LinkedFile("Example Thesis", "https://raw.githubusercontent.com/JabRef/jabref/main/src/test/resources/pdfs/thesis-example.pdf", StandardFileType.PDF.getName()))); // when indexer.addToIndex(List.of(entry), mock(BackgroundTask.class)); @@ -96,9 +96,9 @@ void dontIndexOnlineLinks() throws IOException { @Test void exampleThesisIndexWithKey() throws IOException { // given - BibEntry entry = new BibEntry(StandardEntryType.PhdThesis); - entry.setCitationKey("Example2017"); - entry.setFiles(Collections.singletonList(new LinkedFile("Example Thesis", "thesis-example.pdf", StandardFileType.PDF.getName()))); + BibEntry entry = new BibEntry(StandardEntryType.PhdThesis) + .withCitationKey("Example2017") + .withFiles(List.of(new LinkedFile("Example Thesis", "thesis-example.pdf", StandardFileType.PDF.getName()))); // when indexer.addToIndex(List.of(entry), mock(BackgroundTask.class)); @@ -113,8 +113,8 @@ void exampleThesisIndexWithKey() throws IOException { @Test void metaDataIndex() throws IOException { // given - BibEntry entry = new BibEntry(StandardEntryType.Article); - entry.setFiles(Collections.singletonList(new LinkedFile("Example Thesis", "metaData.pdf", StandardFileType.PDF.getName()))); + BibEntry entry = new BibEntry(StandardEntryType.Article) + .withFiles(List.of(new LinkedFile("Example Thesis", "metaData.pdf", StandardFileType.PDF.getName()))); // when indexer.addToIndex(List.of(entry), mock(BackgroundTask.class)); @@ -129,9 +129,9 @@ void metaDataIndex() throws IOException { @Test void exampleThesisIndexAppendMetaData() throws IOException { // given - BibEntry exampleThesis = new BibEntry(StandardEntryType.PhdThesis); - exampleThesis.setCitationKey("ExampleThesis2017"); - exampleThesis.setFiles(Collections.singletonList(new LinkedFile("Example Thesis", "thesis-example.pdf", StandardFileType.PDF.getName()))); + BibEntry exampleThesis = new BibEntry(StandardEntryType.PhdThesis) + .withCitationKey("ExampleThesis2017") + .withFiles(List.of(new LinkedFile("Example Thesis", "thesis-example.pdf", StandardFileType.PDF.getName()))); // when indexer.addToIndex(List.of(exampleThesis), mock(BackgroundTask.class)); @@ -142,9 +142,9 @@ void exampleThesisIndexAppendMetaData() throws IOException { assertEquals(33, reader.numDocs()); } - BibEntry metadata = new BibEntry(StandardEntryType.Article); - metadata.setCitationKey("MetaData2017"); - metadata.setFiles(Collections.singletonList(new LinkedFile("Metadata file", "metaData.pdf", StandardFileType.PDF.getName()))); + BibEntry metadata = new BibEntry(StandardEntryType.Article) + .withCitationKey("MetaData2017") + .withFiles(List.of(new LinkedFile("Metadata file", "metaData.pdf", StandardFileType.PDF.getName()))); // when indexer.addToIndex(List.of(metadata), mock(BackgroundTask.class)); @@ -159,9 +159,9 @@ void exampleThesisIndexAppendMetaData() throws IOException { @Test public void flushIndex() throws IOException { // given - BibEntry entry = new BibEntry(StandardEntryType.PhdThesis); - entry.setCitationKey("Example2017"); - entry.setFiles(Collections.singletonList(new LinkedFile("Example Thesis", "thesis-example.pdf", StandardFileType.PDF.getName()))); + BibEntry entry = new BibEntry(StandardEntryType.PhdThesis) + .withCitationKey("Example2017") + .withFiles(List.of(new LinkedFile("Example Thesis", "thesis-example.pdf", StandardFileType.PDF.getName()))); indexer.addToIndex(List.of(entry), mock(BackgroundTask.class)); From 85b8800658c1f2c78b1d9aa3f41f1364313392b7 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 31 Mar 2025 23:07:35 +0200 Subject: [PATCH 3/4] Shut down indexer during test --- .../logic/search/indexing/LinkedFilesIndexerTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/org/jabref/logic/search/indexing/LinkedFilesIndexerTest.java b/src/test/java/org/jabref/logic/search/indexing/LinkedFilesIndexerTest.java index 2419fd7f080..519719f0767 100644 --- a/src/test/java/org/jabref/logic/search/indexing/LinkedFilesIndexerTest.java +++ b/src/test/java/org/jabref/logic/search/indexing/LinkedFilesIndexerTest.java @@ -17,6 +17,7 @@ import org.jabref.model.entry.types.StandardEntryType; import org.apache.lucene.index.IndexReader; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -45,6 +46,11 @@ void setUp(@TempDir Path indexDir) throws IOException { this.indexer = new DefaultLinkedFilesIndexer(context, filePreferences); } + @AfterEach + void tearDown() { + this.indexer.closeAndWait(); + } + @Test void exampleThesisIndex() throws IOException { // given From f6e5901860c28095c2d56304632cf6867aa8a587 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 31 Mar 2025 23:12:53 +0200 Subject: [PATCH 4/4] Disable non-working tests --- src/test/java/org/jabref/logic/util/io/FileUtilTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/java/org/jabref/logic/util/io/FileUtilTest.java b/src/test/java/org/jabref/logic/util/io/FileUtilTest.java index 124587c2837..7288ad4cbcc 100644 --- a/src/test/java/org/jabref/logic/util/io/FileUtilTest.java +++ b/src/test/java/org/jabref/logic/util/io/FileUtilTest.java @@ -20,6 +20,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -219,6 +220,7 @@ void getFileNameWithMultipleDotsString() { } @Test + @DisabledOnOs(value = org.junit.jupiter.api.condition.OS.WINDOWS, disabledReason = "Assumed path separator is /") void uniquePathSubstrings() { List paths = List.of("C:/uniquefile.bib", "C:/downloads/filename.bib", @@ -236,12 +238,14 @@ void uniquePathSubstrings() { } @Test + @DisabledOnOs(value = org.junit.jupiter.api.condition.OS.WINDOWS, disabledReason = "Assumed path separator is /") void uniquePathFragmentWithSameSuffix() { List dirs = List.of("/users/jabref/bibliography.bib", "/users/jabref/koppor-bibliograsphy.bib"); assertEquals(Optional.of("bibliography.bib"), FileUtil.getUniquePathFragment(dirs, Path.of("/users/jabref/bibliography.bib"))); } @Test + @DisabledOnOs(value = org.junit.jupiter.api.condition.OS.WINDOWS, disabledReason = "Assumed path separator is /") void uniquePathFragmentWithSameSuffixAndLongerName() { List paths = List.of("/users/jabref/bibliography.bib", "/users/jabref/koppor-bibliography.bib"); assertEquals(Optional.of("koppor-bibliography.bib"), FileUtil.getUniquePathFragment(paths, Path.of("/users/jabref/koppor-bibliography.bib")));