Skip to content

Commit

Permalink
Use @tempdir for index path
Browse files Browse the repository at this point in the history
  • Loading branch information
LoayGhreeb committed Sep 10, 2024
1 parent 14ba56d commit d51c77e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit d51c77e

Please sign in to comment.