Permalink
Browse files

Added testing in the abstract test class for general pattern that get…

…Parameters() should return a non-null List

Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information...
1 parent c1a660a commit 49f45dfa000c3b56980547e012963cfaaed3cfe4 @egonw egonw committed with egonw Feb 8, 2012
@@ -29,6 +29,7 @@
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.annotations.TestClass;
+import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.geometry.GeometryTools;
import org.openscience.cdk.graph.ConnectivityChecker;
import org.openscience.cdk.interfaces.IAtom;
@@ -525,6 +526,7 @@ public IRenderingElement generateBond(IBond bond, RendererModel model) {
}
/** {@inheritDoc} */
+ @TestMethod("testGetParameters")
public List<IGeneratorParameter<?>> getParameters() {
return Arrays.asList(
new IGeneratorParameter<?>[] {
@@ -25,6 +25,7 @@
import java.util.List;
import org.openscience.cdk.annotations.TestClass;
+import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.renderer.RendererModel;
import org.openscience.cdk.renderer.elements.ElementGroup;
@@ -70,6 +71,7 @@ public IRenderingElement generate(IAtomContainer ac, RendererModel model) {
}
/** {@inheritDoc} */
+ @TestMethod("testGetParameters")
public List<IGeneratorParameter<?>> getParameters() {
ArrayList<IGeneratorParameter<?>> list = new ArrayList<IGeneratorParameter<?>>();
list.addAll(this.atomGenerator.getParameters());
@@ -24,6 +24,7 @@
import java.util.List;
import org.openscience.cdk.annotations.TestClass;
+import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.renderer.RendererModel;
import org.openscience.cdk.renderer.elements.ElementGroup;
@@ -219,6 +220,7 @@ public IRenderingElement generate(IAtomContainer ac, RendererModel model) {
}
/** {@inheritDoc} */
+ @TestMethod("testGetParameters")
public List<IGeneratorParameter<?>> getParameters() {
return Arrays.asList(
new IGeneratorParameter<?>[] {
@@ -29,6 +29,8 @@
import javax.vecmath.Point2d;
+import org.openscience.cdk.annotations.TestClass;
+import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.geometry.GeometryTools;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IBond;
@@ -46,6 +48,7 @@
* @cdk.module renderbasic
* @cdk.githash
*/
+@TestClass("org.openscience.cdk.renderer.generators.RingGeneratorTest")
public class RingGenerator extends BasicBondGenerator {
/**
@@ -158,6 +161,7 @@ private boolean ringIsAromatic(IRing ring) {
}
/** {@inheritDoc} */
+ @TestMethod("testGetParameters")
public List<IGeneratorParameter<?>> getParameters() {
// Get our super class's version of things
List<IGeneratorParameter<?>> superPars = super.getParameters();
@@ -42,6 +42,7 @@
import org.openscience.cdk.renderer.generators.BasicBondGeneratorTest;
import org.openscience.cdk.renderer.generators.BasicGeneratorTest;
import org.openscience.cdk.renderer.generators.BasicSceneGeneratorTest;
+import org.openscience.cdk.renderer.generators.RingGeneratorTest;
/**
* TestSuite that runs all the tests for the CDK <code>renderbasic</code>
@@ -57,6 +58,7 @@
BasicBondGeneratorTest.class,
BasicSceneGeneratorTest.class,
BasicGeneratorTest.class,
+ RingGeneratorTest.class,
WedgeLineElementTest.class,
LineElementTest.class,
PathElementTest.class,
@@ -27,6 +27,8 @@
import javax.vecmath.Point2d;
+import org.junit.Assert;
+import org.junit.Test;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
@@ -55,11 +57,21 @@
protected BasicSceneGenerator sceneGenerator;
+ private IGenerator testedGenerator;
+
+ /**
+ * Sets the {@link IGenerator} that is being tested.
+ */
+ public void setTestedGenerator(IGenerator generator) {
+ testedGenerator = generator;
+ }
+
/**
* Sets up the model and transform.
* Call from the 'Before' method in subclasses.
*/
public void setup() {
+ if (model != null) return; // things are already set up
model = new RendererModel();
elementUtil = new ElementUtility();
elementUtil.setTransform(this.getTransform());
@@ -278,6 +290,15 @@ public IAtomContainer makeSNOPSquare() {
container.addBond(1, 2, IBond.Order.SINGLE);
container.addBond(2, 3, IBond.Order.SINGLE);
return container;
-
+ }
+
+ @Test
+ public void testGetParameters() {
+ Assert.assertNotNull("The tested generator is not set.", this.testedGenerator);
+
+ Assert.assertNotNull(
+ "The getParameters() must not return a null value.",
+ this.testedGenerator.getParameters()
+ );
}
}
@@ -68,6 +68,7 @@ public void setup() {
super.setup();
this.generator = new BasicAtomGenerator();
model.registerParameters(generator);
+ super.setTestedGenerator(generator);
}
@Test
@@ -32,6 +32,7 @@ public void setup() {
super.setup();
this.generator = new BasicBondGenerator();
model.registerParameters(generator);
+ super.setTestedGenerator(generator);
}
@Test
@@ -54,6 +54,7 @@ public void setup() {
super.setup();
this.generator = new BasicGenerator();
model.registerParameters(generator);
+ super.setTestedGenerator(generator);
}
@Test
@@ -53,6 +53,7 @@ public void setup() {
super.setup();
this.generator = new BasicSceneGenerator();
model.registerParameters(generator);
+ super.setTestedGenerator(generator);
}
@Test
@@ -0,0 +1,66 @@
+/* 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. All we ask is that proper credit is given for our work,
+ * which includes - but is not limited to - adding the above copyright notice to
+ * the beginning of your source code files, and to any copyright notice that you
+ * may distribute with programs based on this work.
+ *
+ * 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.renderer.generators;
+
+import java.awt.Rectangle;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openscience.cdk.interfaces.IAtomContainer;
+import org.openscience.cdk.renderer.elements.IRenderingElement;
+
+/**
+ * @cdk.module test-renderbasic
+ */
+public class RingGeneratorTest extends AbstractGeneratorTest {
+
+ private RingGenerator generator;
+
+ @Override
+ public Rectangle getCustomCanvas() {
+ return null;
+ }
+
+ @Before
+ public void setup() {
+ super.setup();
+ model.registerParameters(new BasicSceneGenerator());
+ model.registerParameters(new BasicAtomGenerator());
+ this.generator = new RingGenerator();
+ model.registerParameters(generator);
+ super.setTestedGenerator(generator);
+ }
+
+ @Test
+ public void testEmptyContainer() {
+ IAtomContainer emptyContainer = super.builder.newInstance(IAtomContainer.class);
+
+ // nothing should be made
+ IRenderingElement root = generator.generate(emptyContainer, model);
+ List<IRenderingElement> elements = elementUtil.getAllSimpleElements(root);
+ Assert.assertEquals(0, elements.size());
+ }
+
+}

0 comments on commit 49f45df

Please sign in to comment.