From 21d22238062580b173c6e293e95a3e318699e029 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Mon, 19 Dec 2022 22:27:32 +0100 Subject: [PATCH 1/4] Cleanup tests, removed getKeywordSeparator from ImportFormatPreferences and made it a record, applied simple ide suggestions --- .../jabref/logic/crawler/StudyRepository.java | 2 +- .../importer/ImportFormatPreferences.java | 68 ++----------------- .../logic/importer/ImportFormatReader.java | 4 +- .../jabref/logic/importer/OpenDatabase.java | 7 +- .../jabref/logic/importer/WebFetchers.java | 2 +- .../logic/importer/fetcher/ArXivFetcher.java | 14 ++-- .../logic/importer/fetcher/DOAJFetcher.java | 2 +- .../jabref/logic/importer/fetcher/IEEE.java | 2 +- .../importer/fileformat/BibtexParser.java | 6 +- .../fileformat/EndnoteXmlImporter.java | 7 +- .../importer/fileformat/ModsImporter.java | 10 +-- .../fileformat/PdfGrobidImporter.java | 2 +- .../fileformat/PdfMergeMetadataImporter.java | 4 +- .../importer/fileformat/RepecNepImporter.java | 2 +- .../jabref/gui/entryeditor/SourceTabTest.java | 10 +-- .../ManageStudyDefinitionViewModelTest.java | 4 -- .../org/jabref/logic/crawler/CrawlerTest.java | 5 +- .../StudyDatabaseToFetcherConverterTest.java | 4 +- .../logic/crawler/StudyRepositoryTest.java | 6 +- .../logic/database/DatabaseMergerTest.java | 19 +++--- .../EmbeddedBibFilePdfExporterTest.java | 34 ++++------ .../exporter/ModsExportFormatFilesTest.java | 14 ++-- .../jabref/logic/importer/ImporterTest.java | 4 +- .../logic/importer/WebFetchersTest.java | 6 +- .../importer/fetcher/ArXivFetcherTest.java | 8 ++- .../fetcher/AstrophysicsDataSystemTest.java | 2 +- ...puterScienceBibliographiesFetcherTest.java | 2 +- ...mputerScienceBibliographiesParserTest.java | 2 +- .../fetcher/CompositeIdFetcherTest.java | 8 +-- .../CompositeSearchBasedFetcherTest.java | 6 +- .../importer/fetcher/DBLPFetcherTest.java | 8 +-- .../importer/fetcher/DOAJFetcherTest.java | 5 +- .../importer/fetcher/GoogleScholarTest.java | 7 +- .../logic/importer/fetcher/IEEETest.java | 7 +- .../importer/fetcher/INSPIREFetcherTest.java | 6 +- .../fetcher/LibraryOfCongressTest.java | 11 +-- .../importer/fetcher/MathSciNetTest.java | 2 +- .../logic/importer/fetcher/ZbMATHTest.java | 8 +-- .../importer/fileformat/BibtexParserTest.java | 8 +-- .../CitaviXmlImporterTestFiles.java | 14 ---- .../EndnoteXmlImporterTestFiles.java | 13 ++-- .../fileformat/ModsImporterTestFiles.java | 2 +- .../PdfEmbeddedBibFileImporterTest.java | 5 +- .../fileformat/PdfGrobidImporterTest.java | 4 +- .../PdfMergeMetadataImporterTest.java | 4 +- .../PdfVerbatimBibTextImporterTest.java | 5 +- .../fileformat/RepecNepImporterTest.java | 6 +- .../importer/util/GrobidServiceTest.java | 13 ++-- 48 files changed, 152 insertions(+), 242 deletions(-) diff --git a/src/main/java/org/jabref/logic/crawler/StudyRepository.java b/src/main/java/org/jabref/logic/crawler/StudyRepository.java index 0194a92f8e9..21e32c00f2b 100644 --- a/src/main/java/org/jabref/logic/crawler/StudyRepository.java +++ b/src/main/java/org/jabref/logic/crawler/StudyRepository.java @@ -385,7 +385,7 @@ private String computeIDForQuery(String query) { * @param crawlResults The results that shall be persisted. */ private void persistResults(List crawlResults) throws IOException, SaveException { - DatabaseMerger merger = new DatabaseMerger(importFormatPreferences.getKeywordSeparator()); + DatabaseMerger merger = new DatabaseMerger(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()); BibDatabase newStudyResultEntries = new BibDatabase(); for (QueryResult result : crawlResults) { diff --git a/src/main/java/org/jabref/logic/importer/ImportFormatPreferences.java b/src/main/java/org/jabref/logic/importer/ImportFormatPreferences.java index a3472341305..4c7df21f0da 100644 --- a/src/main/java/org/jabref/logic/importer/ImportFormatPreferences.java +++ b/src/main/java/org/jabref/logic/importer/ImportFormatPreferences.java @@ -1,8 +1,5 @@ package org.jabref.logic.importer; -import javafx.beans.property.ReadOnlyObjectProperty; -import javafx.beans.property.SimpleObjectProperty; - import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences; import org.jabref.logic.importer.fetcher.GrobidPreferences; @@ -10,62 +7,11 @@ import org.jabref.logic.xmp.XmpPreferences; import org.jabref.preferences.BibEntryPreferences; -public class ImportFormatPreferences { - - private final ReadOnlyObjectProperty bibEntryPreferences; - private final CitationKeyPatternPreferences citationKeyPatternPreferences; - private final FieldContentFormatterPreferences fieldContentFormatterPreferences; - private final XmpPreferences xmpPreferences; - private final DOIPreferences doiPreferences; - private final GrobidPreferences grobidPreferences; - - public ImportFormatPreferences(BibEntryPreferences bibEntryPreferences, - CitationKeyPatternPreferences citationKeyPatternPreferences, - FieldContentFormatterPreferences fieldContentFormatterPreferences, - XmpPreferences xmpPreferences, - DOIPreferences doiPreferences, - GrobidPreferences grobidPreferences) { - this.bibEntryPreferences = new SimpleObjectProperty<>(bibEntryPreferences); - this.citationKeyPatternPreferences = citationKeyPatternPreferences; - this.fieldContentFormatterPreferences = fieldContentFormatterPreferences; - this.xmpPreferences = xmpPreferences; - this.doiPreferences = doiPreferences; - this.grobidPreferences = grobidPreferences; - } - - public DOIPreferences getDoiPreferences() { - return doiPreferences; - } - - public ReadOnlyObjectProperty bibEntryPreferencesProperty() { - return bibEntryPreferences; - } - - public BibEntryPreferences getBibEntryPreferences() { - return bibEntryPreferences.getValue(); - } - - /** - * @deprecated use {@link BibEntryPreferences#getKeywordSeparator} instead. - */ - @Deprecated - public Character getKeywordSeparator() { - return bibEntryPreferencesProperty().getValue().getKeywordSeparator(); - } - - public CitationKeyPatternPreferences getCitationKeyPatternPreferences() { - return citationKeyPatternPreferences; - } - - public FieldContentFormatterPreferences getFieldContentFormatterPreferences() { - return fieldContentFormatterPreferences; - } - - public XmpPreferences getXmpPreferences() { - return xmpPreferences; - } - - public GrobidPreferences getGrobidPreferences() { - return grobidPreferences; - } +public record ImportFormatPreferences( + BibEntryPreferences bibEntryPreferences, + CitationKeyPatternPreferences citationKeyPatternPreferences, + FieldContentFormatterPreferences fieldContentFormatterPreferences, + XmpPreferences xmpPreferences, + DOIPreferences doiPreferences, + GrobidPreferences grobidPreferences) { } diff --git a/src/main/java/org/jabref/logic/importer/ImportFormatReader.java b/src/main/java/org/jabref/logic/importer/ImportFormatReader.java index 67ceeb59647..e1254371b4f 100644 --- a/src/main/java/org/jabref/logic/importer/ImportFormatReader.java +++ b/src/main/java/org/jabref/logic/importer/ImportFormatReader.java @@ -73,10 +73,10 @@ public void resetImportFormats(ImporterPreferences importerPreferences, formats.add(new PdfVerbatimBibTextImporter(importFormatPreferences)); formats.add(new PdfContentImporter(importFormatPreferences)); formats.add(new PdfEmbeddedBibFileImporter(importFormatPreferences)); - if (importFormatPreferences.getGrobidPreferences().isGrobidEnabled()) { + if (importFormatPreferences.grobidPreferences().isGrobidEnabled()) { formats.add(new PdfGrobidImporter(importFormatPreferences)); } - formats.add(new PdfXmpImporter(importFormatPreferences.getXmpPreferences())); + formats.add(new PdfXmpImporter(importFormatPreferences.xmpPreferences())); formats.add(new RepecNepImporter(importFormatPreferences)); formats.add(new RisImporter()); formats.add(new SilverPlatterImporter()); diff --git a/src/main/java/org/jabref/logic/importer/OpenDatabase.java b/src/main/java/org/jabref/logic/importer/OpenDatabase.java index f5e2fc1cd9c..3eb0bc09d12 100644 --- a/src/main/java/org/jabref/logic/importer/OpenDatabase.java +++ b/src/main/java/org/jabref/logic/importer/OpenDatabase.java @@ -12,13 +12,8 @@ import org.jabref.migrations.SpecialFieldsToSeparateFields; import org.jabref.model.util.FileUpdateMonitor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public class OpenDatabase { - private static final Logger LOGGER = LoggerFactory.getLogger(OpenDatabase.class); - private OpenDatabase() { } @@ -32,7 +27,7 @@ public static ParserResult loadDatabase(Path fileToOpen, ImportFormatPreferences throws IOException { ParserResult result = new BibtexImporter(importFormatPreferences, fileMonitor).importDatabase(fileToOpen); - performLoadDatabaseMigrations(result, importFormatPreferences.getKeywordSeparator()); + performLoadDatabaseMigrations(result, importFormatPreferences.bibEntryPreferences().getKeywordSeparator()); return result; } diff --git a/src/main/java/org/jabref/logic/importer/WebFetchers.java b/src/main/java/org/jabref/logic/importer/WebFetchers.java index 8440b2bb874..a42aea0efe1 100644 --- a/src/main/java/org/jabref/logic/importer/WebFetchers.java +++ b/src/main/java/org/jabref/logic/importer/WebFetchers.java @@ -186,7 +186,7 @@ public static Set getFullTextFetchers(ImportFormatPreferences i Set fetchers = new HashSet<>(); // Original - fetchers.add(new DoiResolution(importFormatPreferences.getDoiPreferences())); + fetchers.add(new DoiResolution(importFormatPreferences.doiPreferences())); // Publishers fetchers.add(new ScienceDirect(importerPreferences)); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ArXivFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/ArXivFetcher.java index dc5c6888a3d..8ac63c4056c 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ArXivFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ArXivFetcher.java @@ -148,7 +148,10 @@ private void adaptKeywordsFrom(BibEntry bibEntry) { allKeywords = Optional.of(allKeywords.get().replaceAll(entry.getKey(), entry.getValue())); } - String filteredKeywords = KeywordList.merge(allKeywords.get(), "", importFormatPreferences.getKeywordSeparator()).toString(); + String filteredKeywords = KeywordList.merge( + allKeywords.get(), + "", + importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).toString(); bibEntry.setField(StandardField.KEYWORDS, filteredKeywords); } } @@ -596,9 +599,10 @@ public Optional getHelpPage() { public Page performSearchPaged(QueryNode luceneQuery, int pageNumber) throws FetcherException { ArXivQueryTransformer transformer = new ArXivQueryTransformer(); String transformedQuery = transformer.transformLuceneQuery(luceneQuery).orElse(""); - List searchResult = searchForEntries(transformedQuery, pageNumber).stream() - .map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator())) - .collect(Collectors.toList()); + List searchResult = searchForEntries(transformedQuery, pageNumber) + .stream() + .map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.bibEntryPreferences().getKeywordSeparator())) + .collect(Collectors.toList()); return new Page<>(transformedQuery, pageNumber, filterYears(searchResult, transformer)); } @@ -624,7 +628,7 @@ protected CompletableFuture> asyncPerformSearchById(String id @Override public Optional performSearchById(String identifier) throws FetcherException { return searchForEntryById(identifier) - .map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator())); + .map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.bibEntryPreferences().getKeywordSeparator())); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java index a8656936077..ee949f00fed 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java @@ -211,7 +211,7 @@ public Parser getParser() { JSONArray results = jsonObject.getJSONArray("results"); for (int i = 0; i < results.length(); i++) { JSONObject bibJsonEntry = results.getJSONObject(i).getJSONObject("bibjson"); - BibEntry entry = parseBibJSONtoBibtex(bibJsonEntry, preferences.getKeywordSeparator()); + BibEntry entry = parseBibJSONtoBibtex(bibJsonEntry, preferences.bibEntryPreferences().getKeywordSeparator()); entries.add(entry); } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java index fe9860c3f44..30d41bd5d77 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java @@ -214,7 +214,7 @@ public Parser getParser() { JSONArray results = jsonObject.getJSONArray("articles"); for (int i = 0; i < results.length(); i++) { JSONObject jsonEntry = results.getJSONObject(i); - BibEntry entry = parseJsonResponse(jsonEntry, importFormatPreferences.getKeywordSeparator()); + BibEntry entry = parseJsonResponse(jsonEntry, importFormatPreferences.bibEntryPreferences().getKeywordSeparator()); boolean addEntry; // In case entry has no year, add it // In case an entry has a year, check if its in the year range diff --git a/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java b/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java index 8e5af3f715c..20da30e16ed 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java @@ -83,7 +83,7 @@ public class BibtexParser implements Parser { public BibtexParser(ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor) { this.importFormatPreferences = Objects.requireNonNull(importFormatPreferences); - fieldContentFormatter = new FieldContentFormatter(importFormatPreferences.getFieldContentFormatterPreferences()); + fieldContentFormatter = new FieldContentFormatter(importFormatPreferences.fieldContentFormatterPreferences()); metaDataParser = new MetaDataParser(fileMonitor); } @@ -228,7 +228,7 @@ private ParserResult parseFileContent() throws IOException { // Instantiate meta data try { - parserResult.setMetaData(metaDataParser.parse(meta, importFormatPreferences.getBibEntryPreferences().getKeywordSeparator())); + parserResult.setMetaData(metaDataParser.parse(meta, importFormatPreferences.bibEntryPreferences().getKeywordSeparator())); } catch (ParseException exception) { parserResult.addException(exception); } @@ -611,7 +611,7 @@ private void parseField(BibEntry entry) throws IOException { entry.setField(field, entry.getField(field).get() + " and " + content); } else if (StandardField.KEYWORDS.equals(field)) { // multiple keywords fields should be combined to one - entry.addKeyword(content, importFormatPreferences.getBibEntryPreferences().getKeywordSeparator()); + entry.addKeyword(content, importFormatPreferences.bibEntryPreferences().getKeywordSeparator()); } } else { entry.setField(field, content); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporter.java index 7c011473cc9..73edaa07433 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporter.java @@ -28,6 +28,7 @@ import org.jabref.logic.importer.fileformat.endnote.Dates; import org.jabref.logic.importer.fileformat.endnote.ElectronicResourceNum; import org.jabref.logic.importer.fileformat.endnote.Isbn; +import org.jabref.logic.importer.fileformat.endnote.Keyword; import org.jabref.logic.importer.fileformat.endnote.Keywords; import org.jabref.logic.importer.fileformat.endnote.Label; import org.jabref.logic.importer.fileformat.endnote.Notes; @@ -212,7 +213,7 @@ private BibEntry parseRecord(Record endNoteRecord) { .ifPresent(value -> entry.setField(StandardField.NOTE, value.trim())); getUrl(endNoteRecord) .ifPresent(value -> entry.setField(StandardField.URL, value)); - entry.putKeywords(getKeywords(endNoteRecord), preferences.getKeywordSeparator()); + entry.putKeywords(getKeywords(endNoteRecord), preferences.bibEntryPreferences().getKeywordSeparator()); Optional.ofNullable(endNoteRecord.getAbstract()) .map(Abstract::getStyle) .map(Style::getContent) @@ -307,9 +308,9 @@ private List getKeywords(Record endNoteRecord) { if (keywords != null) { return keywords.getKeyword() .stream() - .map(keyword -> keyword.getStyle()) + .map(Keyword::getStyle) .filter(Objects::nonNull) - .map(style -> style.getContent()) + .map(Style::getContent) .collect(Collectors.toList()); } else { return Collections.emptyList(); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/ModsImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/ModsImporter.java index 052578f7657..3ca2bc8d1c3 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/ModsImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/ModsImporter.java @@ -81,7 +81,7 @@ public class ModsImporter extends Importer implements Parser { private JAXBContext context; public ModsImporter(ImportFormatPreferences importFormatPreferences) { - keywordSeparator = importFormatPreferences.getKeywordSeparator() + " "; + keywordSeparator = importFormatPreferences.bibEntryPreferences().getKeywordSeparator() + " "; } @Override @@ -179,7 +179,7 @@ private void parseModsGroup(Map fields, List modsGroup, B nameDefinition.ifPresent(name -> handleAuthorsInNamePart(name, authors, fields)); originInfoDefinition.ifPresent(originInfo -> originInfo - .getPlaceOrPublisherOrDateIssued().stream() + .getPlaceOrPublisherOrDateIssued() .forEach(element -> putPlaceOrPublisherOrDate(fields, element.getName().getLocalPart(), element.getValue()))); @@ -229,7 +229,7 @@ private void parseTitle(Map fields, List titleOrSubTitleO private void parseIdentifier(Map fields, IdentifierDefinition identifier, BibEntry entry) { String type = identifier.getType(); - if ("citekey".equals(type) && !entry.getCitationKey().isPresent()) { + if ("citekey".equals(type) && entry.getCitationKey().isEmpty()) { entry.setCitationKey(identifier.getValue()); } else if (!"local".equals(type) && !"citekey".equals(type)) { // put all identifiers (doi, issn, isbn,...) except of local and citekey @@ -381,8 +381,8 @@ private void putPlaceOrPublisherOrDate(Map fields, String element List places = new ArrayList<>(); placeDefinition - .ifPresent(place -> place.getPlaceTerm().stream().filter(placeTerm -> placeTerm.getValue() != null) - .map(PlaceTermDefinition::getValue).forEach(element -> places.add(element))); + .ifPresent(place -> place.getPlaceTerm().stream().map(PlaceTermDefinition::getValue) + .filter(Objects::nonNull).forEach(places::add)); putIfListIsNotEmpty(fields, places, StandardField.ADDRESS, ", "); dateDefinition.ifPresent(date -> putDate(fields, elementName, date)); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/PdfGrobidImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/PdfGrobidImporter.java index bb013d58118..f12ee30c986 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/PdfGrobidImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/PdfGrobidImporter.java @@ -25,7 +25,7 @@ public class PdfGrobidImporter extends Importer { private final ImportFormatPreferences importFormatPreferences; public PdfGrobidImporter(ImportFormatPreferences importFormatPreferences) { - this.grobidService = new GrobidService(importFormatPreferences.getGrobidPreferences()); + this.grobidService = new GrobidService(importFormatPreferences.grobidPreferences()); this.importFormatPreferences = importFormatPreferences; } diff --git a/src/main/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporter.java index 7b4088dfee9..a954859a136 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporter.java @@ -46,10 +46,10 @@ public PdfMergeMetadataImporter(ImportFormatPreferences importFormatPreferences) this.metadataImporters = new ArrayList<>(); this.metadataImporters.add(new PdfVerbatimBibTextImporter(importFormatPreferences)); this.metadataImporters.add(new PdfEmbeddedBibFileImporter(importFormatPreferences)); - if (importFormatPreferences.getGrobidPreferences().isGrobidEnabled()) { + if (importFormatPreferences.grobidPreferences().isGrobidEnabled()) { this.metadataImporters.add(new PdfGrobidImporter(importFormatPreferences)); } - this.metadataImporters.add(new PdfXmpImporter(importFormatPreferences.getXmpPreferences())); + this.metadataImporters.add(new PdfXmpImporter(importFormatPreferences.xmpPreferences())); this.metadataImporters.add(new PdfContentImporter(importFormatPreferences)); } diff --git a/src/main/java/org/jabref/logic/importer/fileformat/RepecNepImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/RepecNepImporter.java index 3e3e62f183b..3b09fd7634e 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/RepecNepImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/RepecNepImporter.java @@ -332,7 +332,7 @@ private void parseAdditionalFields(BibEntry be, boolean multilineUrlFieldAllowed String content = readMultipleLines(in); String[] keywords = content.split("[,;]"); be.addKeywords(Arrays.asList(keywords), - importFormatPreferences.getKeywordSeparator()); + importFormatPreferences.bibEntryPreferences().getKeywordSeparator()); } else if ("JEL".equals(keyword)) { // parse JEL field be.setField(new UnknownField("jel"), readMultipleLines(in)); diff --git a/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java b/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java index a0361ec6ecb..125b8880cb4 100644 --- a/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java +++ b/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java @@ -22,12 +22,12 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UnknownField; import org.jabref.model.util.DummyFileUpdateMonitor; -import org.jabref.preferences.BibEntryPreferences; import org.jabref.testutils.category.GUITest; import org.fxmisc.richtext.CodeArea; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Answers; import org.testfx.api.FxRobot; import org.testfx.framework.junit5.ApplicationExtension; import org.testfx.framework.junit5.Start; @@ -52,12 +52,8 @@ public void onStart(Stage stage) { StateManager stateManager = mock(StateManager.class); when(stateManager.activeSearchQueryProperty()).thenReturn(OptionalObjectProperty.empty()); KeyBindingRepository keyBindingRepository = new KeyBindingRepository(Collections.emptyList(), Collections.emptyList()); - BibEntryPreferences bibEntryPreferences = mock(BibEntryPreferences.class); - when(bibEntryPreferences.getKeywordSeparator()).thenReturn(','); - ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); - when(importFormatPreferences.getFieldContentFormatterPreferences()) - .thenReturn(mock(FieldContentFormatterPreferences.class)); - when(importFormatPreferences.getBibEntryPreferences()).thenReturn(bibEntryPreferences); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); FieldWriterPreferences fieldWriterPreferences = new FieldWriterPreferences(true, List.of(StandardField.MONTH), new FieldContentFormatterPreferences()); sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), fieldWriterPreferences, importFormatPreferences, new DummyFileUpdateMonitor(), mock(DialogService.class), stateManager, keyBindingRepository); diff --git a/src/test/java/org/jabref/gui/slr/ManageStudyDefinitionViewModelTest.java b/src/test/java/org/jabref/gui/slr/ManageStudyDefinitionViewModelTest.java index 726945b923f..bf6e508d75f 100644 --- a/src/test/java/org/jabref/gui/slr/ManageStudyDefinitionViewModelTest.java +++ b/src/test/java/org/jabref/gui/slr/ManageStudyDefinitionViewModelTest.java @@ -4,7 +4,6 @@ import java.util.List; import org.jabref.gui.DialogService; -import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.ImporterPreferences; import org.jabref.model.study.Study; @@ -17,7 +16,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; class ManageStudyDefinitionViewModelTest { private ImportFormatPreferences importFormatPreferences; @@ -29,8 +27,6 @@ void setUp() { // code taken from org.jabref.logic.importer.WebFetchersTest.setUp importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); importerPreferences = mock(ImporterPreferences.class); - FieldContentFormatterPreferences fieldContentFormatterPreferences = mock(FieldContentFormatterPreferences.class); - when(importFormatPreferences.getFieldContentFormatterPreferences()).thenReturn(fieldContentFormatterPreferences); dialogService = mock(DialogService.class); } diff --git a/src/test/java/org/jabref/logic/crawler/CrawlerTest.java b/src/test/java/org/jabref/logic/crawler/CrawlerTest.java index a16d3b4469d..c7a80743331 100644 --- a/src/test/java/org/jabref/logic/crawler/CrawlerTest.java +++ b/src/test/java/org/jabref/logic/crawler/CrawlerTest.java @@ -7,7 +7,6 @@ import javafx.collections.FXCollections; -import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences; import org.jabref.logic.citationkeypattern.GlobalCitationKeyPattern; import org.jabref.logic.exporter.SavePreferences; @@ -100,8 +99,8 @@ private void setUp() throws Exception { when(savePreferences.takeMetadataSaveOrderInAccount()).thenReturn(true); when(savePreferences.getCitationKeyPatternPreferences()).thenReturn(citationKeyPatternPreferences); when(importerPreferences.getApiKeys()).thenReturn(FXCollections.emptyObservableSet()); - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); - when(importFormatPreferences.getFieldContentFormatterPreferences()).thenReturn(new FieldContentFormatterPreferences()); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); + entryTypesManager = new BibEntryTypesManager(); } diff --git a/src/test/java/org/jabref/logic/crawler/StudyDatabaseToFetcherConverterTest.java b/src/test/java/org/jabref/logic/crawler/StudyDatabaseToFetcherConverterTest.java index 78b557a6fe0..d874a14544b 100644 --- a/src/test/java/org/jabref/logic/crawler/StudyDatabaseToFetcherConverterTest.java +++ b/src/test/java/org/jabref/logic/crawler/StudyDatabaseToFetcherConverterTest.java @@ -7,7 +7,6 @@ import javafx.collections.FXCollections; -import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.exporter.SavePreferences; import org.jabref.logic.git.SlrGitHandler; import org.jabref.logic.importer.ImportFormatPreferences; @@ -49,8 +48,7 @@ void setUpMocks() { timestampPreferences = mock(TimestampPreferences.class); when(savePreferences.getSaveOrder()).thenReturn(new SaveOrderConfig()); when(savePreferences.takeMetadataSaveOrderInAccount()).thenReturn(true); - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); - when(importFormatPreferences.getFieldContentFormatterPreferences()).thenReturn(new FieldContentFormatterPreferences()); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); when(importerPreferences.getApiKeys()).thenReturn(FXCollections.emptyObservableSet()); entryTypesManager = new BibEntryTypesManager(); gitHandler = mock(SlrGitHandler.class, Answers.RETURNS_DEFAULTS); diff --git a/src/test/java/org/jabref/logic/crawler/StudyRepositoryTest.java b/src/test/java/org/jabref/logic/crawler/StudyRepositoryTest.java index 5c6c14983d6..717e0da4f52 100644 --- a/src/test/java/org/jabref/logic/crawler/StudyRepositoryTest.java +++ b/src/test/java/org/jabref/logic/crawler/StudyRepositoryTest.java @@ -87,8 +87,8 @@ public void setUpMocks() throws Exception { when(savePreferences.takeMetadataSaveOrderInAccount()).thenReturn(true); when(savePreferences.getCitationKeyPatternPreferences()).thenReturn(citationKeyPatternPreferences); when(importerPreferences.getApiKeys()).thenReturn(FXCollections.emptyObservableSet()); - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); - when(importFormatPreferences.getFieldContentFormatterPreferences()).thenReturn(new FieldContentFormatterPreferences()); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); + when(importFormatPreferences.fieldContentFormatterPreferences()).thenReturn(new FieldContentFormatterPreferences()); when(timestampPreferences.getTimestampField()).then(invocation -> StandardField.TIMESTAMP); entryTypesManager = new BibEntryTypesManager(); getTestStudyRepository(); @@ -211,7 +211,7 @@ private void setUpTestResultFile() throws Exception { private BibDatabase getNonDuplicateBibEntryResult() { BibDatabase mockResults = new BibDatabase(getSpringerCloudComputingMockResults()); - DatabaseMerger merger = new DatabaseMerger(importFormatPreferences.getKeywordSeparator()); + DatabaseMerger merger = new DatabaseMerger(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()); merger.merge(mockResults, new BibDatabase(getSpringerQuantumMockResults())); merger.merge(mockResults, new BibDatabase(getArXivQuantumMockResults())); return mockResults; diff --git a/src/test/java/org/jabref/logic/database/DatabaseMergerTest.java b/src/test/java/org/jabref/logic/database/DatabaseMergerTest.java index f36cddb486c..0ba97e64a89 100644 --- a/src/test/java/org/jabref/logic/database/DatabaseMergerTest.java +++ b/src/test/java/org/jabref/logic/database/DatabaseMergerTest.java @@ -20,6 +20,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; @@ -30,8 +31,8 @@ class DatabaseMergerTest { @BeforeEach void setUp() { - importFormatPreferences = mock(ImportFormatPreferences.class); - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); + importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); } @Test @@ -49,7 +50,7 @@ void mergeAddsNonDuplicateEntries() { BibDatabase database = new BibDatabase(List.of(entry1)); BibDatabase other = new BibDatabase(List.of(entry2, entry3)); - new DatabaseMerger(importFormatPreferences.getKeywordSeparator()).merge(database, other); + new DatabaseMerger(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).merge(database, other); assertEquals(List.of(entry1, entry3), database.getEntries()); } @@ -80,7 +81,7 @@ void mergeAddsWithDuplicateEntries() { BibDatabase database = new BibDatabase(List.of(entry1, entry4)); BibDatabase other = new BibDatabase(List.of(entry2, entry3)); - new DatabaseMerger(importFormatPreferences.getKeywordSeparator()).merge(database, other); + new DatabaseMerger(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).merge(database, other); assertEquals(List.of(entry1, entry4), database.getEntries()); } @@ -103,8 +104,8 @@ void mergeBibTexStringsWithSameNameAreImportedWithModifiedName() { source1.addString(sourceString1); source2.addString(sourceString2); - new DatabaseMerger(importFormatPreferences.getKeywordSeparator()).mergeStrings(target, source1); - new DatabaseMerger(importFormatPreferences.getKeywordSeparator()).mergeStrings(target, source2); + new DatabaseMerger(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).mergeStrings(target, source1); + new DatabaseMerger(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).mergeStrings(target, source2); // Use string representation to compare since the id will not match List resultStringsSorted = target.getStringValues() .stream() @@ -132,7 +133,7 @@ void mergeBibTexStringsWithSameNameAndContentAreIgnored() { source.addString(sourceString1); source.addString(sourceString2); - new DatabaseMerger(importFormatPreferences.getKeywordSeparator()).mergeStrings(target, source); + new DatabaseMerger(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).mergeStrings(target, source); List resultStringsSorted = target.getStringValues() .stream() .sorted((s1, s2) -> new BibtexStringComparator(false).compare(s1, s2)) @@ -155,7 +156,7 @@ void mergeMetaDataWithoutAllEntriesGroup() { List.of(new ContentSelector(StandardField.AUTHOR, List.of("Test Author")), new ContentSelector(StandardField.TITLE, List.of("Test Title"))); - new DatabaseMerger(importFormatPreferences.getKeywordSeparator()).mergeMetaData(target, other, "unknown", List.of()); + new DatabaseMerger(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).mergeMetaData(target, other, "unknown", List.of()); // Assert that content selectors are all merged assertEquals(expectedContentSelectors, target.getContentSelectorList()); @@ -181,7 +182,7 @@ void mergeMetaDataWithAllEntriesGroup() { new ContentSelector(StandardField.TITLE, List.of("Test Title"))); GroupTreeNode expectedImportedGroupNode = new GroupTreeNode(new ExplicitGroup("Imported unknown", GroupHierarchyType.INDEPENDENT, ';')); - new DatabaseMerger(importFormatPreferences.getKeywordSeparator()).mergeMetaData(target, other, "unknown", List.of()); + new DatabaseMerger(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).mergeMetaData(target, other, "unknown", List.of()); // Assert that groups of other are children of root node of target assertEquals(targetRootGroup, target.getGroups().get()); diff --git a/src/test/java/org/jabref/logic/exporter/EmbeddedBibFilePdfExporterTest.java b/src/test/java/org/jabref/logic/exporter/EmbeddedBibFilePdfExporterTest.java index e2e4ee62323..daf53480553 100644 --- a/src/test/java/org/jabref/logic/exporter/EmbeddedBibFilePdfExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/EmbeddedBibFilePdfExporterTest.java @@ -1,16 +1,13 @@ package org.jabref.logic.exporter; import java.io.IOException; -import java.nio.charset.Charset; import java.nio.file.Path; -import java.util.Arrays; import java.util.List; import java.util.stream.Stream; import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.bibtex.FieldWriterPreferences; import org.jabref.logic.importer.ImportFormatPreferences; -import org.jabref.logic.importer.fileformat.PdfEmbeddedBibFileImporter; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; @@ -40,17 +37,14 @@ class EmbeddedBibFilePdfExporterTest { @TempDir static Path tempDir; - private static BibEntry olly2018 = new BibEntry(StandardEntryType.Article); - private static BibEntry toral2006 = new BibEntry(StandardEntryType.Article); - private static BibEntry vapnik2000 = new BibEntry(StandardEntryType.Article); + private static final BibEntry olly2018 = new BibEntry(StandardEntryType.Article); + private static final BibEntry toral2006 = new BibEntry(StandardEntryType.Article); + private static final BibEntry vapnik2000 = new BibEntry(StandardEntryType.Article); - private PdfEmbeddedBibFileImporter importer; private EmbeddedBibFilePdfExporter exporter; private ImportFormatPreferences importFormatPreferences; private BibDatabaseMode bibDatabaseMode; private BibEntryTypesManager bibEntryTypesManager; - private FieldWriterPreferences fieldWriterPreferences; - private Charset encoding; private BibDatabaseContext databaseContext; private BibDatabase dataBase; @@ -79,7 +73,7 @@ private static void initBibEntries() throws IOException { olly2018.setField(StandardField.URL, "https://www.olly2018.edu"); LinkedFile linkedFile = createDefaultLinkedFile("existing.pdf", tempDir); - olly2018.setFiles(Arrays.asList(linkedFile)); + olly2018.setFiles(List.of(linkedFile)); toral2006.setField(StandardField.AUTHOR, "Toral, Antonio and Munoz, Rafael"); toral2006.setField(StandardField.TITLE, "A proposal to automatically build and maintain gazetteers for Named Entity Recognition by using Wikipedia"); @@ -89,7 +83,7 @@ private static void initBibEntries() throws IOException { toral2006.setField(StandardField.OWNER, "Ich"); toral2006.setField(StandardField.URL, "www.url.de"); - toral2006.setFiles(Arrays.asList(new LinkedFile("non-existing", "path/to/nowhere.pdf", "PDF"))); + toral2006.setFiles(List.of(new LinkedFile("non-existing", "path/to/nowhere.pdf", "PDF"))); vapnik2000.setCitationKey("vapnik2000"); vapnik2000.setField(StandardField.TITLE, "The Nature of Statistical Learning Theory"); @@ -104,20 +98,20 @@ private static void initBibEntries() throws IOException { */ @BeforeEach void setUp() throws IOException { - encoding = Charset.defaultCharset(); - filePreferences = mock(FilePreferences.class); when(filePreferences.getUser()).thenReturn(tempDir.toAbsolutePath().toString()); when(filePreferences.shouldStoreFilesRelativeToBibFile()).thenReturn(false); importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); - when(importFormatPreferences.getFieldContentFormatterPreferences().getNonWrappableFields()).thenReturn(List.of()); + when(importFormatPreferences.fieldContentFormatterPreferences().getNonWrappableFields()).thenReturn(List.of()); bibDatabaseMode = BibDatabaseMode.BIBTEX; bibEntryTypesManager = new BibEntryTypesManager(); - FieldWriterPreferences fieldWriterPreferences = new FieldWriterPreferences(true, List.of(StandardField.MONTH), new FieldContentFormatterPreferences()); + FieldWriterPreferences fieldWriterPreferences = new FieldWriterPreferences( + true, + List.of(StandardField.MONTH), + new FieldContentFormatterPreferences()); - importer = new PdfEmbeddedBibFileImporter(importFormatPreferences); exporter = new EmbeddedBibFilePdfExporter(bibDatabaseMode, bibEntryTypesManager, fieldWriterPreferences); databaseContext = new BibDatabaseContext(); @@ -132,13 +126,13 @@ void setUp() throws IOException { @ParameterizedTest @MethodSource("provideBibEntriesWithValidPdfFileLinks") void successfulExportToAllFilesOfEntry(BibEntry bibEntryWithValidPdfFileLink) throws Exception { - assertTrue(exporter.exportToAllFilesOfEntry(databaseContext, filePreferences, bibEntryWithValidPdfFileLink, Arrays.asList(olly2018))); + assertTrue(exporter.exportToAllFilesOfEntry(databaseContext, filePreferences, bibEntryWithValidPdfFileLink, List.of(olly2018))); } @ParameterizedTest @MethodSource("provideBibEntriesWithInvalidPdfFileLinks") void unsuccessfulExportToAllFilesOfEntry(BibEntry bibEntryWithValidPdfFileLink) throws Exception { - assertFalse(exporter.exportToAllFilesOfEntry(databaseContext, filePreferences, bibEntryWithValidPdfFileLink, Arrays.asList(olly2018))); + assertFalse(exporter.exportToAllFilesOfEntry(databaseContext, filePreferences, bibEntryWithValidPdfFileLink, List.of(olly2018))); } public static Stream provideBibEntriesWithValidPdfFileLinks() { @@ -180,8 +174,6 @@ private static LinkedFile createDefaultLinkedFile(String fileName, Path tempDir) pdf.save(pdfFile.toAbsolutePath().toString()); } - LinkedFile linkedFile = new LinkedFile("A linked pdf", pdfFile, "PDF"); - - return linkedFile; + return new LinkedFile("A linked pdf", pdfFile, "PDF"); } } diff --git a/src/test/java/org/jabref/logic/exporter/ModsExportFormatFilesTest.java b/src/test/java/org/jabref/logic/exporter/ModsExportFormatFilesTest.java index 567459318c6..9b9998a3dbc 100644 --- a/src/test/java/org/jabref/logic/exporter/ModsExportFormatFilesTest.java +++ b/src/test/java/org/jabref/logic/exporter/ModsExportFormatFilesTest.java @@ -14,18 +14,19 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.util.DummyFileUpdateMonitor; +import org.jabref.preferences.BibEntryPreferences; 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.MethodSource; import org.mockito.Answers; -import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class ModsExportFormatFilesTest { private static final Logger LOGGER = LoggerFactory.getLogger(ModsExportFormatFilesTest.class); @@ -52,16 +53,19 @@ public static Stream fileNames() throws Exception { @BeforeEach public void setUp(@TempDir Path testFolder) throws Exception { + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importFormatPreferences.bibEntryPreferences()).thenReturn(mock(BibEntryPreferences.class)); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); + databaseContext = new BibDatabaseContext(); charset = StandardCharsets.UTF_8; exporter = new ModsExporter(); + bibtexImporter = new BibtexImporter(importFormatPreferences, new DummyFileUpdateMonitor()); + modsImporter = new ModsImporter(importFormatPreferences); + Path path = testFolder.resolve("ARandomlyNamedFile.tmp"); Files.createFile(path); exportedFile = path.toAbsolutePath(); - ImportFormatPreferences mock = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); - bibtexImporter = new BibtexImporter(mock, new DummyFileUpdateMonitor()); - Mockito.when(mock.getKeywordSeparator()).thenReturn(','); - modsImporter = new ModsImporter(mock); } @ParameterizedTest diff --git a/src/test/java/org/jabref/logic/importer/ImporterTest.java b/src/test/java/org/jabref/logic/importer/ImporterTest.java index 5409b87fe1b..97c236ffd53 100644 --- a/src/test/java/org/jabref/logic/importer/ImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/ImporterTest.java @@ -27,6 +27,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.Answers; import org.mockito.Mockito; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -105,7 +106,8 @@ public static Stream instancesToTest() { // all classes implementing {@link Importer} // sorted alphabetically - ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); XmpPreferences xmpPreferences = mock(XmpPreferences.class); // @formatter:off return Stream.of( diff --git a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java index 8ce65cc322c..47412d20445 100644 --- a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java +++ b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java @@ -6,7 +6,6 @@ import java.util.Set; import java.util.stream.Collectors; -import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.importer.fetcher.AbstractIsbnFetcher; import org.jabref.logic.importer.fetcher.CiteSeer; import org.jabref.logic.importer.fetcher.GoogleScholar; @@ -30,7 +29,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; class WebFetchersTest { @@ -45,8 +43,6 @@ class WebFetchersTest { void setUp() { importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); importerPreferences = mock(ImporterPreferences.class); - FieldContentFormatterPreferences fieldContentFormatterPreferences = mock(FieldContentFormatterPreferences.class); - when(importFormatPreferences.getFieldContentFormatterPreferences()).thenReturn(fieldContentFormatterPreferences); } private Set> getIgnoredInaccessibleClasses() { @@ -56,7 +52,7 @@ private Set> getIgnoredInaccessibleClasses() { try { return Class.forName(classPath); } catch (ClassNotFoundException e) { - LOGGER.error("Some of the ignored classes were not found {}", e); + LOGGER.error("Some of the ignored classes were not found", e); return null; } }).filter(Objects::nonNull).collect(Collectors.toSet()); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ArXivFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ArXivFetcherTest.java index d7173fc1027..119877fa76a 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ArXivFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ArXivFetcherTest.java @@ -29,6 +29,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.mockito.Answers; import org.mockito.Mockito; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -53,10 +54,10 @@ class ArXivFetcherTest implements SearchBasedFetcherCapabilityTest, PagedSearchF @BeforeAll static void setUp() { - importFormatPreferences = mock(ImportFormatPreferences.class); - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); + importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); // Used during DOI fetch process - when(importFormatPreferences.getFieldContentFormatterPreferences()).thenReturn( + when(importFormatPreferences.fieldContentFormatterPreferences()).thenReturn( new FieldContentFormatterPreferences( Arrays.stream("pdf;ps;url;doi;file;isbn;issn".split(";")) .map(fieldName -> StandardField.fromName(fieldName).isPresent() ? StandardField.fromName(fieldName).get() : new UnknownField(fieldName)) @@ -104,6 +105,7 @@ void eachSetUp() { .withField(StandardField.DOI, "10.48550/ARXIV.1811.10364"); // Example of a robust result, with information from both ArXiv-assigned and user-assigned DOIs + // FixMe: Test this BibEntry completePaper = new BibEntry(StandardEntryType.Article) .withField(StandardField.AUTHOR, "Büscher, Tobias and Diez, Angel L. and Gompper, Gerhard and Elgeti, Jens") .withField(StandardField.TITLE, "Instability and fingering of interfaces in growing tissue") diff --git a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java index 7eac2f723a0..fa8acd4e870 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java @@ -40,7 +40,7 @@ public void setUp() throws Exception { ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); ImporterPreferences importerPreferences = mock(ImporterPreferences.class); when(importerPreferences.getApiKeys()).thenReturn(FXCollections.emptyObservableSet()); - when(importFormatPreferences.getFieldContentFormatterPreferences()).thenReturn( + when(importFormatPreferences.fieldContentFormatterPreferences()).thenReturn( mock(FieldContentFormatterPreferences.class)); fetcher = new AstrophysicsDataSystem(importFormatPreferences, importerPreferences); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java index de15e01aa3b..093fe015397 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java @@ -34,7 +34,7 @@ class CollectionOfComputerScienceBibliographiesFetcherTest { @BeforeEach public void setUp() { ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); fetcher = new CollectionOfComputerScienceBibliographiesFetcher(importFormatPreferences); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesParserTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesParserTest.java index 8c50807604f..f55110bbcd3 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesParserTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesParserTest.java @@ -39,7 +39,7 @@ public void parseEntriesReturnsMultipleBibEntriesInListIfXmlHasMultipleResults() private void parseXmlAndCheckResults(String xmlName, List resourceNames) throws Exception { ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); InputStream is = CollectionOfComputerScienceBibliographiesParserTest.class.getResourceAsStream(xmlName); CollectionOfComputerScienceBibliographiesParser parser = new CollectionOfComputerScienceBibliographiesParser(importFormatPreferences); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CompositeIdFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CompositeIdFetcherTest.java index ce2427a21e4..0440b67d06a 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CompositeIdFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CompositeIdFetcherTest.java @@ -3,7 +3,6 @@ import java.util.Optional; import java.util.stream.Stream; -import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.importer.CompositeIdFetcher; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; @@ -19,6 +18,7 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.ValueSource; +import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; @@ -104,11 +104,9 @@ public static Stream performSearchByIdReturnsCorrectEntryForIdentifie @BeforeEach void setUp() throws Exception { - ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); - FieldContentFormatterPreferences fieldContentFormatterPreferences = mock(FieldContentFormatterPreferences.class); - when(importFormatPreferences.getFieldContentFormatterPreferences()).thenReturn(fieldContentFormatterPreferences); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); // Needed for ArXiv Fetcher keyword processing - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); compositeIdFetcher = new CompositeIdFetcher(importFormatPreferences); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java index 6ca761f0283..ba943481fff 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java @@ -9,7 +9,6 @@ import javafx.collections.FXCollections; -import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportCleanup; import org.jabref.logic.importer.ImportFormatPreferences; @@ -25,6 +24,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.Answers; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -92,11 +92,9 @@ public void performSearchOnNonEmptyQuery(Set fetchers) throw * @return A stream of Arguments wrapping set of fetchers. */ static Stream performSearchParameters() { - ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); ImporterPreferences importerPreferences = mock(ImporterPreferences.class); when(importerPreferences.getApiKeys()).thenReturn(FXCollections.emptyObservableSet()); - when(importFormatPreferences.getFieldContentFormatterPreferences()) - .thenReturn(mock(FieldContentFormatterPreferences.class)); List> fetcherParameters = new ArrayList<>(); List list = List.of( diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DBLPFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DBLPFetcherTest.java index 0e6e3d767f1..5e051e48394 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DBLPFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DBLPFetcherTest.java @@ -3,7 +3,6 @@ import java.util.Collections; import java.util.List; -import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.entry.BibEntry; @@ -14,10 +13,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; @FetcherTest public class DBLPFetcherTest { @@ -27,10 +26,7 @@ public class DBLPFetcherTest { @BeforeEach public void setUp() { - ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); - when(importFormatPreferences.getFieldContentFormatterPreferences()) - .thenReturn(mock(FieldContentFormatterPreferences.class)); - dblpFetcher = new DBLPFetcher(importFormatPreferences); + dblpFetcher = new DBLPFetcher(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS)); entry = new BibEntry(); entry.setType(StandardEntryType.Article); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java index 2cad38a3f17..540e6b9a5c2 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java @@ -14,6 +14,7 @@ import org.apache.http.client.utils.URIBuilder; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; @@ -26,8 +27,8 @@ class DOAJFetcherTest { @BeforeEach void setUp() { - ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); fetcher = new DOAJFetcher(importFormatPreferences); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java b/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java index 0aceb0310d2..4432e20a19b 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Optional; -import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.PagedSearchBasedFetcher; @@ -19,10 +18,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; @FetcherTest @DisabledOnCIServer("CI server is blocked by Google") @@ -33,9 +32,7 @@ class GoogleScholarTest implements SearchBasedFetcherCapabilityTest, PagedSearch @BeforeEach void setUp() { - ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); - when(importFormatPreferences.getFieldContentFormatterPreferences()).thenReturn( - mock(FieldContentFormatterPreferences.class)); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); finder = new GoogleScholar(importFormatPreferences); entry = new BibEntry(); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java b/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java index a6921608ce4..965fde89a1a 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; @@ -48,10 +49,12 @@ class IEEETest implements SearchBasedFetcherCapabilityTest, PagedSearchFetcherTe @BeforeEach void setUp() { - ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); + ImporterPreferences importerPreferences = mock(ImporterPreferences.class); when(importerPreferences.getApiKeys()).thenReturn(FXCollections.emptyObservableSet()); + fetcher = new IEEE(importFormatPreferences, importerPreferences); entry = new BibEntry(); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java index b48b72020c5..e2ff790894d 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java @@ -3,7 +3,6 @@ import java.util.Collections; import java.util.List; -import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; @@ -13,10 +12,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; @FetcherTest class INSPIREFetcherTest { @@ -25,8 +24,7 @@ class INSPIREFetcherTest { @BeforeEach void setUp() { - ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); - when(importFormatPreferences.getFieldContentFormatterPreferences()).thenReturn(mock(FieldContentFormatterPreferences.class)); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); fetcher = new INSPIREFetcher(importFormatPreferences); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java b/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java index 562ded1f3bd..5b8e7d1ceab 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java @@ -7,6 +7,7 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UnknownField; +import org.jabref.preferences.BibEntryPreferences; import org.jabref.testutils.category.FetcherTest; import org.junit.jupiter.api.BeforeEach; @@ -24,9 +25,11 @@ public class LibraryOfCongressTest { @BeforeEach public void setUp() { - ImportFormatPreferences prefs = mock(ImportFormatPreferences.class); - when(prefs.getKeywordSeparator()).thenReturn(','); - fetcher = new LibraryOfCongress(prefs); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); + when(importFormatPreferences.bibEntryPreferences()).thenReturn(mock(BibEntryPreferences.class)); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); + + fetcher = new LibraryOfCongress(importFormatPreferences); } @Test @@ -55,7 +58,7 @@ public void performSearchByEmptyId() throws Exception { } @Test - public void performSearchByInvalidId() throws Exception { + public void performSearchByInvalidId() { assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("xxx")); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java b/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java index 7c3cba64256..10903338184 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java @@ -29,7 +29,7 @@ class MathSciNetTest { @BeforeEach void setUp() throws Exception { ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); - when(importFormatPreferences.getFieldContentFormatterPreferences()).thenReturn( + when(importFormatPreferences.fieldContentFormatterPreferences()).thenReturn( mock(FieldContentFormatterPreferences.class)); fetcher = new MathSciNet(importFormatPreferences); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ZbMATHTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ZbMATHTest.java index b88d95b94a8..9128ed477e8 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ZbMATHTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ZbMATHTest.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.Optional; -import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; @@ -14,6 +13,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; @@ -26,9 +26,9 @@ class ZbMATHTest { @BeforeEach void setUp() throws Exception { - ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); - when(importFormatPreferences.getFieldContentFormatterPreferences()).thenReturn( - mock(FieldContentFormatterPreferences.class)); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); + fetcher = new ZbMATH(importFormatPreferences); donaldsonEntry = new BibEntry(); diff --git a/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java b/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java index b0aa6ceb505..97bc6f3b8a8 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java @@ -54,7 +54,6 @@ import org.jabref.model.metadata.SaveOrderConfig; import org.jabref.model.util.DummyFileUpdateMonitor; import org.jabref.model.util.FileUpdateMonitor; -import org.jabref.preferences.BibEntryPreferences; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -78,10 +77,7 @@ class BibtexParserTest { @BeforeEach void setUp() { importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); - BibEntryPreferences bibEntryPreferences = mock(BibEntryPreferences.class); - - when(importFormatPreferences.getBibEntryPreferences()).thenReturn(bibEntryPreferences); - when(importFormatPreferences.getBibEntryPreferences().getKeywordSeparator()).thenReturn(','); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); parser = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()); } @@ -1133,7 +1129,7 @@ void parseConvertsMultipleTabsToSpace() throws IOException { @Test void parsePreservesMultipleSpacesInNonWrappableField() throws IOException { - when(importFormatPreferences.getFieldContentFormatterPreferences().getNonWrappableFields()) + when(importFormatPreferences.fieldContentFormatterPreferences().getNonWrappableFields()) .thenReturn(List.of(StandardField.FILE)); BibtexParser parser = new BibtexParser(importFormatPreferences, fileMonitor); ParserResult result = parser diff --git a/src/test/java/org/jabref/logic/importer/fileformat/CitaviXmlImporterTestFiles.java b/src/test/java/org/jabref/logic/importer/fileformat/CitaviXmlImporterTestFiles.java index c3f6e6f2892..42b108e9e55 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/CitaviXmlImporterTestFiles.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/CitaviXmlImporterTestFiles.java @@ -4,22 +4,14 @@ import java.util.function.Predicate; import java.util.stream.Stream; -import org.jabref.logic.importer.ImportFormatPreferences; - -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - public class CitaviXmlImporterTestFiles { private static final String FILE_ENDING = ".ctv6bak"; private final CitaviXmlImporter citaviXmlImporter = new CitaviXmlImporter(); - private ImportFormatPreferences preferences; - private static Stream fileNames() throws IOException { Predicate fileName = name -> name.startsWith("CitaviXmlImporterTest") && name.endsWith(FILE_ENDING); return ImporterTestEngine.getTestFiles(fileName).stream(); @@ -30,12 +22,6 @@ private static Stream invalidFileNames() throws IOException { return ImporterTestEngine.getTestFiles(fileName).stream(); } - @BeforeEach - void setUp() { - preferences = mock(ImportFormatPreferences.class); - when(preferences.getKeywordSeparator()).thenReturn(';'); - } - @ParameterizedTest @MethodSource("fileNames") void testIsRecognizedFormat(String fileName) throws IOException { diff --git a/src/test/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestFiles.java b/src/test/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestFiles.java index 3cf39f99291..aeba968fa6e 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestFiles.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/EndnoteXmlImporterTestFiles.java @@ -9,6 +9,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.Answers; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -16,7 +17,7 @@ public class EndnoteXmlImporterTestFiles { private static final String FILE_ENDING = ".xml"; - private ImportFormatPreferences preferences; + private ImportFormatPreferences importFormatPreferences; private static Stream fileNames() throws IOException { Predicate fileName = name -> name.startsWith("EndnoteXmlImporterTest") && name.endsWith(FILE_ENDING); @@ -30,25 +31,25 @@ private static Stream invalidFileNames() throws IOException { @BeforeEach void setUp() { - preferences = mock(ImportFormatPreferences.class); - when(preferences.getKeywordSeparator()).thenReturn(';'); + importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(';'); } @ParameterizedTest @MethodSource("fileNames") void testIsRecognizedFormat(String fileName) throws IOException { - ImporterTestEngine.testIsRecognizedFormat(new EndnoteXmlImporter(preferences), fileName); + ImporterTestEngine.testIsRecognizedFormat(new EndnoteXmlImporter(importFormatPreferences), fileName); } @ParameterizedTest @MethodSource("invalidFileNames") void testIsNotRecognizedFormat(String fileName) throws IOException { - ImporterTestEngine.testIsNotRecognizedFormat(new EndnoteXmlImporter(preferences), fileName); + ImporterTestEngine.testIsNotRecognizedFormat(new EndnoteXmlImporter(importFormatPreferences), fileName); } @ParameterizedTest @MethodSource("fileNames") void testImportEntries(String fileName) throws Exception { - ImporterTestEngine.testImportEntries(new EndnoteXmlImporter(preferences), fileName, FILE_ENDING); + ImporterTestEngine.testImportEntries(new EndnoteXmlImporter(importFormatPreferences), fileName, FILE_ENDING); } } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/ModsImporterTestFiles.java b/src/test/java/org/jabref/logic/importer/fileformat/ModsImporterTestFiles.java index a8909f20c23..aa5905fe716 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/ModsImporterTestFiles.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/ModsImporterTestFiles.java @@ -27,7 +27,7 @@ private static Stream fileNames() throws IOException { @BeforeEach void setUp() { importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); } @ParameterizedTest diff --git a/src/test/java/org/jabref/logic/importer/fileformat/PdfEmbeddedBibFileImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/PdfEmbeddedBibFileImporterTest.java index b00746f8eb8..03fce0180c4 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/PdfEmbeddedBibFileImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/PdfEmbeddedBibFileImporterTest.java @@ -21,12 +21,11 @@ class PdfEmbeddedBibFileImporterTest { private PdfEmbeddedBibFileImporter importer; - private ImportFormatPreferences importFormatPreferences; @BeforeEach void setUp() { - importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); - when(importFormatPreferences.getFieldContentFormatterPreferences().getNonWrappableFields()).thenReturn(List.of()); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importFormatPreferences.fieldContentFormatterPreferences().getNonWrappableFields()).thenReturn(List.of()); importer = new PdfEmbeddedBibFileImporter(importFormatPreferences); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/PdfGrobidImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/PdfGrobidImporterTest.java index 196c3aae38c..07975a31f87 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/PdfGrobidImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/PdfGrobidImporterTest.java @@ -35,8 +35,8 @@ public void setUp() { when(grobidPreferences.getGrobidURL()).thenReturn("http://grobid.jabref.org:8070"); ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); - when(importFormatPreferences.getGrobidPreferences()).thenReturn(grobidPreferences); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); + when(importFormatPreferences.grobidPreferences()).thenReturn(grobidPreferences); importer = new PdfGrobidImporter(importFormatPreferences); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporterTest.java index 1afa5056d18..d39775df28b 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporterTest.java @@ -35,8 +35,8 @@ void setUp() { when(grobidPreferences.getGrobidURL()).thenReturn("http://grobid.jabref.org:8070"); ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); - when(importFormatPreferences.getFieldContentFormatterPreferences().getNonWrappableFields()).thenReturn(List.of()); - when(importFormatPreferences.getGrobidPreferences()).thenReturn(grobidPreferences); + when(importFormatPreferences.fieldContentFormatterPreferences().getNonWrappableFields()).thenReturn(List.of()); + when(importFormatPreferences.grobidPreferences()).thenReturn(grobidPreferences); importer = new PdfMergeMetadataImporter(importFormatPreferences); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/PdfVerbatimBibTextImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/PdfVerbatimBibTextImporterTest.java index 404427a7207..1a86d509b2a 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/PdfVerbatimBibTextImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/PdfVerbatimBibTextImporterTest.java @@ -22,12 +22,11 @@ class PdfVerbatimBibTextImporterTest { private PdfVerbatimBibTextImporter importer; - private ImportFormatPreferences importFormatPreferences; @BeforeEach void setUp() { - importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); - when(importFormatPreferences.getFieldContentFormatterPreferences().getNonWrappableFields()).thenReturn(List.of()); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importFormatPreferences.fieldContentFormatterPreferences().getNonWrappableFields()).thenReturn(List.of()); importer = new PdfVerbatimBibTextImporter(importFormatPreferences); } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/RepecNepImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/RepecNepImporterTest.java index f80b694b7f5..5130e8913fa 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/RepecNepImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/RepecNepImporterTest.java @@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; @@ -24,8 +25,9 @@ public class RepecNepImporterTest { @BeforeEach public void setUp() { - ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); + testImporter = new RepecNepImporter(importFormatPreferences); } diff --git a/src/test/java/org/jabref/logic/importer/util/GrobidServiceTest.java b/src/test/java/org/jabref/logic/importer/util/GrobidServiceTest.java index 9e81c64ede5..69c3693f2d1 100644 --- a/src/test/java/org/jabref/logic/importer/util/GrobidServiceTest.java +++ b/src/test/java/org/jabref/logic/importer/util/GrobidServiceTest.java @@ -30,17 +30,18 @@ public class GrobidServiceTest { private static GrobidService grobidService; - private static GrobidPreferences grobidPreferences = new GrobidPreferences( - true, - false, - "http://grobid.jabref.org:8070"); private static ImportFormatPreferences importFormatPreferences; @BeforeAll public static void setup() { - grobidService = new GrobidService(grobidPreferences); importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); - when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); + + GrobidPreferences grobidPreferences = new GrobidPreferences( + true, + false, + "http://grobid.jabref.org:8070"); + grobidService = new GrobidService(grobidPreferences); } @Test From ea0d38edf3082cc92cd03500bf59d099b0ca7af9 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Mon, 19 Dec 2022 22:38:27 +0100 Subject: [PATCH 2/4] Fixed MathSciNetTest --- .../org/jabref/logic/importer/fetcher/MathSciNetTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java b/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java index 10903338184..adc114c1b2a 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.Optional; -import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; @@ -14,6 +13,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -28,9 +28,9 @@ class MathSciNetTest { @BeforeEach void setUp() throws Exception { - ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); - when(importFormatPreferences.fieldContentFormatterPreferences()).thenReturn( - mock(FieldContentFormatterPreferences.class)); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(','); + fetcher = new MathSciNet(importFormatPreferences); ratiuEntry = new BibEntry(); From effdd6e69abfc51babaf541aef17bd48f4873394 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Mon, 19 Dec 2022 22:53:46 +0100 Subject: [PATCH 3/4] Fixed checkstyle --- .../EmbeddedBibFilePdfExporterTest.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/jabref/logic/exporter/EmbeddedBibFilePdfExporterTest.java b/src/test/java/org/jabref/logic/exporter/EmbeddedBibFilePdfExporterTest.java index daf53480553..a15c380418d 100644 --- a/src/test/java/org/jabref/logic/exporter/EmbeddedBibFilePdfExporterTest.java +++ b/src/test/java/org/jabref/logic/exporter/EmbeddedBibFilePdfExporterTest.java @@ -7,7 +7,6 @@ import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.bibtex.FieldWriterPreferences; -import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; @@ -26,7 +25,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -37,14 +35,11 @@ class EmbeddedBibFilePdfExporterTest { @TempDir static Path tempDir; - private static final BibEntry olly2018 = new BibEntry(StandardEntryType.Article); - private static final BibEntry toral2006 = new BibEntry(StandardEntryType.Article); - private static final BibEntry vapnik2000 = new BibEntry(StandardEntryType.Article); + private static BibEntry olly2018 = new BibEntry(StandardEntryType.Article); + private static BibEntry toral2006 = new BibEntry(StandardEntryType.Article); + private static BibEntry vapnik2000 = new BibEntry(StandardEntryType.Article); private EmbeddedBibFilePdfExporter exporter; - private ImportFormatPreferences importFormatPreferences; - private BibDatabaseMode bibDatabaseMode; - private BibEntryTypesManager bibEntryTypesManager; private BibDatabaseContext databaseContext; private BibDatabase dataBase; @@ -102,11 +97,8 @@ void setUp() throws IOException { when(filePreferences.getUser()).thenReturn(tempDir.toAbsolutePath().toString()); when(filePreferences.shouldStoreFilesRelativeToBibFile()).thenReturn(false); - importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); - when(importFormatPreferences.fieldContentFormatterPreferences().getNonWrappableFields()).thenReturn(List.of()); - - bibDatabaseMode = BibDatabaseMode.BIBTEX; - bibEntryTypesManager = new BibEntryTypesManager(); + BibDatabaseMode bibDatabaseMode = BibDatabaseMode.BIBTEX; + BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); FieldWriterPreferences fieldWriterPreferences = new FieldWriterPreferences( true, List.of(StandardField.MONTH), From 10c92697356319b2db1959909496420f3fc34956 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Mon, 19 Dec 2022 22:56:12 +0100 Subject: [PATCH 4/4] Fixed AstrophysicsDataSystemTest --- .../logic/importer/fetcher/AstrophysicsDataSystemTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java index fa8acd4e870..219ce711326 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java @@ -5,7 +5,6 @@ import javafx.collections.FXCollections; -import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.PagedSearchBasedFetcher; @@ -17,6 +16,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -37,11 +37,10 @@ public class AstrophysicsDataSystemTest implements PagedSearchFetcherTest { @BeforeEach public void setUp() throws Exception { - ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class); + ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); ImporterPreferences importerPreferences = mock(ImporterPreferences.class); when(importerPreferences.getApiKeys()).thenReturn(FXCollections.emptyObservableSet()); - when(importFormatPreferences.fieldContentFormatterPreferences()).thenReturn( - mock(FieldContentFormatterPreferences.class)); + fetcher = new AstrophysicsDataSystem(importFormatPreferences, importerPreferences); diezSliceTheoremEntry = new BibEntry(StandardEntryType.Article)