From d51c77ec831beaaf1f3a6d7db6632073291019d9 Mon Sep 17 00:00:00 2001 From: Loay Ghreeb Date: Tue, 10 Sep 2024 19:41:24 +0300 Subject: [PATCH] Use @TempDir for index path --- .../org/jabref/logic/search/DatabaseSearcherTest.java | 8 +++++++- .../logic/search/DatabaseSearcherWithBibFilesTest.java | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jabref/logic/search/DatabaseSearcherTest.java b/src/test/java/org/jabref/logic/search/DatabaseSearcherTest.java index 919b002c54a..b065283086c 100644 --- a/src/test/java/org/jabref/logic/search/DatabaseSearcherTest.java +++ b/src/test/java/org/jabref/logic/search/DatabaseSearcherTest.java @@ -1,6 +1,7 @@ package org.jabref.logic.search; import java.io.IOException; +import java.nio.file.Path; import java.util.EnumSet; import java.util.List; import java.util.stream.Stream; @@ -18,24 +19,29 @@ import org.jabref.preferences.FilePreferences; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; public class DatabaseSearcherTest { private static final TaskExecutor TASK_EXECUTOR = new CurrentThreadTaskExecutor(); private BibDatabaseContext databaseContext; private final FilePreferences filePreferences = mock(FilePreferences.class); + @TempDir + private Path indexDir; @BeforeEach void setUp() { when(filePreferences.shouldFulltextIndexLinkedFiles()).thenReturn(false); when(filePreferences.fulltextIndexLinkedFilesProperty()).thenReturn(mock(BooleanProperty.class)); - databaseContext = new BibDatabaseContext(); + databaseContext = spy(new BibDatabaseContext()); + when(databaseContext.getFulltextIndexPath()).thenReturn(indexDir); } @ParameterizedTest diff --git a/src/test/java/org/jabref/logic/search/DatabaseSearcherWithBibFilesTest.java b/src/test/java/org/jabref/logic/search/DatabaseSearcherWithBibFilesTest.java index fe4d3203f0f..bb7723b0ab0 100644 --- a/src/test/java/org/jabref/logic/search/DatabaseSearcherWithBibFilesTest.java +++ b/src/test/java/org/jabref/logic/search/DatabaseSearcherWithBibFilesTest.java @@ -33,6 +33,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; class DatabaseSearcherWithBibFilesTest { @@ -77,7 +78,8 @@ private BibDatabaseContext initializeDatabaseFromPath(String testFile) throws Ex private BibDatabaseContext initializeDatabaseFromPath(Path testFile) throws Exception { ParserResult result = new BibtexImporter(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS), new DummyFileUpdateMonitor()).importDatabase(testFile); - BibDatabaseContext databaseContext = result.getDatabaseContext(); + BibDatabaseContext databaseContext = spy(result.getDatabaseContext()); + when(databaseContext.getFulltextIndexPath()).thenReturn(indexDir); when(filePreferences.shouldFulltextIndexLinkedFiles()).thenReturn(true); when(filePreferences.fulltextIndexLinkedFilesProperty()).thenReturn(new SimpleBooleanProperty(true));