Skip to content

Disable test not working on Windows #12869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,11 +46,16 @@ void setUp(@TempDir Path indexDir) throws IOException {
this.indexer = new DefaultLinkedFilesIndexer(context, filePreferences);
}

@AfterEach
void tearDown() {
this.indexer.closeAndWait();
}
Comment on lines +50 to +52
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tearDown method is unnecessary when using @tempdir, as JUnit automatically handles cleanup of temporary directories. This violates the instruction to avoid redundant cleanup.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The indexer locks the directory!


@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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));

Expand Down
4 changes: 4 additions & 0 deletions src/test/java/org/jabref/logic/util/io/FileUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -219,6 +220,7 @@ void getFileNameWithMultipleDotsString() {
}

@Test
@DisabledOnOs(value = org.junit.jupiter.api.condition.OS.WINDOWS, disabledReason = "Assumed path separator is /")
void uniquePathSubstrings() {
List<String> paths = List.of("C:/uniquefile.bib",
"C:/downloads/filename.bib",
Expand All @@ -236,12 +238,14 @@ void uniquePathSubstrings() {
}

@Test
@DisabledOnOs(value = org.junit.jupiter.api.condition.OS.WINDOWS, disabledReason = "Assumed path separator is /")
void uniquePathFragmentWithSameSuffix() {
List<String> 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<String> 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")));
Expand Down
Loading