Permalink
Browse files

Now properly tests the right class (fixes #3553754)

Change-Id: Id1a43219832241e57cab46c40941564f8b978187
  • Loading branch information...
1 parent 2ce292f commit 5753c24f0ec78df65ae4ae35cc3676ca4465340b @egonw egonw committed with johnmay Aug 6, 2012
@@ -0,0 +1,67 @@
+/* Copyright (C) 2012-2013 Egon Willighagen <egonw@users.sf.net>
+ *
+ * Contact: cdk-devel@lists.sourceforge.net
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+package org.openscience.cdk.dict;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @cdk.module test-dict
+ */
+public abstract class AbstractDictionaryTest {
+
+ private Dictionary testClass;
+
+ protected void setTestClass(Dictionary testClass) {
+ this.testClass = testClass;
+ }
+
+ protected Dictionary getTestClass() {
+ return this.testClass;
+ }
+
+ @Test
+ public void testSetTestClass() {
+ Assert.assertNotNull(this.testClass);
+ }
+
+ @Test
+ public void testNS() {
+ Dictionary dict = getTestClass();
+ Assert.assertNotNull(dict);
+ Assert.assertNull(dict.getNS());
+ dict.setNS("http://www.namespace.example.org/");
+ Assert.assertEquals("http://www.namespace.example.org/", dict.getNS());
+ }
+
+ @Test
+ public void testAddEntry() {
+ Dictionary dict = getTestClass();
+ Assert.assertNotNull(dict);
+ Assert.assertEquals(0, dict.size());
+ Assert.assertFalse(dict.hasEntry("someidentifier"));
+ Entry entry = new Entry();
+ entry.setID("someidentifier");
+ dict.addEntry(entry);
+ Assert.assertEquals(1, dict.size());
+ Assert.assertTrue(dict.hasEntry("someidentifier"));
+ Assert.assertEquals(entry, dict.getEntry("someidentifier"));
+ }
+
+}
@@ -0,0 +1,116 @@
+/* Copyright (C) 2012 Egon Willighagen <egonw@users.sf.net>
+ *
+ * Contact: cdk-devel@lists.sourceforge.net
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+package org.openscience.cdk.dict;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openscience.cdk.CDKTestCase;
+
+/**
+ * @cdk.module test-dict
+ */
+public abstract class AbstractEntryTest extends CDKTestCase {
+
+ private Entry testClass;
+
+ protected void setTestClass(Entry testClass) {
+ this.testClass = testClass;
+ }
+
+ protected Entry getTestClass() {
+ return this.testClass;
+ }
+
+ @Test
+ public void testSetTestClass() {
+ Assert.assertNotNull(this.testClass);
+ }
+
+ @Test
+ public void testToString() {
+ Entry entry = getTestClass();
+ entry.setID("testid");
+ entry.setLabel("testTerm");
+ Assert.assertNotNull(entry);
+ Assert.assertEquals("Entry[testid](testTerm)", entry.toString());
+ }
+
+ @Test
+ public void testLabel() {
+ Entry entry = getTestClass();
+ Assert.assertEquals("", entry.getLabel());
+ entry.setLabel("label");
+ Assert.assertEquals("label", entry.getLabel());
+ }
+
+ @Test
+ public void testID() {
+ Entry entry = getTestClass();
+ Assert.assertEquals("", entry.getID());
+ entry.setID("identifier");
+ Assert.assertEquals("identifier", entry.getID());
+ }
+
+ @Test
+ public void testDefinition() {
+ Entry entry = getTestClass();
+ Assert.assertNull(entry.getDefinition());
+ entry.setDefinition("This is a definition.");
+ Assert.assertEquals("This is a definition.", entry.getDefinition());
+ }
+
+ @Test
+ public void testDescriptorMetadata() {
+ Entry entry = getTestClass();
+ Assert.assertNotNull(entry.getDescriptorMetadata());
+ List<String> metadata = entry.getDescriptorMetadata();
+ Assert.assertEquals(0, metadata.size());
+ entry.setDescriptorMetadata("This entry was written by me.");
+ metadata = entry.getDescriptorMetadata();
+ Assert.assertEquals(1, metadata.size());
+ }
+
+ @Test
+ public void testDescription() {
+ Entry entry = getTestClass();
+ Assert.assertNull(entry.getDescription());
+ entry.setDescription("This is a description.");
+ Assert.assertEquals("This is a description.", entry.getDescription());
+ }
+
+ @Test
+ public void testClassName() {
+ Entry entry = getTestClass();
+ Assert.assertNull(entry.getClassName());
+ entry.setClassName("org.openscience.cdk.DoesNotExist");
+ Assert.assertEquals("org.openscience.cdk.DoesNotExist", entry.getClassName());
+ }
+
+ @Test
+ public void testRawContent() {
+ Entry entry = getTestClass();
+ Assert.assertNull(entry.getRawContent());
+ Object someObject = new Double(5);
+ entry.setRawContent(someObject);
+ Assert.assertEquals(someObject, entry.getRawContent());
+ }
+
+}
@@ -18,35 +18,23 @@
*/
package org.openscience.cdk.dict;
+import org.junit.After;
import org.junit.Assert;
-import org.junit.Test;
+import org.junit.Before;
/**
* @cdk.module test-dict
*/
-public class DictionaryTest extends EntryTest {
-
- @Test
- public void testNS() {
- Dictionary dict = new Dictionary();
- Assert.assertNotNull(dict);
- Assert.assertNull(dict.getNS());
- dict.setNS("http://www.namespace.example.org/");
- Assert.assertEquals("http://www.namespace.example.org/", dict.getNS());
+public class DictionaryTest extends AbstractDictionaryTest {
+
+ @Before
+ public void setTestClass() {
+ super.setTestClass(new Dictionary());
}
- @Test
- public void testAddEntry() {
- Dictionary dict = new Dictionary();
- Assert.assertNotNull(dict);
- Assert.assertEquals(0, dict.size());
- Assert.assertFalse(dict.hasEntry("someidentifier"));
- Entry entry = new Entry();
- entry.setID("someidentifier");
- dict.addEntry(entry);
- Assert.assertEquals(1, dict.size());
- Assert.assertTrue(dict.hasEntry("someidentifier"));
- Assert.assertEquals(entry, dict.getEntry("someidentifier"));
+ @After
+ public void testTestClass() {
+ Assert.assertTrue(getTestClass().getClass().getName().endsWith(".Dictionary"));
}
}
@@ -18,9 +18,33 @@
*/
package org.openscience.cdk.dict;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
/**
* @cdk.module test-dict
*/
-public class EntryReactTest extends EntryTest {
+public class EntryReactTest extends AbstractEntryTest {
+
+ @Before
+ public void setTestClass() {
+ super.setTestClass(new EntryReact("someID"));
+ }
+
+ @After
+ public void testTestedClass() {
+ Assert.assertTrue(super.getTestClass() instanceof EntryReact);
+ }
+
+ @Test
+ @Override // customize because there is no constructor without any parameters
+ public void testID() {
+ Entry entry = getTestClass();
+ Assert.assertEquals("someid", entry.getID());
+ entry.setID("identifier");
+ Assert.assertEquals("identifier", entry.getID());
+ }
}
@@ -18,16 +18,25 @@
*/
package org.openscience.cdk.dict;
-import java.util.List;
-
+import org.junit.After;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.openscience.cdk.CDKTestCase;
/**
* @cdk.module test-dict
*/
-public class EntryTest extends CDKTestCase {
+public class EntryTest extends AbstractEntryTest {
+
+ @Before
+ public void setTestClass() {
+ super.setTestClass(new Entry());
+ }
+
+ @After
+ public void testTestedClass() {
+ Assert.assertTrue(super.getTestClass().getClass().getName().endsWith(".Entry"));
+ }
@Test
public void testConstructor() {
@@ -44,13 +53,6 @@ public void testConstructor_String_String() {
}
@Test
- public void testToString() {
- Entry entry = new Entry("testid", "testTerm");
- Assert.assertNotNull(entry);
- Assert.assertEquals("Entry[testid](testTerm)", entry.toString());
- }
-
- @Test
public void testConstructor_String() {
Entry entry = new Entry("testid");
Assert.assertNotNull(entry);
@@ -66,64 +68,4 @@ public void testConstructor_IDLowerCasing() {
Assert.assertEquals(entry.getLabel(), "testTerm");
}
- @Test
- public void testLabel() {
- Entry entry = new Entry();
- Assert.assertEquals("", entry.getLabel());
- entry.setLabel("label");
- Assert.assertEquals("label", entry.getLabel());
- }
-
- @Test
- public void testID() {
- Entry entry = new Entry();
- Assert.assertEquals("", entry.getID());
- entry.setID("identifier");
- Assert.assertEquals("identifier", entry.getID());
- }
-
- @Test
- public void testDefinition() {
- Entry entry = new Entry();
- Assert.assertNull(entry.getDefinition());
- entry.setDefinition("This is a definition.");
- Assert.assertEquals("This is a definition.", entry.getDefinition());
- }
-
- @Test
- public void testDescriptorMetadata() {
- Entry entry = new Entry();
- Assert.assertNotNull(entry.getDescriptorMetadata());
- List<String> metadata = entry.getDescriptorMetadata();
- Assert.assertEquals(0, metadata.size());
- entry.setDescriptorMetadata("This entry was written by me.");
- metadata = entry.getDescriptorMetadata();
- Assert.assertEquals(1, metadata.size());
- }
-
- @Test
- public void testDescription() {
- Entry entry = new Entry();
- Assert.assertNull(entry.getDescription());
- entry.setDescription("This is a description.");
- Assert.assertEquals("This is a description.", entry.getDescription());
- }
-
- @Test
- public void testClassName() {
- Entry entry = new Entry();
- Assert.assertNull(entry.getClassName());
- entry.setClassName("org.openscience.cdk.DoesNotExist");
- Assert.assertEquals("org.openscience.cdk.DoesNotExist", entry.getClassName());
- }
-
- @Test
- public void testRawContent() {
- Entry entry = new Entry();
- Assert.assertNull(entry.getRawContent());
- Object someObject = new Double(5);
- entry.setRawContent(someObject);
- Assert.assertEquals(someObject, entry.getRawContent());
- }
-
}
Oops, something went wrong.

0 comments on commit 5753c24

Please sign in to comment.