Skip to content

Commit

Permalink
Added testing in the abstract test class for general pattern that get…
Browse files Browse the repository at this point in the history
…Parameters() should return a non-null List

Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information
egonw authored and rajarshi committed May 18, 2012
1 parent 84b2e87 commit b245c6f
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 1 deletion.
Expand Up @@ -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;
Expand Down Expand Up @@ -525,6 +526,7 @@ public IRenderingElement generateBond(IBond bond, RendererModel model) {
}

/** {@inheritDoc} */
@TestMethod("testGetParameters")
public List<IGeneratorParameter<?>> getParameters() {
return Arrays.asList(
new IGeneratorParameter<?>[] {
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -219,6 +220,7 @@ public IRenderingElement generate(IAtomContainer ac, RendererModel model) {
}

/** {@inheritDoc} */
@TestMethod("testGetParameters")
public List<IGeneratorParameter<?>> getParameters() {
return Arrays.asList(
new IGeneratorParameter<?>[] {
Expand Down
Expand Up @@ -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;
Expand All @@ -46,6 +48,7 @@
* @cdk.module renderbasic
* @cdk.githash
*/
@TestClass("org.openscience.cdk.renderer.generators.RingGeneratorTest")
public class RingGenerator extends BasicBondGenerator {

/**
Expand Down Expand Up @@ -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();
Expand Down
Expand Up @@ -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>
Expand All @@ -57,6 +58,7 @@
BasicBondGeneratorTest.class,
BasicSceneGeneratorTest.class,
BasicGeneratorTest.class,
RingGeneratorTest.class,
WedgeLineElementTest.class,
LineElementTest.class,
PathElementTest.class,
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -55,11 +57,21 @@ public abstract class AbstractGeneratorTest {

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());
Expand Down Expand Up @@ -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()
);
}
}
Expand Up @@ -69,6 +69,7 @@ public void setup() {
super.setup();
this.generator = new BasicAtomGenerator();
model.registerParameters(generator);
super.setTestedGenerator(generator);
}

@Test
Expand Down
Expand Up @@ -34,6 +34,7 @@ public void setup() {
super.setup();
this.generator = new BasicBondGenerator();
model.registerParameters(generator);
super.setTestedGenerator(generator);
}

@Test
Expand Down
Expand Up @@ -55,6 +55,7 @@ public void setup() {
super.setup();
this.generator = new BasicGenerator();
model.registerParameters(generator);
super.setTestedGenerator(generator);
}

@Test
Expand Down
Expand Up @@ -55,6 +55,7 @@ public void setup() {
super.setup();
this.generator = new BasicSceneGenerator();
model.registerParameters(generator);
super.setTestedGenerator(generator);
}

@Test
Expand Down
@@ -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 b245c6f

Please sign in to comment.