Skip to content
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

Add githandler mock to crawler test to fix NPE #7133

Merged
merged 1 commit into from
Nov 29, 2020
Merged
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 @@ -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