-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test CustomImporter #1501
Test CustomImporter #1501
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package net.sf.jabref.importer; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.JabRefPreferences; | ||
import net.sf.jabref.importer.fileformat.BibTeXMLImporter; | ||
import net.sf.jabref.importer.fileformat.CopacImporter; | ||
import net.sf.jabref.importer.fileformat.OvidImporter; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class CustomImporterTest { | ||
|
||
private CustomImporter importer; | ||
|
||
@Before | ||
public void setUp() { | ||
Globals.prefs = JabRefPreferences.getInstance(); | ||
importer = new CustomImporter(new CopacImporter()); | ||
} | ||
|
||
@Test | ||
public void testGetName() { | ||
assertEquals("Copac", importer.getName()); | ||
} | ||
|
||
@Test | ||
public void testGetCliId() { | ||
assertEquals("cpc", importer.getClidId()); | ||
} | ||
|
||
@Test | ||
public void testGetClassName() { | ||
assertEquals("net.sf.jabref.importer.fileformat.CopacImporter", importer.getClassName()); | ||
} | ||
|
||
@Test | ||
public void testGetBasePath() { | ||
assertEquals("src/main/java/net/sf/jabref/importer/fileformat/CopacImporter.java", importer.getBasePath()); | ||
} | ||
|
||
@Test | ||
public void testGetInstance() throws Exception { | ||
assertEquals(new CopacImporter(), importer.getInstance()); | ||
} | ||
|
||
@Test | ||
public void testGetFileFromBasePath() { | ||
assertEquals(new File("src/main/java/net/sf/jabref/importer/fileformat/CopacImporter.java"), importer.getFileFromBasePath()); | ||
} | ||
|
||
@Test | ||
public void testGetBasePathUrl() throws Exception { | ||
assertEquals(new File("src/main/java/net/sf/jabref/importer/fileformat/CopacImporter.java").toURI().toURL(), importer.getBasePathUrl()); | ||
} | ||
|
||
@Test | ||
public void testGetAsStringList() { | ||
assertEquals("Copac", importer.getAsStringList().get(0)); | ||
assertEquals("cpc", importer.getAsStringList().get(1)); | ||
assertEquals("net.sf.jabref.importer.fileformat.CopacImporter", importer.getAsStringList().get(2)); | ||
assertEquals("src/main/java/net/sf/jabref/importer/fileformat/CopacImporter.java", importer.getAsStringList().get(3)); | ||
} | ||
|
||
@Test | ||
public void testEqualsTrue() { | ||
assertEquals(importer, importer); | ||
} | ||
|
||
@Test | ||
public void testEqualsFalse() { | ||
assertNotEquals(new CopacImporter(), importer); | ||
} | ||
|
||
@Test | ||
public void testCompareToSmaller() { | ||
CustomImporter ovidImporter = new CustomImporter(new OvidImporter()); | ||
|
||
assertTrue(importer.compareTo(ovidImporter) < 0); | ||
} | ||
|
||
@Test | ||
public void testCompareToGreater() { | ||
CustomImporter bibtexmlImporter = new CustomImporter(new BibTeXMLImporter()); | ||
CustomImporter ovidImporter = new CustomImporter(new OvidImporter()); | ||
|
||
assertTrue(ovidImporter.compareTo(bibtexmlImporter) > 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I'm not sure if you need this test case. In general it is the same as compareToSmaller. Is there any reason to keep it? |
||
} | ||
|
||
@Test | ||
public void testCompareToEven() { | ||
assertEquals(0, importer.compareTo(importer)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again: only one assertion per test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either remove this, or add a @SuppressWarnings("SelfComparison"), becaue ErrorProne will mark this as error in a newer version. |
||
} | ||
|
||
@Test | ||
public void testToString() { | ||
assertEquals("Copac", importer.toString()); | ||
} | ||
|
||
@Test | ||
public void testClassicConstructor() { | ||
CustomImporter customImporter = new CustomImporter("Copac", "cpc", "net.sf.jabref.importer.fileformat.CopacImporter", "src/main/java/net/sf/jabref/importer/fileformat/CopacImporter.java"); | ||
|
||
assertEquals(importer, customImporter); | ||
} | ||
|
||
@Test | ||
public void testListConstructor() { | ||
List<String> dataTest = Arrays.asList("Ovid", "ovid", "net.sf.jabref.importer.fileformat.OvidImporter", "src/main/java/net/sf/jabref/importer/fileformat/OvidImporter.java"); | ||
CustomImporter customImporter = new CustomImporter(dataTest); | ||
CustomImporter customOvidImporter = new CustomImporter(new OvidImporter()); | ||
|
||
assertEquals(customImporter, customOvidImporter); | ||
} | ||
|
||
@Test | ||
public void testEmptyConstructor() { | ||
CustomImporter customImporter = new CustomImporter(); | ||
customImporter.setName("Ovid"); | ||
customImporter.setCliId("ovid"); | ||
customImporter.setClassName("net.sf.jabref.importer.fileformat.OvidImporter"); | ||
customImporter.setBasePath("src/main/java/net/sf/jabref/importer/fileformat/OvidImporter.java"); | ||
|
||
CustomImporter customOvidImporter = new CustomImporter(new OvidImporter()); | ||
|
||
assertEquals(customImporter, customOvidImporter); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please call one of the other constructors instead of setting each variable here .