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); 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..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,11 +46,16 @@ 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 - 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 +70,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 +86,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 +102,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 +119,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 +135,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 +148,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 +165,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)); 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")));