Skip to content

Commit

Permalink
Add githandler mock to crawler test to fix NPE (#7133)
Browse files Browse the repository at this point in the history
Pass githandler to crawler to enable mock

Signed-off-by: Dominik Voigt <dominik.ingo.voigt@gmail.com>
  • Loading branch information
DominikVoigt authored Nov 29, 2020
1 parent 9d7b93d commit b05ebac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.crawler.Crawler;
import org.jabref.logic.crawler.git.GitHandler;
import org.jabref.logic.importer.ParseException;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.BibEntryTypesManager;
Expand Down Expand Up @@ -49,7 +50,7 @@ public void execute() {
}
final Crawler crawler;
try {
crawler = new Crawler(studyDefinitionFile.get(), fileUpdateMonitor, JabRefPreferences.getInstance().getImportFormatPreferences(), JabRefPreferences.getInstance().getSavePreferences(), new BibEntryTypesManager());
crawler = new Crawler(studyDefinitionFile.get(), new GitHandler(studyDefinitionFile.get().getParent()), fileUpdateMonitor, JabRefPreferences.getInstance().getImportFormatPreferences(), JabRefPreferences.getInstance().getSavePreferences(), new BibEntryTypesManager());
} catch (IOException | ParseException | GitAPIException e) {
LOGGER.error("Error during reading of study definition file.", e);
dialogService.showErrorDialogAndWait(Localization.lang("Error during reading of study definition file."), e);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/crawler/Crawler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class Crawler {
*
* @param studyDefinitionFile The path to the study definition file that contains the list of targeted E-Libraries and used cross-library queries
*/
public Crawler(Path studyDefinitionFile, FileUpdateMonitor fileUpdateMonitor, ImportFormatPreferences importFormatPreferences, SavePreferences savePreferences, BibEntryTypesManager bibEntryTypesManager) throws IllegalArgumentException, IOException, ParseException, GitAPIException {
public Crawler(Path studyDefinitionFile, GitHandler gitHandler, FileUpdateMonitor fileUpdateMonitor, ImportFormatPreferences importFormatPreferences, SavePreferences savePreferences, BibEntryTypesManager bibEntryTypesManager) throws IllegalArgumentException, IOException, ParseException, GitAPIException {
Path studyRepositoryRoot = studyDefinitionFile.getParent();
studyRepository = new StudyRepository(studyRepositoryRoot, new GitHandler(studyRepositoryRoot), importFormatPreferences, fileUpdateMonitor, savePreferences, bibEntryTypesManager);
studyRepository = new StudyRepository(studyRepositoryRoot, gitHandler, importFormatPreferences, fileUpdateMonitor, savePreferences, bibEntryTypesManager);
Study study = studyRepository.getStudy();
LibraryEntryToFetcherConverter libraryEntryToFetcherConverter = new LibraryEntryToFetcherConverter(study.getActiveLibraryEntries(), importFormatPreferences);
this.studyFetcher = new StudyFetcher(libraryEntryToFetcherConverter.getActiveFetchers(), study.getSearchQueryStrings());
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/jabref/logic/crawler/CrawlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.nio.file.Path;

import org.jabref.logic.bibtex.FieldContentFormatterPreferences;
import org.jabref.logic.crawler.git.GitHandler;
import org.jabref.logic.exporter.SavePreferences;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.util.io.FileUtil;
Expand All @@ -31,11 +32,13 @@ class CrawlerTest {
ImportFormatPreferences importFormatPreferences;
SavePreferences savePreferences;
BibEntryTypesManager entryTypesManager;
GitHandler gitHandler = mock(GitHandler.class, Answers.RETURNS_DEFAULTS);

@Test
public void testWhetherAllFilesAreCreated() throws Exception {
setUp();
Crawler testCrawler = new Crawler(getPathToStudyDefinitionFile(),
gitHandler,
new DummyFileUpdateMonitor(),
importFormatPreferences,
savePreferences,
Expand Down

0 comments on commit b05ebac

Please sign in to comment.