Skip to content

Commit

Permalink
Removed Globals.prefs init in some logic tests (JabRef#1819)
Browse files Browse the repository at this point in the history
* Removed Globals.prefs init in some logic tests

* Some more tests
  • Loading branch information
oscargus authored and ayanai1 committed Sep 5, 2016
1 parent 650bf3b commit 0df28d4
Show file tree
Hide file tree
Showing 40 changed files with 41 additions and 156 deletions.
9 changes: 4 additions & 5 deletions src/test/java/net/sf/jabref/BibtexTestData.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

public class BibtexTestData {

public static BibEntry getBibtexEntry() throws IOException {
BibDatabase database = getBibtexDatabase();
public static BibEntry getBibtexEntry(ImportFormatPreferences importFormatPreferences) throws IOException {
BibDatabase database = getBibtexDatabase(importFormatPreferences);
return database.getEntryByKey("HipKro03").get();
}

public static BibDatabase getBibtexDatabase() throws IOException {
public static BibDatabase getBibtexDatabase(ImportFormatPreferences importFormatPreferences) throws IOException {
StringReader reader = new StringReader(
"@ARTICLE{HipKro03,\n" + " author = {Eric von Hippel and Georg von Krogh},\n"
+ " title = {Open Source Software and the \"Private-Collective\" Innovation Model: Issues for Organization Science},\n"
Expand All @@ -26,8 +26,7 @@ public static BibDatabase getBibtexDatabase() throws IOException {
+ " doi = {http://dx.doi.org/10.1287/orsc.14.2.209.14992}," + "\n" + " issn = {1526-5455},"
+ "\n" + " publisher = {INFORMS}\n" + "}");

BibtexParser parser = new BibtexParser(reader,
ImportFormatPreferences.fromPreferences(Globals.prefs));
BibtexParser parser = new BibtexParser(reader, importFormatPreferences);
ParserResult result = parser.parse();

return result.getDatabase();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/net/sf/jabref/logic/bibtex/BibEntryAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import java.util.Collections;
import java.util.List;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.importer.ImportFormatPreferences;
import net.sf.jabref.logic.importer.ParserResult;
import net.sf.jabref.logic.importer.fileformat.BibtexParser;
import net.sf.jabref.logic.importer.fileformat.ImportFormat;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.preferences.JabRefPreferences;

import org.junit.Assert;

Expand Down Expand Up @@ -64,7 +64,7 @@ private static List<BibEntry> getListFromInputStream(InputStream is) throws IOEx
ParserResult result;
try (Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
BibtexParser parser = new BibtexParser(reader,
ImportFormatPreferences.fromPreferences(Globals.prefs));
ImportFormatPreferences.fromPreferences(JabRefPreferences.getInstance()));
result = parser.parse();
}
Assert.assertNotNull(result);
Expand Down
9 changes: 1 addition & 8 deletions src/test/java/net/sf/jabref/logic/bst/TestVM.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.List;
import java.util.Optional;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.bst.VM.BstEntry;
import net.sf.jabref.logic.bst.VM.StackFunction;
import net.sf.jabref.logic.importer.ImportFormatPreferences;
Expand All @@ -19,16 +18,10 @@

import org.antlr.runtime.RecognitionException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class TestVM {

@Before
public void setPreferences() {
Globals.prefs = JabRefPreferences.getInstance();
}


@Test
public void testAbbrv() throws RecognitionException, IOException {
Expand Down Expand Up @@ -649,7 +642,7 @@ public void testVMSwap() throws RecognitionException {

private static BibEntry bibtexString2BibtexEntry(String s) throws IOException {
ParserResult result = BibtexParser.parse(new StringReader(s),
ImportFormatPreferences.fromPreferences(Globals.prefs));
ImportFormatPreferences.fromPreferences(JabRefPreferences.getInstance()));
Collection<BibEntry> c = result.getDatabase().getEntries();
Assert.assertEquals(1, c.size());
return c.iterator().next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.importer.fileformat.BibtexParser;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.preferences.JabRefPreferences;
Expand All @@ -21,9 +20,7 @@ public class BibDatabaseTestsWithFiles {

@Before
public void setUp() {
Globals.prefs = JabRefPreferences.getInstance(); // set preferences for this test

importFormatPreferences = ImportFormatPreferences.fromPreferences(Globals.prefs);
importFormatPreferences = ImportFormatPreferences.fromPreferences(JabRefPreferences.getInstance());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.nio.charset.StandardCharsets;
import java.util.Collection;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.importer.fileformat.BibtexParser;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.entry.BibEntry;
Expand All @@ -32,11 +31,10 @@ public class DatabaseFileLookupTest {

@Before
public void setUp() throws FileNotFoundException, IOException {
Globals.prefs = JabRefPreferences.getInstance();

try (FileInputStream stream = new FileInputStream(ImportDataTest.UNLINKED_FILES_TEST_BIB);
InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
ParserResult result = BibtexParser.parse(reader, ImportFormatPreferences.fromPreferences(Globals.prefs));
ParserResult result = BibtexParser.parse(reader,
ImportFormatPreferences.fromPreferences(JabRefPreferences.getInstance()));
database = result.getDatabase();
entries = database.getEntries();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ImportFormatReaderIntegrationTest(String resource, String format, int cou

@Before
public void setUp() {
Globals.prefs = JabRefPreferences.getInstance();
Globals.prefs = JabRefPreferences.getInstance(); // Needed for special fields
reader = new ImportFormatReader();
reader.resetImportFormats(ImportFormatPreferences.fromPreferences(Globals.prefs),
XMPPreferences.fromPreferences(JabRefPreferences.getInstance()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ImportFormatReaderTestParameterless {

@Before
public void setUp() {
Globals.prefs = JabRefPreferences.getInstance();
Globals.prefs = JabRefPreferences.getInstance(); // Needed for special fields
reader = new ImportFormatReader();
reader.resetImportFormats(ImportFormatPreferences.fromPreferences(Globals.prefs),
XMPPreferences.fromPreferences(Globals.prefs));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public OpenDatabaseTest() throws URISyntaxException {

@BeforeClass
public static void setUpGlobalsPrefs() {
// otherwise FieldContentParser (called by BibtexParser) crashes
// otherwise FieldContentParser (called by BibtexParser) and SpecialFields crashes
Globals.prefs = JabRefPreferences.getInstance();
}

@Before
public void setUp() {
importFormatPreferences = ImportFormatPreferences.fromPreferences(Globals.prefs);
importFormatPreferences = ImportFormatPreferences.fromPreferences(JabRefPreferences.getInstance());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Optional;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.importer.fileformat.BibtexParser;
import net.sf.jabref.preferences.JabRefPreferences;

Expand All @@ -18,10 +17,7 @@ public class ParsedBibEntryTests {

@Before
public void setUp() {
Globals.prefs = JabRefPreferences.getInstance();


importFormatPreferences = ImportFormatPreferences.fromPreferences(Globals.prefs);
importFormatPreferences = ImportFormatPreferences.fromPreferences(JabRefPreferences.getInstance());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,15 @@

import javax.xml.parsers.ParserConfigurationException;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.bibtex.BibEntryAssert;
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 org.xml.sax.SAXException;

public class GVKParserTest {

@Before
public void setUp() {
Globals.prefs = JabRefPreferences.getInstance();
}

private void doTest(String xmlName, int expectedSize, List<String> resourceNames)
throws ParserConfigurationException, SAXException, IOException {
try (InputStream is = GVKParser.class.getResourceAsStream(xmlName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import java.util.List;
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.Before;
import org.junit.Test;
Expand Down Expand Up @@ -46,7 +44,6 @@ public List<Path> getTestFiles() throws IOException {

@Before
public void setUp() throws Exception {
Globals.prefs = JabRefPreferences.getInstance();
importer = new BibTeXMLImporter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.bibtex.BibEntryAssert;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.preferences.JabRefPreferences;

import org.junit.Assert;
import org.junit.Before;
Expand All @@ -40,7 +38,6 @@ public class BibTeXMLImporterTestFiles {

@Before
public void setUp() {
Globals.prefs = JabRefPreferences.getInstance();
bibtexmlImporter = new BibTeXMLImporter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import java.util.Collections;
import java.util.List;

import net.sf.jabref.Globals;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.preferences.JabRefPreferences;

import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -41,7 +39,6 @@ public static Collection<String[]> types() {

@Before
public void setUp() throws Exception {
Globals.prefs = JabRefPreferences.getInstance();
bibteXMLImporter = new BibTeXMLImporter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import java.nio.file.Paths;
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;
import org.junit.Before;
Expand All @@ -20,7 +18,6 @@ public class BiblioscapeImporterTest {

@Before
public void setUp() throws Exception {
Globals.prefs = JabRefPreferences.getInstance();
importer = new BiblioscapeImporter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import java.util.Collection;
import java.util.List;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.bibtex.BibEntryAssert;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.preferences.JabRefPreferences;

import org.junit.Assert;
import org.junit.Before;
Expand All @@ -36,7 +34,6 @@ public BiblioscapeImporterTestFiles(String fileName) throws URISyntaxException {

@Before
public void setUp() throws Exception {
Globals.prefs = JabRefPreferences.getInstance();
bsImporter = new BiblioscapeImporter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import java.util.Collections;
import java.util.List;

import net.sf.jabref.Globals;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.preferences.JabRefPreferences;

import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -41,7 +39,6 @@ public static Collection<String[]> types() {

@Before
public void setUp() throws Exception {
Globals.prefs = JabRefPreferences.getInstance();
bsImporter = new BiblioscapeImporter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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;
Expand All @@ -34,8 +33,7 @@ public class BibtexImporterTest {

@Before
public void setUp() {
Globals.prefs = JabRefPreferences.getInstance();
importer = new BibtexImporter(ImportFormatPreferences.fromPreferences(Globals.prefs));
importer = new BibtexImporter(ImportFormatPreferences.fromPreferences(JabRefPreferences.getInstance()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
import java.util.List;
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;

import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -43,7 +41,6 @@ public List<String> getTestFiles() throws IOException {

@Before
public void setUp() throws Exception {
Globals.prefs = JabRefPreferences.getInstance();
importer = new CopacImporter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import java.util.List;
import java.util.stream.Collectors;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.bibtex.BibEntryAssert;
import net.sf.jabref.preferences.JabRefPreferences;

import org.junit.Assert;
import org.junit.Before;
Expand All @@ -37,7 +35,6 @@ public class CopacImporterTestFiles {

@Before
public void setUp() {
Globals.prefs = JabRefPreferences.getInstance();
copacImporter = new CopacImporter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import java.util.Arrays;
import java.util.List;

import net.sf.jabref.Globals;
import net.sf.jabref.preferences.JabRefPreferences;

import org.junit.Before;
import org.junit.Test;

Expand All @@ -20,7 +17,6 @@ public class CustomImporterTest {

@Before
public void setUp() {
Globals.prefs = JabRefPreferences.getInstance();
importer = new CustomImporter(new CopacImporter());
}

Expand Down
Loading

0 comments on commit 0df28d4

Please sign in to comment.