Permalink
Browse files

Added dedicated unit testing for the InChIGeneratorFactory

Change-Id: I6f77b41e950474857e953181b0f03af5fa92a4ea
  • Loading branch information...
1 parent 516edbb commit a80b6d51230f69d58297730768d45ab5d7580e87 @egonw egonw committed Mar 15, 2012
@@ -26,6 +26,8 @@
import net.sf.jniinchi.JniInchiWrapper;
import net.sf.jniinchi.LoadNativeLibraryException;
+import org.openscience.cdk.annotations.TestClass;
+import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
@@ -64,6 +66,7 @@
* @cdk.module inchi
* @cdk.githash
*/
+@TestClass("org.openscience.cdk.inchi.InChIGeneratorFactoryTest")
public class InChIGeneratorFactory {
private static InChIGeneratorFactory INSTANCE;
@@ -92,6 +95,7 @@ private InChIGeneratorFactory() throws CDKException {
* @throws CDKException if unable to load native code when attempting
* to create the factory
*/
+ @TestMethod("testGetInstance")
public static InChIGeneratorFactory getInstance() throws CDKException {
synchronized ( InChIGeneratorFactory.class ) {
if ( INSTANCE == null ) {
@@ -108,6 +112,7 @@ public static InChIGeneratorFactory getInstance() throws CDKException {
* @return the InChI generator object
* @throws CDKException if the generator cannot be instantiated
*/
+ @TestMethod("testGetInChIGenerator_IAtomContainer")
public InChIGenerator getInChIGenerator(IAtomContainer container)
throws CDKException {
return(new InChIGenerator(container));
@@ -121,6 +126,7 @@ public InChIGenerator getInChIGenerator(IAtomContainer container)
* @return the InChI generator object
* @throws CDKException if the generator cannot be instantiated
*/
+ @TestMethod("testGetInChIGenerator_IAtomContainer_String")
public InChIGenerator getInChIGenerator(IAtomContainer container,
String options)
throws CDKException {
@@ -135,6 +141,7 @@ public InChIGenerator getInChIGenerator(IAtomContainer container,
* @return the InChI generator object
* @throws CDKException if the generator cannot be instantiated
*/
+ @TestMethod("testGetInChIGenerator_IAtomContainer_List")
public InChIGenerator getInChIGenerator(IAtomContainer container,
List<INCHI_OPTION> options) throws CDKException {
return(new InChIGenerator(container, options));
@@ -148,6 +155,7 @@ public InChIGenerator getInChIGenerator(IAtomContainer container,
* @return the InChI structure generator object
* @throws CDKException if the generator cannot be instantiated
*/
+ @TestMethod("testGetInChIToStructure_String_IChemObjectBuilder")
public InChIToStructure getInChIToStructure(String inchi,
IChemObjectBuilder builder)
throws CDKException {
@@ -163,6 +171,7 @@ public InChIToStructure getInChIToStructure(String inchi,
* @return the InChI structure generator object
* @throws CDKException if the generator cannot be instantiated
*/
+ @TestMethod("testGetInChIToStructure_String_IChemObjectBuilder_NullString")
public InChIToStructure getInChIToStructure(String inchi,
IChemObjectBuilder builder,
String options)
@@ -179,6 +188,7 @@ public InChIToStructure getInChIToStructure(String inchi,
* @return the InChI structure generator object
* @throws CDKException if the generator cannot be instantiated
*/
+ @TestMethod("testGetInChIToStructure_String_IChemObjectBuilder_List")
public InChIToStructure getInChIToStructure(String inchi,
IChemObjectBuilder builder,
List<String> options)
@@ -0,0 +1,146 @@
+/* Copyright (C) 2006 Sam Adams <sea36@users.sf.net>
+ * 2007 Rajarshi Guha <rajarshi.guha@gmail.com>
+ * 2010,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.inchi;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sf.jniinchi.INCHI_OPTION;
+import net.sf.jniinchi.INCHI_RET;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openscience.cdk.Atom;
+import org.openscience.cdk.AtomContainer;
+import org.openscience.cdk.DefaultChemObjectBuilder;
+import org.openscience.cdk.exception.CDKException;
+import org.openscience.cdk.interfaces.IAtom;
+import org.openscience.cdk.interfaces.IAtomContainer;
+
+/**
+ * @cdk.module test-inchi
+ */
+public class InChIGeneratorFactoryTest {
+
+ @Test
+ public void testGetInstance() throws CDKException {
+ InChIGeneratorFactory factory = InChIGeneratorFactory.getInstance();
+ Assert.assertNotNull(factory);
+ }
+
+ /**
+ * Because we are not setting any options, we get an Standard InChI.
+ */
+ @Test public void testGetInChIGenerator_IAtomContainer() throws Exception {
+ IAtomContainer ac = new AtomContainer();
+ IAtom a = new Atom("Cl");
+ a.setImplicitHydrogenCount(1);
+ ac.addAtom(a);
+ InChIGenerator gen = InChIGeneratorFactory.getInstance().getInChIGenerator(ac);
+ Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
+ Assert.assertEquals("InChI=1S/ClH/h1H", gen.getInchi());
+ }
+
+ /**
+ * Because we are setting an options, we get a non-standard InChI.
+ */
+ @Test public void testGetInChIGenerator_IAtomContainer_String() throws Exception {
+ IAtomContainer ac = new AtomContainer();
+ IAtom a = new Atom("Cl");
+ a.setImplicitHydrogenCount(1);
+ ac.addAtom(a);
+ InChIGenerator gen = InChIGeneratorFactory.getInstance().getInChIGenerator(ac, "FixedH");
+ Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
+ Assert.assertEquals("InChI=1/ClH/h1H", gen.getInchi());
+ }
+
+ /**
+ * Because we are setting no option, we get a Standard InChI.
+ */
+ @Test public void testGetInChIGenerator_IAtomContainer_NullString() throws Exception {
+ IAtomContainer ac = new AtomContainer();
+ IAtom a = new Atom("Cl");
+ a.setImplicitHydrogenCount(1);
+ ac.addAtom(a);
+ InChIGenerator gen = InChIGeneratorFactory.getInstance().getInChIGenerator(ac, (String)null);
+ Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
+ Assert.assertEquals("InChI=1S/ClH/h1H", gen.getInchi());
+ }
+
+ /**
+ * Because we are setting an options, we get a non-standard InChI.
+ */
+ @Test public void testGetInChIGenerator_IAtomContainer_List() throws Exception {
+ IAtomContainer ac = new AtomContainer();
+ IAtom a = new Atom("Cl");
+ a.setImplicitHydrogenCount(1);
+ ac.addAtom(a);
+ List<INCHI_OPTION> options = new ArrayList<INCHI_OPTION>();
+ options.add(INCHI_OPTION.FixedH);
+ InChIGenerator gen = InChIGeneratorFactory.getInstance().getInChIGenerator(ac, options);
+ Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
+ Assert.assertEquals("InChI=1/ClH/h1H", gen.getInchi());
+ }
+
+ /**
+ * Because we are setting an options, we get a non-standard InChI.
+ */
+ @Test(expected=IllegalArgumentException.class)
+ public void testGetInChIGenerator_IAtomContainer_NullList() throws Exception {
+ IAtomContainer ac = new AtomContainer();
+ IAtom a = new Atom("Cl");
+ a.setImplicitHydrogenCount(1);
+ ac.addAtom(a);
+ InChIGeneratorFactory.getInstance().getInChIGenerator(ac, (List<INCHI_OPTION>)null);
+ }
+
+ @Test
+ public void testGetInChIToStructure_String_IChemObjectBuilder() throws CDKException {
+ InChIToStructure parser = InChIGeneratorFactory.getInstance().getInChIToStructure(
+ "InChI=1/ClH/h1H", DefaultChemObjectBuilder.getInstance()
+ );
+ Assert.assertNotNull(parser);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testGetInChIToStructure_String_IChemObjectBuilder_NullString() throws CDKException {
+ InChIGeneratorFactory.getInstance().getInChIToStructure(
+ "InChI=1/ClH/h1H", DefaultChemObjectBuilder.getInstance(), (String)null
+ );
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testGetInChIToStructure_String_IChemObjectBuilder_NullList() throws CDKException {
+ InChIGeneratorFactory.getInstance().getInChIToStructure(
+ "InChI=1/ClH/h1H", DefaultChemObjectBuilder.getInstance(), (List<String>)null
+ );
+ }
+
+ /**
+ * No options set.
+ */
+ @Test public void testGetInChIToStructure_String_IChemObjectBuilder_List() throws CDKException {
+ InChIToStructure parser = InChIGeneratorFactory.getInstance().getInChIToStructure(
+ "InChI=1/ClH/h1H", DefaultChemObjectBuilder.getInstance(), new ArrayList<String>()
+ );
+ Assert.assertNotNull(parser);
+ }
+}
@@ -24,6 +24,7 @@
import org.junit.runners.Suite.SuiteClasses;
import org.openscience.cdk.coverage.InchiCoverageTest;
import org.openscience.cdk.graph.invariant.InChINumbersToolsTest;
+import org.openscience.cdk.inchi.InChIGeneratorFactoryTest;
import org.openscience.cdk.inchi.InChIGeneratorTest;
import org.openscience.cdk.inchi.InChIToStructureTest;
@@ -37,6 +38,7 @@
InchiCoverageTest.class,
InChIGeneratorTest.class,
InChIToStructureTest.class,
- InChINumbersToolsTest.class
+ InChINumbersToolsTest.class,
+ InChIGeneratorFactoryTest.class
})
public class MinchiTests {}

0 comments on commit a80b6d5

Please sign in to comment.