diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 26052b80573..1a9b90bbd9d 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -122,6 +122,7 @@ import net.sf.jabref.logic.layout.Layout; import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.logic.layout.LayoutHelper; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.util.UpdateField; import net.sf.jabref.logic.util.io.FileBasedLock; import net.sf.jabref.logic.util.io.FileUtil; diff --git a/src/main/java/net/sf/jabref/gui/FileExtensions.java b/src/main/java/net/sf/jabref/gui/FileExtensions.java deleted file mode 100644 index 0e1e49c15d8..00000000000 --- a/src/main/java/net/sf/jabref/gui/FileExtensions.java +++ /dev/null @@ -1,68 +0,0 @@ -package net.sf.jabref.gui; - -import net.sf.jabref.logic.l10n.Localization; - -/** - * - * - *This enum contains all kind of file extensions for open and save dialogs - *Important: Enter the extension without a dot! - *The dot is added implicit - */ -public enum FileExtensions { - - //important: No dot before the extension! - BIBTEX_DB( - String.format("%1s %2s", "BibTex", Localization.lang("Database")), "bib"), - BIBTEXML( - Localization.lang("%0 file", "BibTeXML"), "bibx"), - AUX( - Localization.lang("%0 file", "AUX"), "aux"), - SILVER_PLATTERN( - Localization.lang("%0 file", "SilverPlatter"), "dat"), - PUBMED( - Localization.lang("%0 file", "PubMed"), "fcgi"), - RIS( - Localization.lang("%0 file", "RIS"), "ris"), - ENDNOTE( - Localization.lang("%0 file", "Endnote/Refer"), "ref"), - JSTYLE( - Localization.lang("Style file"), "jstyle"), - LAYOUT( - Localization.lang("Custom layout file"), "layout"), - XML( - Localization.lang("%0 file", "XML"), "xml"), - TERMS( - Localization.lang("Protected terms file"), "terms"), - TXT( - Localization.lang("%0 file", Localization.lang("plain text")), "txt"), - CLASS( - Localization.lang("%0 file", "CLASS"), "class"), - JAR( - Localization.lang("%0 file", "JAR"), "jar"), - ZIP( - Localization.lang("%0 file", "ZIP"), "zip"); - - private final String[] extension; - private final String description; - - - private FileExtensions(String description, String... extension) { - this.extension = extension; - this.description = description; - } - - //Array because a) is varags and b) gets passed as varags parameter to FileExtensionNameFilter - public String[] getExtensions() { - return extension; - } - - public String getDescription() { - - return description; - } - - public String getFirstExtensionWithDot() { - return "." + extension[0].trim(); - } -} diff --git a/src/main/java/net/sf/jabref/gui/NewFileDialogs.java b/src/main/java/net/sf/jabref/gui/NewFileDialogs.java index 18d2b98d22b..babead98840 100644 --- a/src/main/java/net/sf/jabref/gui/NewFileDialogs.java +++ b/src/main/java/net/sf/jabref/gui/NewFileDialogs.java @@ -19,6 +19,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.preferences.JabRefPreferences; public class NewFileDialogs { diff --git a/src/main/java/net/sf/jabref/gui/actions/BrowseAction.java b/src/main/java/net/sf/jabref/gui/actions/BrowseAction.java index 61ed52997f9..32b3ed73db3 100644 --- a/src/main/java/net/sf/jabref/gui/actions/BrowseAction.java +++ b/src/main/java/net/sf/jabref/gui/actions/BrowseAction.java @@ -27,9 +27,9 @@ import javax.swing.JFrame; import javax.swing.JTextField; -import net.sf.jabref.gui.FileExtensions; import net.sf.jabref.gui.NewFileDialogs; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.util.FileExtensions; /** * Action used to produce a "Browse" button for one of the text fields. diff --git a/src/main/java/net/sf/jabref/gui/auximport/FromAuxDialog.java b/src/main/java/net/sf/jabref/gui/auximport/FromAuxDialog.java index a00264be8be..09d48a35b61 100644 --- a/src/main/java/net/sf/jabref/gui/auximport/FromAuxDialog.java +++ b/src/main/java/net/sf/jabref/gui/auximport/FromAuxDialog.java @@ -57,13 +57,13 @@ import net.sf.jabref.Globals; import net.sf.jabref.gui.BasePanel; -import net.sf.jabref.gui.FileExtensions; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.actions.BrowseAction; import net.sf.jabref.gui.keyboard.KeyBinding; import net.sf.jabref.logic.auxparser.AuxParser; import net.sf.jabref.logic.auxparser.AuxParserResult; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.database.BibDatabase; import com.jgoodies.forms.builder.ButtonBarBuilder; diff --git a/src/main/java/net/sf/jabref/gui/exporter/CustomExportDialog.java b/src/main/java/net/sf/jabref/gui/exporter/CustomExportDialog.java index 15cf0b4ba89..07bb11b7a4b 100644 --- a/src/main/java/net/sf/jabref/gui/exporter/CustomExportDialog.java +++ b/src/main/java/net/sf/jabref/gui/exporter/CustomExportDialog.java @@ -37,11 +37,11 @@ import javax.swing.JTextField; import net.sf.jabref.Globals; -import net.sf.jabref.gui.FileExtensions; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.actions.BrowseAction; import net.sf.jabref.gui.keyboard.KeyBinding; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.preferences.JabRefPreferences; import com.jgoodies.forms.builder.ButtonBarBuilder; diff --git a/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java index c9df0c01c38..99b55d09875 100644 --- a/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java @@ -31,7 +31,6 @@ import net.sf.jabref.JabRefExecutorService; import net.sf.jabref.collab.ChangeScanner; import net.sf.jabref.gui.BasePanel; -import net.sf.jabref.gui.FileExtensions; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.NewFileDialogs; import net.sf.jabref.gui.worker.AbstractWorker; @@ -44,6 +43,7 @@ import net.sf.jabref.logic.exporter.SaveSession; import net.sf.jabref.logic.l10n.Encodings; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.util.io.FileBasedLock; import net.sf.jabref.preferences.JabRefPreferences; diff --git a/src/main/java/net/sf/jabref/gui/importer/ImportCustomizationDialog.java b/src/main/java/net/sf/jabref/gui/importer/ImportCustomizationDialog.java index bdf5f1e71b9..03033339a95 100644 --- a/src/main/java/net/sf/jabref/gui/importer/ImportCustomizationDialog.java +++ b/src/main/java/net/sf/jabref/gui/importer/ImportCustomizationDialog.java @@ -44,7 +44,6 @@ import javax.swing.table.TableColumnModel; import net.sf.jabref.Globals; -import net.sf.jabref.gui.FileExtensions; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.NewFileDialogs; import net.sf.jabref.gui.help.HelpAction; @@ -55,6 +54,7 @@ import net.sf.jabref.logic.importer.fileformat.CustomImporter; import net.sf.jabref.logic.importer.fileformat.ImportFormat; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.xmp.XMPPreferences; import com.jgoodies.forms.builder.ButtonBarBuilder; diff --git a/src/main/java/net/sf/jabref/gui/importer/ImportFileFilter.java b/src/main/java/net/sf/jabref/gui/importer/ImportFileFilter.java index fc0de4b1f9d..e880b18d34b 100644 --- a/src/main/java/net/sf/jabref/gui/importer/ImportFileFilter.java +++ b/src/main/java/net/sf/jabref/gui/importer/ImportFileFilter.java @@ -16,30 +16,25 @@ package net.sf.jabref.gui.importer; import java.io.File; -import java.util.StringJoiner; import javax.swing.filechooser.FileFilter; +import javax.swing.filechooser.FileNameExtensionFilter; import net.sf.jabref.logic.importer.fileformat.ImportFormat; +import net.sf.jabref.logic.util.FileExtensions; -/** - * File filter that lets the user choose export format while choosing file to - * export to. Contains a reference to the ExportFormat in question. - */ class ImportFileFilter extends FileFilter implements Comparable { private final ImportFormat format; private final String name; + private final FileNameExtensionFilter filextFilter; public ImportFileFilter(ImportFormat format) { this.format = format; - - StringJoiner sj = new StringJoiner(", ", format.getFormatName() + " (", ")"); - for (String ext : format.getExtensions()) { - sj.add("*" + ext); - } - this.name = sj.toString(); + FileExtensions extensions = format.getExtensions(); + this.name = extensions.getDescription(); + filextFilter = new FileNameExtensionFilter(extensions.getDescription(), extensions.getExtensions()); } public ImportFormat getImportFormat() { @@ -48,17 +43,7 @@ public ImportFormat getImportFormat() { @Override public boolean accept(File file) { - if (format.getExtensions().isEmpty()) { - return true; - } - - for (String extension : format.getExtensions()) { - if (file.getName().endsWith(extension)) { - return true; - } - } - - return false; + return filextFilter.accept(file); } @Override @@ -73,7 +58,7 @@ public int compareTo(ImportFileFilter o) { @Override public boolean equals(Object o) { - if(this == o) { + if (this == o) { return true; } if (o instanceof ImportFileFilter) { diff --git a/src/main/java/net/sf/jabref/gui/importer/ImportFormats.java b/src/main/java/net/sf/jabref/gui/importer/ImportFormats.java index b58c5a6ed04..7e691bced93 100644 --- a/src/main/java/net/sf/jabref/gui/importer/ImportFormats.java +++ b/src/main/java/net/sf/jabref/gui/importer/ImportFormats.java @@ -26,6 +26,7 @@ import javax.swing.Action; import javax.swing.JFileChooser; import javax.swing.JOptionPane; + import javax.swing.filechooser.FileFilter; import net.sf.jabref.Globals; @@ -40,8 +41,10 @@ import org.apache.commons.logging.LogFactory; public class ImportFormats { + private static final Log LOGGER = LogFactory.getLog(ImportFormats.class); + private static JFileChooser createImportFileChooser(String currentDir) { SortedSet importers = Globals.IMPORT_FORMAT_READER.getImportFormats(); @@ -91,12 +94,14 @@ public ImportAction(JabRefFrame frame, boolean openInNew) { putValue(Action.NAME, openInNew ? Localization.menuTitle("Import into new database") : Localization .menuTitle("Import into current database")); putValue(Action.ACCELERATOR_KEY, - openInNew ? Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_NEW_DATABASE) : Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_CURRENT_DATABASE)); + openInNew ? Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_NEW_DATABASE) : Globals + .getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_CURRENT_DATABASE)); } @Override public void actionPerformed(ActionEvent e) { - JFileChooser fileChooser = createImportFileChooser(Globals.prefs.get(JabRefPreferences.IMPORT_WORKING_DIRECTORY)); + JFileChooser fileChooser = createImportFileChooser( + Globals.prefs.get(JabRefPreferences.IMPORT_WORKING_DIRECTORY)); int result = fileChooser.showOpenDialog(frame); if (result != JFileChooser.APPROVE_OPTION) { @@ -118,8 +123,7 @@ public void actionPerformed(ActionEvent e) { if (!file.exists()) { // Warn that the file doesn't exists: JOptionPane.showMessageDialog(frame, - Localization.lang("File not found") + - ": '" + file.getName() + "'.", + Localization.lang("File not found") + ": '" + file.getName() + "'.", Localization.lang("Import"), JOptionPane.ERROR_MESSAGE); return; } diff --git a/src/main/java/net/sf/jabref/gui/importer/actions/OpenDatabaseAction.java b/src/main/java/net/sf/jabref/gui/importer/actions/OpenDatabaseAction.java index 6704b0307e7..33fb782f7d0 100644 --- a/src/main/java/net/sf/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/net/sf/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -35,7 +35,6 @@ import net.sf.jabref.JabRefExecutorService; import net.sf.jabref.MetaData; import net.sf.jabref.gui.BasePanel; -import net.sf.jabref.gui.FileExtensions; import net.sf.jabref.gui.IconTheme; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.NewFileDialogs; @@ -46,6 +45,7 @@ import net.sf.jabref.logic.importer.OpenDatabase; import net.sf.jabref.logic.importer.ParserResult; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.util.io.AutoSaveUtil; import net.sf.jabref.logic.util.io.FileBasedLock; import net.sf.jabref.logic.util.strings.StringUtil; diff --git a/src/main/java/net/sf/jabref/gui/openoffice/StyleSelectDialog.java b/src/main/java/net/sf/jabref/gui/openoffice/StyleSelectDialog.java index d69b64627d7..b04b0dffeca 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/StyleSelectDialog.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/StyleSelectDialog.java @@ -51,7 +51,6 @@ import net.sf.jabref.external.ExternalFileType; import net.sf.jabref.external.ExternalFileTypes; import net.sf.jabref.external.UnknownExternalFileType; -import net.sf.jabref.gui.FileExtensions; import net.sf.jabref.gui.IconTheme; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.PreviewPanel; @@ -63,6 +62,7 @@ import net.sf.jabref.logic.openoffice.OOBibStyle; import net.sf.jabref.logic.openoffice.OpenOfficePreferences; import net.sf.jabref.logic.openoffice.StyleLoader; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.util.TestEntry; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; diff --git a/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java b/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java index 9d1ff5099d0..0b03dcbbb82 100644 --- a/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java +++ b/src/main/java/net/sf/jabref/gui/plaintextimport/TextInputDialog.java @@ -112,7 +112,6 @@ import net.sf.jabref.Globals; import net.sf.jabref.gui.ClipBoardManager; import net.sf.jabref.gui.EntryMarker; -import net.sf.jabref.gui.FileExtensions; import net.sf.jabref.gui.IconTheme; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.NewFileDialogs; @@ -127,6 +126,7 @@ import net.sf.jabref.logic.importer.ParserResult; import net.sf.jabref.logic.importer.fileformat.FreeCiteImporter; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.util.OS; import net.sf.jabref.logic.util.UpdateField; import net.sf.jabref.model.EntryTypes; diff --git a/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java b/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java index 81b47dbc89b..4a8b29b87c5 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java @@ -37,8 +37,6 @@ import net.sf.jabref.Globals; import net.sf.jabref.JabRefException; - -import net.sf.jabref.gui.FileExtensions; import net.sf.jabref.gui.GUIGlobals; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.NewFileDialogs; @@ -46,6 +44,7 @@ import net.sf.jabref.gui.maintable.MainTable; import net.sf.jabref.logic.exporter.ExportFormats; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.preferences.JabRefPreferences; import net.sf.jabref.preferences.JabRefPreferencesFilter; diff --git a/src/main/java/net/sf/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java b/src/main/java/net/sf/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java index d00264cbb7f..34eceb1110e 100644 --- a/src/main/java/net/sf/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java +++ b/src/main/java/net/sf/jabref/gui/protectedterms/NewProtectedTermsFileDialog.java @@ -13,14 +13,13 @@ import javax.swing.JTextField; import net.sf.jabref.Globals; - -import net.sf.jabref.gui.FileExtensions; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.actions.BrowseAction; import net.sf.jabref.gui.keyboard.KeyBinding; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.protectedterms.ProtectedTermsLoader; +import net.sf.jabref.logic.util.FileExtensions; import com.jgoodies.forms.builder.ButtonBarBuilder; import com.jgoodies.forms.builder.FormBuilder; diff --git a/src/main/java/net/sf/jabref/gui/protectedterms/ProtectedTermsDialog.java b/src/main/java/net/sf/jabref/gui/protectedterms/ProtectedTermsDialog.java index 93f3dcf3756..97826dddccf 100644 --- a/src/main/java/net/sf/jabref/gui/protectedterms/ProtectedTermsDialog.java +++ b/src/main/java/net/sf/jabref/gui/protectedterms/ProtectedTermsDialog.java @@ -53,8 +53,6 @@ import net.sf.jabref.external.ExternalFileType; import net.sf.jabref.external.ExternalFileTypes; import net.sf.jabref.external.UnknownExternalFileType; - -import net.sf.jabref.gui.FileExtensions; import net.sf.jabref.gui.IconTheme; import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.actions.BrowseAction; @@ -65,6 +63,7 @@ import net.sf.jabref.logic.protectedterms.ProtectedTermsList; import net.sf.jabref.logic.protectedterms.ProtectedTermsLoader; import net.sf.jabref.logic.protectedterms.ProtectedTermsPreferences; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.util.OS; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/BibTeXMLImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/BibTeXMLImporter.java index 8ef53c3a014..794da34d4d6 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/BibTeXMLImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/BibTeXMLImporter.java @@ -18,7 +18,6 @@ import java.io.BufferedReader; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.regex.Pattern; @@ -28,6 +27,7 @@ import net.sf.jabref.logic.importer.ParserResult; import net.sf.jabref.logic.importer.util.BibTeXMLHandler; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import org.apache.commons.logging.Log; @@ -52,8 +52,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Collections.singletonList(".xml"); + public FileExtensions getExtensions() { + return FileExtensions.BIBTEXML; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/BiblioscapeImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/BiblioscapeImporter.java index 38aa78bc6cc..15820a1e114 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/BiblioscapeImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/BiblioscapeImporter.java @@ -18,13 +18,13 @@ import java.io.BufferedReader; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import net.sf.jabref.logic.importer.ParserResult; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; @@ -42,8 +42,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Collections.singletonList(".txt"); + public FileExtensions getExtensions() { + return FileExtensions.BILBIOSCAPE; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/BibtexImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/BibtexImporter.java index f773c1b4e59..ef837c26da4 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/BibtexImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/BibtexImporter.java @@ -19,14 +19,13 @@ import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Path; -import java.util.Collections; -import java.util.List; import java.util.Objects; import java.util.Optional; import net.sf.jabref.logic.exporter.SavePreferences; import net.sf.jabref.logic.importer.ImportFormatPreferences; import net.sf.jabref.logic.importer.ParserResult; +import net.sf.jabref.logic.util.FileExtensions; /** * This importer exists only to enable `--importToOpen someEntry.bib` @@ -91,8 +90,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Collections.singletonList(".bib"); + public FileExtensions getExtensions() { + return FileExtensions.BIBTEX_DB; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/CopacImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/CopacImporter.java index 43e728d6e8b..add5b7ce97b 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/CopacImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/CopacImporter.java @@ -17,13 +17,13 @@ import java.io.BufferedReader; import java.io.IOException; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.regex.Pattern; import net.sf.jabref.logic.importer.ParserResult; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; @@ -44,8 +44,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Collections.singletonList(".txt"); + public FileExtensions getExtensions() { + return FileExtensions.COPAC; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/EndnoteImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/EndnoteImporter.java index a3eaf3d5640..0f9e9c95135 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/EndnoteImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/EndnoteImporter.java @@ -18,7 +18,6 @@ import java.io.BufferedReader; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -27,6 +26,7 @@ import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.logic.importer.ImportFormatPreferences; import net.sf.jabref.logic.importer.ParserResult; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.AuthorList; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; @@ -58,8 +58,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Collections.singletonList(".enw"); + public FileExtensions getExtensions() { + return FileExtensions.ENDNOTE; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/FreeCiteImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/FreeCiteImporter.java index a4254bad6ff..fa213f8bab9 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/FreeCiteImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/FreeCiteImporter.java @@ -25,7 +25,6 @@ import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Scanner; @@ -40,6 +39,7 @@ import net.sf.jabref.logic.importer.ImportFormatPreferences; import net.sf.jabref.logic.importer.ParserResult; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.util.OS; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.BibtexEntryTypes; @@ -72,8 +72,7 @@ public boolean isRecognizedFormat(BufferedReader reader) throws IOException { } @Override - public ParserResult importDatabase(BufferedReader reader) - throws IOException { + public ParserResult importDatabase(BufferedReader reader) throws IOException { try (Scanner scan = new Scanner(reader)) { String text = scan.useDelimiter("\\A").next(); return importEntries(text); @@ -174,16 +173,11 @@ public ParserResult importEntries(String text) { type = BibtexEntryTypes.TECHREPORT; // the content of the "tech" field seems to contain the number of the technical report e.setField(FieldName.NUMBER, parser.getElementText()); - } else if (FieldName.DOI.equals(ln) - || FieldName.INSTITUTION.equals(ln) - || FieldName.LOCATION.equals(ln) - || FieldName.NUMBER.equals(ln) - || FieldName.NOTE.equals(ln) - || FieldName.TITLE.equals(ln) - || FieldName.PAGES.equals(ln) - || FieldName.PUBLISHER.equals(ln) - || FieldName.VOLUME.equals(ln) - || FieldName.YEAR.equals(ln)) { + } else if (FieldName.DOI.equals(ln) || FieldName.INSTITUTION.equals(ln) + || FieldName.LOCATION.equals(ln) || FieldName.NUMBER.equals(ln) + || FieldName.NOTE.equals(ln) || FieldName.TITLE.equals(ln) + || FieldName.PAGES.equals(ln) || FieldName.PUBLISHER.equals(ln) + || FieldName.VOLUME.equals(ln) || FieldName.YEAR.equals(ln)) { e.setField(ln, parser.getElementText()); } else if (FieldName.BOOKTITLE.equals(ln)) { String booktitle = parser.getElementText(); @@ -210,7 +204,8 @@ public ParserResult importEntries(String text) { String note; if (e.hasField(FieldName.NOTE)) { // "note" could have been set during the parsing as FreeCite also returns "note" - note = e.getFieldOptional(FieldName.NOTE).get().concat(OS.NEWLINE).concat(noteSB.toString()); + note = e.getFieldOptional(FieldName.NOTE).get().concat(OS.NEWLINE) + .concat(noteSB.toString()); } else { note = noteSB.toString(); } @@ -246,8 +241,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Arrays.asList(".txt",".xml"); + public FileExtensions getExtensions() { + return FileExtensions.FREECITE; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/ImportFormat.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/ImportFormat.java index 494d7ce939a..2f32b312a22 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/ImportFormat.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/ImportFormat.java @@ -23,10 +23,10 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.util.List; import java.util.Objects; import net.sf.jabref.logic.importer.ParserResult; +import net.sf.jabref.logic.util.FileExtensions; /** * Role of an importer for JabRef. @@ -117,13 +117,12 @@ public static BufferedReader getReader(Path filePath, Charset encoding) */ public abstract String getFormatName(); + /** - * Returns the file extensions that this importer can read. - * The extension should contain the leading dot, so for example ".bib" - * - * @return list of supported file extensions (not null but may be empty). The list should never be null. Instead return an empty list. + * Returns the file extensions that this importer can read + * @return {@link FileExtensions} correspoding to the importer */ - public abstract List getExtensions(); + public abstract FileExtensions getExtensions(); /** * Returns a one-word ID which identifies this import format. diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/InspecImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/InspecImporter.java index 07df6333aef..00576923380 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/InspecImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/InspecImporter.java @@ -18,13 +18,13 @@ import java.io.BufferedReader; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Pattern; import net.sf.jabref.logic.importer.ParserResult; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.AuthorList; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; @@ -42,8 +42,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Collections.singletonList(".txt"); + public FileExtensions getExtensions() { + return FileExtensions.INSPEC; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/IsiImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/IsiImporter.java index 2c29b2eb838..6beed50c246 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/IsiImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/IsiImporter.java @@ -18,7 +18,6 @@ import java.io.BufferedReader; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -28,6 +27,7 @@ import net.sf.jabref.logic.formatter.casechanger.TitleCaseFormatter; import net.sf.jabref.logic.importer.ParserResult; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; import net.sf.jabref.model.entry.MonthUtil; @@ -64,8 +64,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Arrays.asList(".isi",".txt"); + public FileExtensions getExtensions() { + return FileExtensions.ISI; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/MedlineImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/MedlineImporter.java index a56c8bdc848..3b437c5caba 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/MedlineImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/MedlineImporter.java @@ -19,7 +19,6 @@ import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -79,6 +78,7 @@ import net.sf.jabref.logic.importer.fileformat.medline.Section; import net.sf.jabref.logic.importer.fileformat.medline.Sections; import net.sf.jabref.logic.importer.fileformat.medline.Text; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.util.strings.StringUtil; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; @@ -108,8 +108,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Arrays.asList(".nbib", ".xml"); + public FileExtensions getExtensions() { + return FileExtensions.MEDLINE; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/MedlinePlainImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/MedlinePlainImporter.java index c8d5c379c5d..5ea2bc4f667 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/MedlinePlainImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/MedlinePlainImporter.java @@ -20,7 +20,6 @@ import java.io.BufferedReader; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -28,6 +27,7 @@ import java.util.regex.Pattern; import net.sf.jabref.logic.importer.ParserResult; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.util.OS; import net.sf.jabref.model.entry.AuthorList; import net.sf.jabref.model.entry.BibEntry; @@ -56,8 +56,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Arrays.asList(".nbib", ".txt"); + public FileExtensions getExtensions() { + return FileExtensions.MEDLINE_PLAIN; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/MsBibImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/MsBibImporter.java index f96a8fccafc..103233f524b 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/MsBibImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/MsBibImporter.java @@ -17,8 +17,6 @@ import java.io.BufferedReader; import java.io.IOException; -import java.util.Collections; -import java.util.List; import java.util.Objects; import javax.xml.parsers.DocumentBuilder; @@ -26,6 +24,7 @@ import net.sf.jabref.logic.importer.ParserResult; import net.sf.jabref.logic.msbib.MSBibDatabase; +import net.sf.jabref.logic.util.FileExtensions; import org.w3c.dom.Document; import org.xml.sax.InputSource; @@ -73,8 +72,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Collections.singletonList(".xml"); + public FileExtensions getExtensions() { + return FileExtensions.MSBIB; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/OvidImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/OvidImporter.java index 1d007ac05aa..e86b9311828 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/OvidImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/OvidImporter.java @@ -18,7 +18,6 @@ import java.io.BufferedReader; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -26,6 +25,7 @@ import java.util.regex.Pattern; import net.sf.jabref.logic.importer.ParserResult; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.AuthorList; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; @@ -62,8 +62,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Collections.singletonList(".txt"); + public FileExtensions getExtensions() { + return FileExtensions.OVID; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporter.java index 75b021fee06..fa5411df5ef 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporter.java @@ -21,8 +21,6 @@ import java.nio.charset.Charset; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.regex.Matcher; @@ -33,6 +31,7 @@ import net.sf.jabref.logic.importer.fetcher.DOItoBibTeX; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.util.DOI; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.xmp.EncryptedPdfsNotSupportedException; import net.sf.jabref.logic.xmp.XMPUtil; import net.sf.jabref.model.entry.BibEntry; @@ -602,8 +601,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Collections.singletonList(".pdf"); + public FileExtensions getExtensions() { + return FileExtensions.PDF_CONTENT; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/PdfXmpImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/PdfXmpImporter.java index d3c55726927..0d82a65b703 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/PdfXmpImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/PdfXmpImporter.java @@ -19,12 +19,11 @@ import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Path; -import java.util.Collections; -import java.util.List; import java.util.Objects; import net.sf.jabref.logic.importer.ParserResult; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.xmp.XMPPreferences; import net.sf.jabref.logic.xmp.XMPUtil; @@ -46,8 +45,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Collections.singletonList(".pdf"); + public FileExtensions getExtensions() { + return FileExtensions.XMP; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/RepecNepImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/RepecNepImporter.java index 5241d5e88da..0144bef3f9c 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/RepecNepImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/RepecNepImporter.java @@ -25,7 +25,6 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collection; -import java.util.Collections; import java.util.Date; import java.util.GregorianCalendar; import java.util.LinkedHashSet; @@ -34,6 +33,7 @@ import net.sf.jabref.logic.importer.ImportFormatPreferences; import net.sf.jabref.logic.importer.ParserResult; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; import net.sf.jabref.model.entry.IdGenerator; @@ -190,8 +190,8 @@ public String getId() { } @Override - public List getExtensions() { - return Collections.singletonList(".txt"); + public FileExtensions getExtensions() { + return FileExtensions.REPEC; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/RisImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/RisImporter.java index 64d0c55b2e0..45efadb1337 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/RisImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/RisImporter.java @@ -18,13 +18,13 @@ import java.io.BufferedReader; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Pattern; import net.sf.jabref.logic.importer.ParserResult; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.util.OS; import net.sf.jabref.model.entry.AuthorList; import net.sf.jabref.model.entry.BibEntry; @@ -47,8 +47,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Collections.singletonList(".ris"); + public FileExtensions getExtensions() { + return FileExtensions.RIS; } @Override diff --git a/src/main/java/net/sf/jabref/logic/importer/fileformat/SilverPlatterImporter.java b/src/main/java/net/sf/jabref/logic/importer/fileformat/SilverPlatterImporter.java index 54e189795d9..f724821470c 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fileformat/SilverPlatterImporter.java +++ b/src/main/java/net/sf/jabref/logic/importer/fileformat/SilverPlatterImporter.java @@ -18,13 +18,13 @@ import java.io.BufferedReader; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Pattern; import net.sf.jabref.logic.importer.ParserResult; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.AuthorList; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; @@ -43,8 +43,8 @@ public String getFormatName() { } @Override - public List getExtensions() { - return Collections.singletonList(".txt"); + public FileExtensions getExtensions() { + return FileExtensions.SILVER_PLATTER; } @Override diff --git a/src/main/java/net/sf/jabref/logic/util/FileExtensions.java b/src/main/java/net/sf/jabref/logic/util/FileExtensions.java new file mode 100644 index 00000000000..93121ab944b --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/util/FileExtensions.java @@ -0,0 +1,72 @@ +package net.sf.jabref.logic.util; + +import java.util.StringJoiner; + +import net.sf.jabref.logic.l10n.Localization; + +/** + * + * + *This enum contains all kind of file extensions for open and save dialogs + *Important: Enter the extension without a dot! + *The dot is added implicit + */ +public enum FileExtensions { + + //important: No dot before the extension! + BIBTEX_DB(String.format("%1s %2s", "BibTex", Localization.lang("Database")), "bib"), + BIBTEXML(Localization.lang("%0 file", "BibTeXML"), "bibx"), + BILBIOSCAPE(Localization.lang("%0 file", "Biblioscape"), "txt"), + COPAC(Localization.lang("%0 file", "Copac"), "txt"), + ENDNOTE(Localization.lang("%0 file", "Endnote/Refer"), "ref", "enw"), + FREECITE(Localization.lang("%0 file", "FreeCite"), "txt", "xml"), + INSPEC(Localization.lang("%0 file", "INSPEC"), "txt"), + ISI(Localization.lang("%0 file", "ISI"), "isi", "txt"), + MEDLINE(Localization.lang("%0 file", "Medline"), "nbib", "xml"), + MEDLINE_PLAIN(Localization.lang("%0 file", "MedlinePlain"), "nbib", "txt"), + MSBIB(Localization.lang("%0 file", "MSBib"), "xml"), + OVID(Localization.lang("%0 file", "Ovid"), "txt"), + PDF_CONTENT(Localization.lang("%0 file", "PDF content "), "pdf"), + PUBMED(Localization.lang("%0 file", "PubMed"), "fcgi"), + REPEC("REPEC New Economic Papers (NEP)", "txt"), + RIS(Localization.lang("%0 file", "RIS"), "ris"), + SILVER_PLATTER(Localization.lang("%0 file", "SilverPlatter"), "dat", "txt"), + XMP(Localization.lang("XMP-annotated PDF"), "pdf"), + + AUX(Localization.lang("%0 file", "AUX"), "aux"), + JSTYLE(Localization.lang("Style file"), "jstyle"), + LAYOUT(Localization.lang("Custom layout file"), "layout"), + TERMS(Localization.lang("Protected terms file"), "terms"), + TXT(Localization.lang("%0 file", Localization.lang("Plain text")), "txt"), + CLASS(Localization.lang("%0 file", "CLASS"), "class"), + JAR(Localization.lang("%0 file", "JAR"), "jar"), + XML(Localization.lang("%0 file", "XML"), "xml"), + ZIP(Localization.lang("%0 file", "ZIP"), "zip"); + + private final String[] extension; + private final String description; + + + private FileExtensions(String description, String... extension) { + this.extension = extension; + this.description = description; + } + + //Array because a) is varags and b) gets passed as varags parameter to FileExtensionNameFilter + public String[] getExtensions() { + return extension; + } + + public String getDescription() { + + StringJoiner sj = new StringJoiner(", ", description + " (", ")"); + for (String ext : extension) { + sj.add("*." + ext); + } + return sj.toString(); + } + + public String getFirstExtensionWithDot() { + return "." + extension[0].trim(); + } +} diff --git a/src/test/java/net/sf/jabref/gui/importer/ImportFileFilterTest.java b/src/test/java/net/sf/jabref/gui/importer/ImportFileFilterTest.java deleted file mode 100644 index 667c901179f..00000000000 --- a/src/test/java/net/sf/jabref/gui/importer/ImportFileFilterTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package net.sf.jabref.gui.importer; - - -import java.util.Arrays; -import java.util.Collections; - -import net.sf.jabref.logic.importer.fileformat.ImportFormat; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - - -public class ImportFileFilterTest { - - @Test - public void nameWithSingleExtensions() { - ImportFormat importFormatSingleExtension = mock(ImportFormat.class); - when(importFormatSingleExtension.getFormatName()).thenReturn("Single Extension"); - when(importFormatSingleExtension.getExtensions()).thenReturn(Collections.singletonList(".abc")); - - ImportFileFilter importFileFilter = new ImportFileFilter(importFormatSingleExtension); - assertEquals("Single Extension (*.abc)", importFileFilter.getDescription()); - } - - @Test - public void nameWithMultipleExtensions() { - ImportFormat importFormatMultipleExtensions = mock(ImportFormat.class); - when(importFormatMultipleExtensions.getFormatName()).thenReturn("Multiple Extensions"); - when(importFormatMultipleExtensions.getExtensions()).thenReturn(Arrays.asList(".abc", ".xyz")); - - ImportFileFilter importFileFilter = new ImportFileFilter(importFormatMultipleExtensions); - assertEquals("Multiple Extensions (*.abc, *.xyz)", importFileFilter.getDescription()); - } - -} diff --git a/src/test/java/net/sf/jabref/logic/TypedBibEntryTest.java b/src/test/java/net/sf/jabref/logic/TypedBibEntryTest.java index db2fc8e20fd..8df0fd6efee 100644 --- a/src/test/java/net/sf/jabref/logic/TypedBibEntryTest.java +++ b/src/test/java/net/sf/jabref/logic/TypedBibEntryTest.java @@ -8,6 +8,7 @@ import org.junit.Test; public class TypedBibEntryTest { + @Test public void hasAllRequiredFieldsFail() { BibEntry e = new BibEntry("id", BibtexEntryTypes.ARTICLE.getName()); diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibTeXMLImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibTeXMLImporterTest.java index 8346188ef4f..164f34aba60 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibTeXMLImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibTeXMLImporterTest.java @@ -13,14 +13,17 @@ import net.sf.jabref.Globals; import net.sf.jabref.logic.importer.util.BibTeXMLHandler; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.preferences.JabRefPreferences; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + @RunWith(MockitoJUnitRunner.class) public class BibTeXMLImporterTest { @@ -52,27 +55,27 @@ public void setUp() throws Exception { @Test public void testGetItemsEmpty() { BibTeXMLHandler handler = new BibTeXMLHandler(); - Assert.assertEquals(Collections.emptyList(), handler.getItems()); + assertEquals(Collections.emptyList(), handler.getItems()); } @Test public void testGetFormatName() { - Assert.assertEquals("BibTeXML", importer.getFormatName()); + assertEquals("BibTeXML", importer.getFormatName()); } @Test public void testGetCLIId() { - Assert.assertEquals("bibtexml", importer.getId()); + assertEquals("bibtexml", importer.getId()); } @Test public void testsGetExtensions() { - Assert.assertEquals(Collections.singletonList(".xml"), importer.getExtensions()); + assertEquals(FileExtensions.BIBTEXML, importer.getExtensions()); } @Test public void testGetDescription() { - Assert.assertEquals("Importer for the BibTeXML format.", importer.getDescription()); + assertEquals("Importer for the BibTeXML format.", importer.getDescription()); } @Test @@ -82,7 +85,7 @@ public void testIsRecognizedFormatReject() throws IOException { .collect(Collectors.toList()); for (Path file : list) { - Assert.assertFalse(file.toString(), importer.isRecognizedFormat(file, Charset.defaultCharset())); + assertFalse(file.toString(), importer.isRecognizedFormat(file, Charset.defaultCharset())); } } } diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/BiblioscapeImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/BiblioscapeImporterTest.java index 6b8438a729f..02dac28a756 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/BiblioscapeImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/BiblioscapeImporterTest.java @@ -3,10 +3,10 @@ import java.nio.charset.Charset; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; import java.util.Collections; import net.sf.jabref.Globals; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.preferences.JabRefPreferences; import org.junit.Assert; @@ -31,7 +31,7 @@ public void testGetFormatName() { @Test public void testsGetExtensions() { - Assert.assertEquals(Arrays.asList(".txt"), importer.getExtensions()); + Assert.assertEquals(FileExtensions.BILBIOSCAPE, importer.getExtensions()); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexImporterTest.java index 882c37d3048..0ad9a43740e 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexImporterTest.java @@ -5,12 +5,12 @@ import java.nio.charset.Charset; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; import java.util.List; import java.util.Optional; import net.sf.jabref.Globals; import net.sf.jabref.logic.importer.ImportFormatPreferences; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; @@ -110,7 +110,7 @@ public void testGetFormatName() { @Test public void testsGetExtensions() { - assertEquals(Arrays.asList(".bib"), importer.getExtensions()); + assertEquals(FileExtensions.BIBTEX_DB, importer.getExtensions()); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/CopacImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/CopacImporterTest.java index f80709eca6d..39c2ff8db10 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/CopacImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/CopacImporterTest.java @@ -13,6 +13,7 @@ import java.util.stream.Collectors; import net.sf.jabref.Globals; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; @@ -48,10 +49,8 @@ public void setUp() throws Exception { @Test public void testsGetExtensions() { - List extensions = new ArrayList<>(); - extensions.add(".txt"); + Assert.assertEquals(FileExtensions.COPAC, importer.getExtensions()); - Assert.assertEquals(extensions.get(0), importer.getExtensions().get(0)); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/EndnoteImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/EndnoteImporterTest.java index 66aa187e53b..c7b2610e135 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/EndnoteImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/EndnoteImporterTest.java @@ -7,13 +7,13 @@ import java.nio.charset.Charset; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; import net.sf.jabref.Globals; import net.sf.jabref.logic.importer.ImportFormatPreferences; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; @@ -47,10 +47,9 @@ public void testGetCLIId() { @Test public void testsGetExtensions() { - List extensions = new ArrayList<>(); - extensions.add(".enw"); - assertEquals(extensions.get(0), importer.getExtensions().get(0)); + assertEquals(FileExtensions.ENDNOTE, importer.getExtensions()); + } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/FreeCiteImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/FreeCiteImporterTest.java index 5b57b142fa9..21265906907 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/FreeCiteImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/FreeCiteImporterTest.java @@ -1,8 +1,7 @@ package net.sf.jabref.logic.importer.fileformat; -import java.util.Arrays; - import net.sf.jabref.logic.importer.ImportFormatPreferences; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.preferences.JabRefPreferences; import org.junit.Before; @@ -14,6 +13,7 @@ public class FreeCiteImporterTest { private FreeCiteImporter importer; + @Before public void setUp() { importer = new FreeCiteImporter(ImportFormatPreferences.fromPreferences(JabRefPreferences.getInstance())); @@ -26,11 +26,12 @@ public void testGetFormatName() { @Test public void testsGetExtensions() { - assertEquals(Arrays.asList(".txt",".xml"), importer.getExtensions()); + assertEquals(FileExtensions.FREECITE, importer.getExtensions()); } @Test public void testGetDescription() { - assertEquals("This importer parses text format citations using the online API of FreeCite.", importer.getDescription()); + assertEquals("This importer parses text format citations using the online API of FreeCite.", + importer.getDescription()); } } diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/InspecImportTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/InspecImportTest.java index 9724a2e2102..09f8e42f4ea 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/InspecImportTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/InspecImportTest.java @@ -13,6 +13,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.logic.bibtex.BibEntryAssert; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; @@ -117,7 +118,7 @@ public void testGetCLIId() { @Test public void testsGetExtensions() { - assertEquals(".txt", importer.getExtensions().get(0)); + assertEquals(FileExtensions.INSPEC, importer.getExtensions()); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/IsiImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/IsiImporterTest.java index 684bb484f7b..6e3c7c82668 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/IsiImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/IsiImporterTest.java @@ -11,15 +11,19 @@ import java.util.Optional; import net.sf.jabref.Globals; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * Test cases for the IsiImporter */ @@ -43,22 +47,22 @@ public void testParseMonthException() { @Test public void testGetFormatName() { - Assert.assertEquals(importer.getFormatName(), "ISI"); + assertEquals(importer.getFormatName(), "ISI"); } @Test public void testGetCLIId() { - Assert.assertEquals(importer.getId(), "isi"); + assertEquals(importer.getId(), "isi"); } @Test public void testsGetExtensions() { - Assert.assertEquals(Arrays.asList(".isi",".txt"), importer.getExtensions()); + assertEquals(FileExtensions.ISI, importer.getExtensions()); } @Test public void testGetDescription() { - Assert.assertEquals("Importer for the ISI Web of Science, INSPEC and Medline format.", + assertEquals("Importer for the ISI Web of Science, INSPEC and Medline format.", importer.getDescription()); } @@ -69,7 +73,7 @@ public void testIsRecognizedFormatAccepted() throws IOException, URISyntaxExcept for (String str : list) { Path file = Paths.get(IsiImporterTest.class.getResource(str).toURI()); - Assert.assertTrue(importer.isRecognizedFormat(file, Charset.defaultCharset())); + assertTrue(importer.isRecognizedFormat(file, Charset.defaultCharset())); } } @@ -79,7 +83,7 @@ public void testIsRecognizedFormatRejected() throws IOException, URISyntaxExcept for (String str : list) { Path file = Paths.get(IsiImporterTest.class.getResource(str).toURI()); - Assert.assertFalse(importer.isRecognizedFormat(file, Charset.defaultCharset())); + assertFalse(importer.isRecognizedFormat(file, Charset.defaultCharset())); } } @@ -89,79 +93,81 @@ public void testProcessSubSup() { HashMap hm = new HashMap<>(); hm.put("title", "/sub 3/"); IsiImporter.processSubSup(hm); - Assert.assertEquals("$_3$", hm.get("title")); + assertEquals("$_3$", hm.get("title")); hm.put("title", "/sub 3 /"); IsiImporter.processSubSup(hm); - Assert.assertEquals("$_3$", hm.get("title")); + assertEquals("$_3$", hm.get("title")); hm.put("title", "/sub 31/"); IsiImporter.processSubSup(hm); - Assert.assertEquals("$_{31}$", hm.get("title")); + assertEquals("$_{31}$", hm.get("title")); hm.put("abstract", "/sub 3/"); IsiImporter.processSubSup(hm); - Assert.assertEquals("$_3$", hm.get("abstract")); + assertEquals("$_3$", hm.get("abstract")); hm.put("review", "/sub 31/"); IsiImporter.processSubSup(hm); - Assert.assertEquals("$_{31}$", hm.get("review")); + assertEquals("$_{31}$", hm.get("review")); hm.put("title", "/sup 3/"); IsiImporter.processSubSup(hm); - Assert.assertEquals("$^3$", hm.get("title")); + assertEquals("$^3$", hm.get("title")); hm.put("title", "/sup 31/"); IsiImporter.processSubSup(hm); - Assert.assertEquals("$^{31}$", hm.get("title")); + assertEquals("$^{31}$", hm.get("title")); hm.put("abstract", "/sup 3/"); IsiImporter.processSubSup(hm); - Assert.assertEquals("$^3$", hm.get("abstract")); + assertEquals("$^3$", hm.get("abstract")); hm.put("review", "/sup 31/"); IsiImporter.processSubSup(hm); - Assert.assertEquals("$^{31}$", hm.get("review")); + assertEquals("$^{31}$", hm.get("review")); hm.put("title", "/sub $Hello/"); IsiImporter.processSubSup(hm); - Assert.assertEquals("$_{\\$Hello}$", hm.get("title")); + assertEquals("$_{\\$Hello}$", hm.get("title")); } @Test public void testImportEntries1() throws IOException, URISyntaxException { Path file = Paths.get(IsiImporterTest.class.getResource("IsiImporterTest1.isi").toURI()); List entries = importer.importDatabase(file, Charset.defaultCharset()).getDatabase().getEntries(); - Assert.assertEquals(1, entries.size()); + assertEquals(1, entries.size()); BibEntry entry = entries.get(0); - Assert.assertEquals(Optional.of("Optical properties of MgO doped LiNbO$_3$ single crystals"), entry.getFieldOptional("title")); - Assert.assertEquals( + assertEquals(Optional.of("Optical properties of MgO doped LiNbO$_3$ single crystals"), + entry.getFieldOptional("title")); + assertEquals( Optional.of( "James Brown and James Marc Brown and Brown, J. M. and Brown, J. and Brown, J. M. and Brown, J."), entry.getFieldOptional("author")); - Assert.assertEquals("article", entry.getType()); - Assert.assertEquals(Optional.of("Optical Materials"), entry.getFieldOptional("journal")); - Assert.assertEquals(Optional.of("2006"), entry.getFieldOptional("year")); - Assert.assertEquals(Optional.of("28"), entry.getFieldOptional("volume")); - Assert.assertEquals(Optional.of("5"), entry.getFieldOptional("number")); - Assert.assertEquals(Optional.of("467--72"), entry.getFieldOptional("pages")); + assertEquals("article", entry.getType()); + assertEquals(Optional.of("Optical Materials"), entry.getFieldOptional("journal")); + assertEquals(Optional.of("2006"), entry.getFieldOptional("year")); + assertEquals(Optional.of("28"), entry.getFieldOptional("volume")); + assertEquals(Optional.of("5"), entry.getFieldOptional("number")); + assertEquals(Optional.of("467--72"), entry.getFieldOptional("pages")); } @Test public void testImportEntries2() throws IOException, URISyntaxException { Path file = Paths.get(IsiImporterTest.class.getResource("IsiImporterTest2.isi").toURI()); List entries = importer.importDatabase(file, Charset.defaultCharset()).getDatabase().getEntries(); - Assert.assertEquals(3, entries.size()); + assertEquals(3, entries.size()); BibEntry entry = entries.get(0); - Assert.assertEquals(Optional.of("Optical properties of MgO doped LiNbO$_3$ single crystals"), entry.getFieldOptional("title")); - - Assert.assertEquals("misc", entry.getType()); - Assert.assertEquals(Optional.of("Optical Materials"), entry.getFieldOptional("journal")); - Assert.assertEquals(Optional.of("2006"), entry.getFieldOptional("year")); - Assert.assertEquals(Optional.of("28"), entry.getFieldOptional("volume")); - Assert.assertEquals(Optional.of("5"), entry.getFieldOptional("number")); - Assert.assertEquals(Optional.of("467-72"), entry.getFieldOptional("pages")); + assertEquals(Optional.of("Optical properties of MgO doped LiNbO$_3$ single crystals"), + entry.getFieldOptional("title")); + + assertEquals("misc", entry.getType()); + assertEquals(Optional.of("Optical Materials"), entry.getFieldOptional("journal")); + assertEquals(Optional.of("2006"), entry.getFieldOptional("year")); + assertEquals(Optional.of("28"), entry.getFieldOptional("volume")); + assertEquals(Optional.of("5"), entry.getFieldOptional("number")); + assertEquals(Optional.of("467-72"), entry.getFieldOptional("pages")); } @Test @@ -169,7 +175,7 @@ public void testImportEntriesINSPEC() throws IOException, URISyntaxException { Path file = Paths.get(IsiImporterTest.class.getResource("IsiImporterTestInspec.isi").toURI()); List entries = importer.importDatabase(file, Charset.defaultCharset()).getDatabase().getEntries(); - Assert.assertEquals(2, entries.size()); + assertEquals(2, entries.size()); BibEntry a = entries.get(0); BibEntry b = entries.get(1); @@ -180,25 +186,26 @@ public void testImportEntriesINSPEC() throws IOException, URISyntaxException { b = tmp; } - Assert.assertEquals( + assertEquals( Optional.of( "Second harmonic generation of continuous wave ultraviolet light and production of beta -BaB$_2$O$_4$ optical waveguides"), a.getFieldOptional("title")); - Assert.assertEquals("article", a.getType()); - - Assert.assertEquals(Optional.of("Degl'Innocenti, R. and Guarino, A. and Poberaj, G. and Gunter, P."), a.getFieldOptional("author")); - Assert.assertEquals(Optional.of("Applied Physics Letters"), a.getFieldOptional("journal")); - Assert.assertEquals(Optional.of("2006"), a.getFieldOptional("year")); - Assert.assertEquals(Optional.of("#jul#"), a.getFieldOptional("month")); - Assert.assertEquals(Optional.of("89"), a.getFieldOptional("volume")); - Assert.assertEquals(Optional.of("4"), a.getFieldOptional("number")); - Assert.assertEquals(Optional.of("Lorem ipsum abstract"), a.getFieldOptional("abstract")); - Assert.assertEquals(Optional.of("Aip"), a.getFieldOptional("publisher")); - - Assert.assertEquals( + assertEquals("article", a.getType()); + + assertEquals(Optional.of("Degl'Innocenti, R. and Guarino, A. and Poberaj, G. and Gunter, P."), + a.getFieldOptional("author")); + assertEquals(Optional.of("Applied Physics Letters"), a.getFieldOptional("journal")); + assertEquals(Optional.of("2006"), a.getFieldOptional("year")); + assertEquals(Optional.of("#jul#"), a.getFieldOptional("month")); + assertEquals(Optional.of("89"), a.getFieldOptional("volume")); + assertEquals(Optional.of("4"), a.getFieldOptional("number")); + assertEquals(Optional.of("Lorem ipsum abstract"), a.getFieldOptional("abstract")); + assertEquals(Optional.of("Aip"), a.getFieldOptional("publisher")); + + assertEquals( Optional.of("Optical and photoelectric spectroscopy of photorefractive Sn$_2$P$_2$S$_6$ crystals"), b.getFieldOptional("title")); - Assert.assertEquals("article", b.getType()); + assertEquals("article", b.getType()); } @Test @@ -206,26 +213,26 @@ public void testImportEntriesWOS() throws IOException, URISyntaxException { Path file = Paths.get(IsiImporterTest.class.getResource("IsiImporterTestWOS.isi").toURI()); List entries = importer.importDatabase(file, Charset.defaultCharset()).getDatabase().getEntries(); - Assert.assertEquals(2, entries.size()); + assertEquals(2, entries.size()); BibEntry a = entries.get(0); BibEntry b = entries.get(1); - Assert.assertEquals(Optional.of("Optical and photoelectric spectroscopy of photorefractive Sn2P2S6 crystals"), + assertEquals(Optional.of("Optical and photoelectric spectroscopy of photorefractive Sn2P2S6 crystals"), a.getFieldOptional("title")); - Assert.assertEquals(Optional.of("Optical waveguides in Sn2P2S6 by low fluence MeV He+ ion implantation"), + assertEquals(Optional.of("Optical waveguides in Sn2P2S6 by low fluence MeV He+ ion implantation"), b.getFieldOptional("title")); - Assert.assertEquals(Optional.of("Journal of Physics-condensed Matter"), a.getFieldOptional("journal")); + assertEquals(Optional.of("Journal of Physics-condensed Matter"), a.getFieldOptional("journal")); } @Test public void testIsiAuthorsConvert() { - Assert.assertEquals( + assertEquals( "James Brown and James Marc Brown and Brown, J. M. and Brown, J. and Brown, J. M. and Brown, J.", IsiImporter.isiAuthorsConvert( "James Brown and James Marc Brown and Brown, J.M. and Brown, J. and Brown, J.M. and Brown, J.")); - Assert.assertEquals( + assertEquals( "Joffe, Hadine and Hall, Janet E. and Gruber, Staci and Sarmiento, Ingrid A. and Cohen, Lee S. and Yurgelun-Todd, Deborah and Martin, Kathryn A.", IsiImporter.isiAuthorsConvert( "Joffe, Hadine; Hall, Janet E; Gruber, Staci; Sarmiento, Ingrid A; Cohen, Lee S; Yurgelun-Todd, Deborah; Martin, Kathryn A")); @@ -235,27 +242,27 @@ public void testIsiAuthorsConvert() { @Test public void testMonthConvert() { - Assert.assertEquals("#jun#", IsiImporter.parseMonth("06")); - Assert.assertEquals("#jun#", IsiImporter.parseMonth("JUN")); - Assert.assertEquals("#jun#", IsiImporter.parseMonth("jUn")); - Assert.assertEquals("#may#", IsiImporter.parseMonth("MAY-JUN")); - Assert.assertEquals("#jun#", IsiImporter.parseMonth("2006 06")); - Assert.assertEquals("#jun#", IsiImporter.parseMonth("2006 06-07")); - Assert.assertEquals("#jul#", IsiImporter.parseMonth("2006 07 03")); - Assert.assertEquals("#may#", IsiImporter.parseMonth("2006 May-Jun")); + assertEquals("#jun#", IsiImporter.parseMonth("06")); + assertEquals("#jun#", IsiImporter.parseMonth("JUN")); + assertEquals("#jun#", IsiImporter.parseMonth("jUn")); + assertEquals("#may#", IsiImporter.parseMonth("MAY-JUN")); + assertEquals("#jun#", IsiImporter.parseMonth("2006 06")); + assertEquals("#jun#", IsiImporter.parseMonth("2006 06-07")); + assertEquals("#jul#", IsiImporter.parseMonth("2006 07 03")); + assertEquals("#may#", IsiImporter.parseMonth("2006 May-Jun")); } @Test public void testIsiAuthorConvert() { - Assert.assertEquals("James Brown", IsiImporter.isiAuthorConvert("James Brown")); - Assert.assertEquals("James Marc Brown", IsiImporter.isiAuthorConvert("James Marc Brown")); - Assert.assertEquals("Brown, J. M.", IsiImporter.isiAuthorConvert("Brown, J.M.")); - Assert.assertEquals("Brown, J.", IsiImporter.isiAuthorConvert("Brown, J.")); - Assert.assertEquals("Brown, J. M.", IsiImporter.isiAuthorConvert("Brown, JM")); - Assert.assertEquals("Brown, J.", IsiImporter.isiAuthorConvert("Brown, J")); - Assert.assertEquals("Brown, James", IsiImporter.isiAuthorConvert("Brown, James")); - Assert.assertEquals("Hall, Janet E.", IsiImporter.isiAuthorConvert("Hall, Janet E")); - Assert.assertEquals("", IsiImporter.isiAuthorConvert("")); + assertEquals("James Brown", IsiImporter.isiAuthorConvert("James Brown")); + assertEquals("James Marc Brown", IsiImporter.isiAuthorConvert("James Marc Brown")); + assertEquals("Brown, J. M.", IsiImporter.isiAuthorConvert("Brown, J.M.")); + assertEquals("Brown, J.", IsiImporter.isiAuthorConvert("Brown, J.")); + assertEquals("Brown, J. M.", IsiImporter.isiAuthorConvert("Brown, JM")); + assertEquals("Brown, J.", IsiImporter.isiAuthorConvert("Brown, J")); + assertEquals("Brown, James", IsiImporter.isiAuthorConvert("Brown, James")); + assertEquals("Hall, Janet E.", IsiImporter.isiAuthorConvert("Hall, Janet E")); + assertEquals("", IsiImporter.isiAuthorConvert("")); } @Test @@ -263,21 +270,22 @@ public void testImportIEEEExport() throws IOException, URISyntaxException { Path file = Paths.get(IsiImporterTest.class.getResource("IEEEImport1.txt").toURI()); List entries = importer.importDatabase(file, Charset.defaultCharset()).getDatabase().getEntries(); - Assert.assertEquals(1, entries.size()); + assertEquals(1, entries.size()); BibEntry a = entries.get(0); - Assert.assertEquals("article", a.getType()); - Assert.assertEquals(Optional.of("Geoscience and Remote Sensing Letters, IEEE"), a.getFieldOptional("journal")); - Assert.assertEquals(Optional.of("Improving Urban Road Extraction in High-Resolution " + assertEquals("article", a.getType()); + assertEquals(Optional.of("Geoscience and Remote Sensing Letters, IEEE"), a.getFieldOptional("journal")); + assertEquals(Optional.of("Improving Urban Road Extraction in High-Resolution " + "Images Exploiting Directional Filtering, Perceptual " + "Grouping, and Simple Topological Concepts"), a.getFieldOptional("title")); - Assert.assertEquals(Optional.of("4"), a.getFieldOptional("volume")); - Assert.assertEquals(Optional.of("3"), a.getFieldOptional("number")); - Assert.assertEquals(Optional.of("1545-598X"), a.getFieldOptional("SN")); - Assert.assertEquals(Optional.of("387--391"), a.getFieldOptional("pages")); - Assert.assertEquals(Optional.of("Gamba, P. and Dell'Acqua, F. and Lisini, G."), a.getFieldOptional("author")); - Assert.assertEquals(Optional.of("2006"), a.getFieldOptional("year")); - Assert.assertEquals(Optional.of("Perceptual grouping, street extraction, urban remote sensing"), a.getFieldOptional("keywords")); - Assert.assertEquals(Optional.of("Lorem ipsum abstract"), a.getFieldOptional("abstract")); + assertEquals(Optional.of("4"), a.getFieldOptional("volume")); + assertEquals(Optional.of("3"), a.getFieldOptional("number")); + assertEquals(Optional.of("1545-598X"), a.getFieldOptional("SN")); + assertEquals(Optional.of("387--391"), a.getFieldOptional("pages")); + assertEquals(Optional.of("Gamba, P. and Dell'Acqua, F. and Lisini, G."), a.getFieldOptional("author")); + assertEquals(Optional.of("2006"), a.getFieldOptional("year")); + assertEquals(Optional.of("Perceptual grouping, street extraction, urban remote sensing"), + a.getFieldOptional("keywords")); + assertEquals(Optional.of("Lorem ipsum abstract"), a.getFieldOptional("abstract")); } @Test @@ -285,23 +293,24 @@ public void testIEEEImport() throws IOException, URISyntaxException { Path file = Paths.get(IsiImporterTest.class.getResource("IEEEImport1.txt").toURI()); List entries = importer.importDatabase(file, Charset.defaultCharset()).getDatabase().getEntries(); - Assert.assertEquals(1, entries.size()); + assertEquals(1, entries.size()); BibEntry a = entries.get(0); - Assert.assertEquals("article", a.getType()); - Assert.assertEquals(Optional.of("Geoscience and Remote Sensing Letters, IEEE"), a.getFieldOptional("journal")); - Assert.assertEquals( + assertEquals("article", a.getType()); + assertEquals(Optional.of("Geoscience and Remote Sensing Letters, IEEE"), a.getFieldOptional("journal")); + assertEquals( Optional.of( "Improving Urban Road Extraction in High-Resolution Images Exploiting Directional Filtering, Perceptual Grouping, and Simple Topological Concepts"), a.getFieldOptional("title")); - Assert.assertEquals(Optional.of("4"), a.getFieldOptional("volume")); - Assert.assertEquals(Optional.of("3"), a.getFieldOptional("number")); - Assert.assertEquals(Optional.of("1545-598X"), a.getFieldOptional("SN")); - Assert.assertEquals(Optional.of("387--391"), a.getFieldOptional("pages")); - Assert.assertEquals(Optional.of("Gamba, P. and Dell'Acqua, F. and Lisini, G."), a.getFieldOptional("author")); - Assert.assertEquals(Optional.of("2006"), a.getFieldOptional("year")); - Assert.assertEquals(Optional.of("Perceptual grouping, street extraction, urban remote sensing"), a.getFieldOptional("keywords")); - Assert.assertEquals(Optional.of("Lorem ipsum abstract"), a.getFieldOptional("abstract")); + assertEquals(Optional.of("4"), a.getFieldOptional("volume")); + assertEquals(Optional.of("3"), a.getFieldOptional("number")); + assertEquals(Optional.of("1545-598X"), a.getFieldOptional("SN")); + assertEquals(Optional.of("387--391"), a.getFieldOptional("pages")); + assertEquals(Optional.of("Gamba, P. and Dell'Acqua, F. and Lisini, G."), a.getFieldOptional("author")); + assertEquals(Optional.of("2006"), a.getFieldOptional("year")); + assertEquals(Optional.of("Perceptual grouping, street extraction, urban remote sensing"), + a.getFieldOptional("keywords")); + assertEquals(Optional.of("Lorem ipsum abstract"), a.getFieldOptional("abstract")); } @Test @@ -310,37 +319,37 @@ public void testImportEntriesMedline() throws IOException, URISyntaxException { List entries = importer.importDatabase(file, Charset.defaultCharset()).getDatabase().getEntries(); - Assert.assertEquals(2, entries.size()); + assertEquals(2, entries.size()); BibEntry a = entries.get(0); BibEntry b = entries.get(1); - Assert.assertEquals( + assertEquals( Optional.of("Effects of modafinil on cognitive performance and alertness during sleep deprivation."), a.getFieldOptional("title")); - Assert.assertEquals(Optional.of("Wesensten, Nancy J."), a.getFieldOptional("author")); - Assert.assertEquals(Optional.of("Curr Pharm Des"), a.getFieldOptional("journal")); - Assert.assertEquals(Optional.of("2006"), a.getFieldOptional("year")); - Assert.assertEquals(Optional.empty(), a.getFieldOptional("month")); - Assert.assertEquals(Optional.of("12"), a.getFieldOptional("volume")); - Assert.assertEquals(Optional.of("20"), a.getFieldOptional("number")); - Assert.assertEquals(Optional.of("2457--71"), a.getFieldOptional("pages")); - Assert.assertEquals("article", a.getType()); + assertEquals(Optional.of("Wesensten, Nancy J."), a.getFieldOptional("author")); + assertEquals(Optional.of("Curr Pharm Des"), a.getFieldOptional("journal")); + assertEquals(Optional.of("2006"), a.getFieldOptional("year")); + assertEquals(Optional.empty(), a.getFieldOptional("month")); + assertEquals(Optional.of("12"), a.getFieldOptional("volume")); + assertEquals(Optional.of("20"), a.getFieldOptional("number")); + assertEquals(Optional.of("2457--71"), a.getFieldOptional("pages")); + assertEquals("article", a.getType()); - Assert.assertEquals( + assertEquals( Optional.of( "Estrogen therapy selectively enhances prefrontal cognitive processes: a randomized, double-blind, placebo-controlled study with functional magnetic resonance imaging in perimenopausal and recently postmenopausal women."), b.getFieldOptional("title")); - Assert.assertEquals( + assertEquals( Optional.of( "Joffe, Hadine and Hall, Janet E. and Gruber, Staci and Sarmiento, Ingrid A. and Cohen, Lee S. and Yurgelun-Todd, Deborah and Martin, Kathryn A."), b.getFieldOptional("author")); - Assert.assertEquals(Optional.of("2006"), b.getFieldOptional("year")); - Assert.assertEquals(Optional.of("#may#"), b.getFieldOptional("month")); - Assert.assertEquals(Optional.of("13"), b.getFieldOptional("volume")); - Assert.assertEquals(Optional.of("3"), b.getFieldOptional("number")); - Assert.assertEquals(Optional.of("411--22"), b.getFieldOptional("pages")); - Assert.assertEquals("article", b.getType()); + assertEquals(Optional.of("2006"), b.getFieldOptional("year")); + assertEquals(Optional.of("#may#"), b.getFieldOptional("month")); + assertEquals(Optional.of("13"), b.getFieldOptional("volume")); + assertEquals(Optional.of("3"), b.getFieldOptional("number")); + assertEquals(Optional.of("411--22"), b.getFieldOptional("pages")); + assertEquals("article", b.getType()); } @Test @@ -349,6 +358,6 @@ public void testImportEntriesEmpty() throws IOException, URISyntaxException { List entries = importer.importDatabase(file, Charset.defaultCharset()).getDatabase().getEntries(); - Assert.assertEquals(1, entries.size()); + assertEquals(1, entries.size()); } } diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/MedlineImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/MedlineImporterTest.java index 26acf6f4ca7..e50ef9cf8e1 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/MedlineImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/MedlineImporterTest.java @@ -11,6 +11,7 @@ import java.util.stream.Collectors; import net.sf.jabref.Globals; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.preferences.JabRefPreferences; import org.junit.Assert; @@ -38,7 +39,7 @@ public class MedlineImporterTest { private MedlineImporter importer; private static final String FILEFORMAT_PATH = "src/test/resources/net/sf/jabref/logic/importer/fileformat"; - + /** * Generates a List of all files in the package "/src/test/resources/net/sf/jabref/logic/importer/fileformat" * @return A list of Names @@ -70,12 +71,7 @@ public void testGetCLIId() { @Test public void testsGetExtensions() { - List extensions = new ArrayList<>(); - extensions.add(".nbib"); - extensions.add(".xml"); - - assertEquals(extensions.get(0), importer.getExtensions().get(0)); - assertEquals(extensions.get(1), importer.getExtensions().get(1)); + assertEquals(FileExtensions.MEDLINE, importer.getExtensions()); } @Test @@ -85,7 +81,7 @@ public void testGetDescription() { @Test public void testIsRecognizedFormatReject() throws IOException { - List list = getTestFiles().stream().filter(n -> !n.getFileName().toString().startsWith("MedlineImporter")) + List list = getTestFiles().stream().filter(n -> !n.getFileName().toString().startsWith("MedlineImporter")) .collect(Collectors.toList()); for (Path file : list) { diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java index 8999cd54672..d6f69d2a0b2 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/MedlinePlainImporterTest.java @@ -8,7 +8,6 @@ import java.nio.charset.Charset; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -16,6 +15,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.logic.bibtex.BibEntryAssert; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; @@ -31,6 +31,7 @@ public class MedlinePlainImporterTest { private MedlinePlainImporter importer; + private BufferedReader readerForString(String string) { return new BufferedReader(new StringReader(string)); } @@ -43,12 +44,7 @@ public void setUp() { @Test public void testsGetExtensions() { - List extensions = new ArrayList<>(); - extensions.add(".nbib"); - extensions.add(".txt"); - - assertEquals(extensions.get(0), importer.getExtensions().get(0)); - assertEquals(extensions.get(1), importer.getExtensions().get(1)); + assertEquals(FileExtensions.MEDLINE_PLAIN, importer.getExtensions()); } @Test @@ -85,8 +81,8 @@ public void doesNotRecognizeEmptyFiles() throws IOException { @Test public void testImportMultipleEntriesInSingleFile() throws IOException, URISyntaxException { - Path inputFile = Paths.get( - MedlinePlainImporter.class.getResource("MedlinePlainImporterTestMultipleEntries.txt").toURI()); + Path inputFile = Paths + .get(MedlinePlainImporter.class.getResource("MedlinePlainImporterTestMultipleEntries.txt").toURI()); List entries = importer.importDatabase(inputFile, Charset.defaultCharset()).getDatabase() .getEntries(); @@ -164,21 +160,21 @@ private void assertImportOfMedlineFileEqualsBibtexFile(String medlineFile, Strin @Test public void testMultiLineComments() throws IOException { - BufferedReader reader = readerForString( - "PMID-22664220" + "\n" + "CON - Comment1" + "\n" + "CIN - Comment2" + "\n" + "EIN - Comment3" + "\n" - + "EFR - Comment4" + "\n" + "CRI - Comment5" + "\n" + "CRF - Comment6" + "\n" + "PRIN- Comment7" - + "\n" + "PROF- Comment8" + "\n" + "RPI - Comment9" + "\n" + "RPF - Comment10" + "\n" - + "RIN - Comment11" + "\n" + "ROF - Comment12" + "\n" + "UIN - Comment13" + "\n" - + "UOF - Comment14" + "\n" + "SPIN- Comment15" + "\n" + "ORI - Comment16"); - List actualEntries = importer.importDatabase(reader).getDatabase().getEntries(); + try (BufferedReader reader = readerForString("PMID-22664220" + "\n" + "CON - Comment1" + "\n" + "CIN - Comment2" + + "\n" + "EIN - Comment3" + "\n" + "EFR - Comment4" + "\n" + "CRI - Comment5" + "\n" + "CRF - Comment6" + + "\n" + "PRIN- Comment7" + "\n" + "PROF- Comment8" + "\n" + "RPI - Comment9" + "\n" + "RPF - Comment10" + + "\n" + "RIN - Comment11" + "\n" + "ROF - Comment12" + "\n" + "UIN - Comment13" + "\n" + + "UOF - Comment14" + "\n" + "SPIN- Comment15" + "\n" + "ORI - Comment16")) { + List actualEntries = importer.importDatabase(reader).getDatabase().getEntries(); - BibEntry expectedEntry = new BibEntry(); - expectedEntry.setField("comment", - "Comment1" + "\n" + "Comment2" + "\n" + "Comment3" + "\n" + "Comment4" + "\n" + "Comment5" + "\n" - + "Comment6" + "\n" + "Comment7" + "\n" + "Comment8" + "\n" + "Comment9" + "\n" - + "Comment10" + "\n" + "Comment11" + "\n" + "Comment12" + "\n" + "Comment13" + "\n" - + "Comment14" + "\n" + "Comment15" + "\n" + "Comment16"); - assertEquals(Collections.singletonList(expectedEntry), actualEntries); + BibEntry expectedEntry = new BibEntry(); + expectedEntry.setField("comment", + "Comment1" + "\n" + "Comment2" + "\n" + "Comment3" + "\n" + "Comment4" + "\n" + "Comment5" + "\n" + + "Comment6" + "\n" + "Comment7" + "\n" + "Comment8" + "\n" + "Comment9" + "\n" + + "Comment10" + "\n" + "Comment11" + "\n" + "Comment12" + "\n" + "Comment13" + "\n" + + "Comment14" + "\n" + "Comment15" + "\n" + "Comment16"); + assertEquals(Collections.singletonList(expectedEntry), actualEntries); + } } @Test @@ -225,12 +221,9 @@ public void testNullReader() throws IOException { @Test public void testAllArticleTypes() throws IOException { - try (BufferedReader reader = readerForString("PMID-22664795" + "\n" + - "MH - Female\n" + - "PT - journal article" + "\n" + - "PT - classical article" + "\n" + - "PT - corrected and republished article" + "\n" + - "PT - introductory journal article" + "\n" + "PT - newspaper article")) { + try (BufferedReader reader = readerForString("PMID-22664795" + "\n" + "MH - Female\n" + "PT - journal article" + + "\n" + "PT - classical article" + "\n" + "PT - corrected and republished article" + "\n" + + "PT - introductory journal article" + "\n" + "PT - newspaper article")) { List actualEntries = importer.importDatabase(reader).getDatabase().getEntries(); BibEntry expectedEntry = new BibEntry(); diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/MsBibImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/MsBibImporterTest.java index 393acb09270..cbd9838728a 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/MsBibImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/MsBibImporterTest.java @@ -5,19 +5,21 @@ import java.nio.charset.Charset; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import net.sf.jabref.Globals; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + public class MsBibImporterTest { @Before @@ -28,16 +30,13 @@ public void setUp() throws Exception { @Test public void testsGetExtensions() { MsBibImporter importer = new MsBibImporter(); - List extensions = new ArrayList<>(); - extensions.add(".xml"); - - Assert.assertEquals(extensions.get(0), importer.getExtensions().get(0)); + assertEquals(FileExtensions.MSBIB, importer.getExtensions()); } @Test public void testGetDescription() { MsBibImporter importer = new MsBibImporter(); - Assert.assertEquals("Importer for the MS Office 2007 XML bibliography format.", importer.getDescription()); + assertEquals("Importer for the MS Office 2007 XML bibliography format.", importer.getDescription()); } @Test @@ -47,7 +46,7 @@ public final void testIsNotRecognizedFormat() throws Exception { "IsiImporterTestInspec.isi", "emptyFile.xml", "IsiImporterTestWOS.isi"); for (String s : notAccepted) { Path file = Paths.get(MsBibImporter.class.getResource(s).toURI()); - Assert.assertFalse(testImporter.isRecognizedFormat(file, Charset.defaultCharset())); + assertFalse(testImporter.isRecognizedFormat(file, Charset.defaultCharset())); } } @@ -56,7 +55,7 @@ public final void testImportEntriesEmpty() throws IOException, URISyntaxExceptio MsBibImporter testImporter = new MsBibImporter(); Path file = Paths.get(MsBibImporter.class.getResource("MsBibImporterTest.xml").toURI()); List entries = testImporter.importDatabase(file, Charset.defaultCharset()).getDatabase().getEntries(); - Assert.assertEquals(Collections.emptyList(), entries); + assertEquals(Collections.emptyList(), entries); } @Test @@ -64,19 +63,19 @@ public final void testImportEntriesNotRecognizedFormat() throws IOException, URI MsBibImporter testImporter = new MsBibImporter(); Path file = Paths.get(MsBibImporter.class.getResource("CopacImporterTest1.txt").toURI()); List entries = testImporter.importDatabase(file, Charset.defaultCharset()).getDatabase().getEntries(); - Assert.assertEquals(0, entries.size()); + assertEquals(0, entries.size()); } @Test public final void testGetFormatName() { MsBibImporter testImporter = new MsBibImporter(); - Assert.assertEquals("MSBib", testImporter.getFormatName()); + assertEquals("MSBib", testImporter.getFormatName()); } @Test public final void testGetCommandLineId() { MsBibImporter testImporter = new MsBibImporter(); - Assert.assertEquals("msbib", testImporter.getId()); + assertEquals("msbib", testImporter.getId()); } } diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/OvidImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/OvidImporterTest.java index 42a4eb1c495..83d6e3a19fa 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/OvidImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/OvidImporterTest.java @@ -13,6 +13,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.logic.bibtex.BibEntryAssert; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; @@ -43,7 +44,7 @@ public void testGetCLIId() { @Test public void testsGetExtensions() { - Assert.assertEquals(".txt", importer.getExtensions().get(0)); + Assert.assertEquals(FileExtensions.OVID, importer.getExtensions()); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporterTest.java index 315e2746d94..1d675619d65 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/PdfContentImporterTest.java @@ -4,11 +4,11 @@ import java.nio.charset.Charset; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; import java.util.Collections; import java.util.List; import net.sf.jabref.logic.importer.ImportFormatPreferences; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; @@ -29,7 +29,7 @@ public void setUp() { @Test public void testsGetExtensions() { - assertEquals(Arrays.asList(".pdf"), importer.getExtensions()); + assertEquals(FileExtensions.PDF_CONTENT, importer.getExtensions()); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/PdfXmpImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/PdfXmpImporterTest.java index eee2cbe45a9..aa3bfeefdd4 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/PdfXmpImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/PdfXmpImporterTest.java @@ -11,6 +11,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.logic.importer.ParserResult; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.logic.xmp.XMPPreferences; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; @@ -41,7 +42,7 @@ public void testGetFormatName() { @Test public void testsGetExtensions() { - assertEquals(".pdf", importer.getExtensions().get(0)); + assertEquals(FileExtensions.XMP, importer.getExtensions()); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/RISImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/RISImporterTest.java index c1ef4a455d3..493bef43a62 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/RISImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/RISImporterTest.java @@ -7,6 +7,7 @@ import java.nio.file.Paths; import net.sf.jabref.Globals; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.preferences.JabRefPreferences; import org.junit.Assert; @@ -36,7 +37,7 @@ public void testGetCLIId() { @Test public void testsGetExtensions() { - Assert.assertEquals(".ris", importer.getExtensions().get(0)); + Assert.assertEquals(FileExtensions.RIS, importer.getExtensions()); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/RepecNepImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/RepecNepImporterTest.java index 1c11936875d..8998738b79e 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/RepecNepImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/RepecNepImporterTest.java @@ -7,12 +7,12 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; -import java.util.Collections; import java.util.List; import net.sf.jabref.Globals; import net.sf.jabref.logic.bibtex.BibEntryAssert; import net.sf.jabref.logic.importer.ImportFormatPreferences; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; @@ -94,7 +94,7 @@ public final void testGetCliId() { @Test public void testGetExtension() { - Assert.assertEquals(Collections.singletonList(".txt"), testImporter.getExtensions()); + Assert.assertEquals(FileExtensions.REPEC, testImporter.getExtensions()); } @Test diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/SilverPlatterImporterTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/SilverPlatterImporterTest.java index 3257362bc73..cd12793c2ea 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/SilverPlatterImporterTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/SilverPlatterImporterTest.java @@ -10,6 +10,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.logic.bibtex.BibEntryAssert; +import net.sf.jabref.logic.util.FileExtensions; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.preferences.JabRefPreferences; @@ -21,6 +22,8 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; +import static org.junit.Assert.assertEquals; + @RunWith(Parameterized.class) public class SilverPlatterImporterTest { @@ -43,12 +46,12 @@ public void setUp() throws Exception { @Test public void testsGetExtensions() { - Assert.assertEquals(".txt", testImporter.getExtensions().get(0)); + assertEquals(FileExtensions.SILVER_PLATTER, testImporter.getExtensions()); } @Test public void testGetDescription() { - Assert.assertEquals("Imports a SilverPlatter exported file.", testImporter.getDescription()); + assertEquals("Imports a SilverPlatter exported file.", testImporter.getDescription()); } @Parameters(name = "{index}: {0}") diff --git a/src/test/java/net/sf/jabref/logic/util/FileExtensionsTest.java b/src/test/java/net/sf/jabref/logic/util/FileExtensionsTest.java new file mode 100644 index 00000000000..4f030b8fad5 --- /dev/null +++ b/src/test/java/net/sf/jabref/logic/util/FileExtensionsTest.java @@ -0,0 +1,36 @@ +package net.sf.jabref.logic.util; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class FileExtensionsTest { + + @Test + public void testSingleFileExtensionDescription() { + String singleDescription = "INSPEC file (*.txt)"; + assertEquals(singleDescription, FileExtensions.INSPEC.getDescription()); + } + + @Test + public void testMultiFileExtensionsDescription() { + String multiDescription = "MedlinePlain file (*.nbib, *.txt)"; + assertEquals(multiDescription, FileExtensions.MEDLINE_PLAIN.getDescription()); + } + + @Test + public void testExtensions() { + List extensions = Arrays.asList("nbib", "txt"); + Assert.assertArrayEquals(extensions.toArray(), FileExtensions.MEDLINE_PLAIN.getExtensions()); + } + + @Test + public void testFirstExtensionWithDot() { + assertEquals(".nbib", FileExtensions.MEDLINE_PLAIN.getFirstExtensionWithDot()); + } + +}