Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test CustomImporter #1501

Merged
merged 3 commits into from
Jul 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/main/java/net/sf/jabref/importer/CustomImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ public CustomImporter(List<String> data) {
}

public CustomImporter(String name, String cliId, String className, String basePath) {
super();
this();
this.name = name;
this.cliId = cliId;
this.className = className;
this.basePath = basePath;
}

public CustomImporter(ImportFormat importer) {
this(importer.getFormatName(), importer.getId(), importer.getClass().getName(), "src/main/java/net/sf/jabref/importer/fileformat/" + importer.getFormatName() + "Importer.java");
}
Copy link
Contributor

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 .


public String getName() {
return this.name;
}
Expand Down Expand Up @@ -113,7 +117,12 @@ public List<String> getAsStringList() {

@Override
public boolean equals(Object o) {
return (o instanceof CustomImporter) && this.getName().equals(((CustomImporter) o).getName());
boolean equalName = this.getName().equals(((CustomImporter) o).getName());
boolean equalCliId = this.getClidId().equals(((CustomImporter) o).getClidId());
boolean equalClassName = this.getClassName().equals(((CustomImporter) o).getClassName());
boolean equalBasePath = this.getBasePath().equals(((CustomImporter) o).getBasePath());

return (o instanceof CustomImporter) && equalName && equalCliId && equalClassName && equalBasePath;
}

@Override
Expand Down
136 changes: 136 additions & 0 deletions src/test/java/net/sf/jabref/importer/CustomImporterTest.java
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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again: only one assertion per test

Copy link
Member

Choose a reason for hiding this comment

The 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.
http://errorprone.info/bugpattern/SelfComparison

}

@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);
}
}