Skip to content

Commit

Permalink
More unit tests. All methods are now at least tested once. (closes #3…
Browse files Browse the repository at this point in the history
…005889)

Change-Id: I305ed297ff335cdd20cd119c84c3968e6e7b13d6
  • Loading branch information
egonw committed Mar 23, 2012
1 parent 8a4d7d8 commit 6d051a6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/META-INF/test-inchi.cdkdepends
Expand Up @@ -9,3 +9,4 @@ cdk-valencycheck.jar
cdk-test.jar
cdk-inchi.jar
cdk-smiles.jar
cdk-silent.jar
4 changes: 4 additions & 0 deletions src/main/org/openscience/cdk/inchi/InChIToStructure.java
Expand Up @@ -142,6 +142,7 @@ protected InChIToStructure(String inchi, IChemObjectBuilder builder, List<String
*
* @throws CDKException
*/
@TestMethod("testGetAtomContainer_IChemObjectBuilder")
protected void generateAtomContainerFromInchi(IChemObjectBuilder builder) throws CDKException {
try {
output = JniInchiWrapper.getStructureFromInchi(input);
Expand Down Expand Up @@ -289,13 +290,15 @@ public INCHI_RET getReturnStatus() {
/**
* Gets generated (error/warning) messages.
*/
@TestMethod("testGetMessage")
public String getMessage() {
return(output.getMessage());
}

/**
* Gets generated log.
*/
@TestMethod("testGetLog")
public String getLog() {
return(output.getLog());
}
Expand All @@ -309,6 +312,7 @@ public String getLog() {
* <br>y=1 => Main layer or Mobile-H
* <br>y=0 => Fixed-H layer
*/
@TestMethod("testGetWarningFlags")
public long[][] getWarningFlags() {
return(output.getWarningFlags());
}
Expand Down
57 changes: 57 additions & 0 deletions src/test/org/openscience/cdk/inchi/InChIToStructureTest.java
Expand Up @@ -27,6 +27,8 @@
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond.Order;
import org.openscience.cdk.silent.AtomContainer;
import org.openscience.cdk.silent.SilentChemObjectBuilder;

/**
* TestCase for the {@link InChIToStructure} class.
Expand Down Expand Up @@ -84,4 +86,59 @@ public void testGetReturnStatus_EOF() throws CDKException {
Assert.assertEquals(INCHI_RET.EOF, returnStatus);
}

@Test
public void testGetMessage() throws CDKException {
InChIToStructure parser = new InChIToStructure(
"InChI=1S/CH5/h1H4", DefaultChemObjectBuilder.getInstance()
);
parser.getAtomContainer();
String message = parser.getMessage();
Assert.assertNotNull(message);
}

@Test
public void testGetMessageNull() throws CDKException {
InChIToStructure parser = new InChIToStructure(
"InChI=1S", DefaultChemObjectBuilder.getInstance()
);
parser.getAtomContainer();
String message = parser.getMessage();
Assert.assertNull(message);
}

@Test
public void testGetLog() throws CDKException {
InChIToStructure parser = new InChIToStructure(
"InChI=1S/CH5/h1H4", DefaultChemObjectBuilder.getInstance()
);
parser.getAtomContainer();
String message = parser.getMessage();
Assert.assertNotNull(message);
}

@Test
public void testGetWarningFlags() throws CDKException {
InChIToStructure parser = new InChIToStructure(
"InChI=1S/CH5/h1H4", DefaultChemObjectBuilder.getInstance()
);
parser.getAtomContainer();
long[][] flags = parser.getWarningFlags();
Assert.assertNotNull(flags);
Assert.assertEquals(2, flags.length);
Assert.assertEquals(2, flags[0].length);
Assert.assertEquals(2, flags[1].length);
}

@Test
public void testGetAtomContainer_IChemObjectBuilder() throws CDKException {
InChIToStructure parser = new InChIToStructure(
"InChI=1S/CH5/h1H4", DefaultChemObjectBuilder.getInstance()
);
parser.generateAtomContainerFromInchi(SilentChemObjectBuilder.getInstance());
IAtomContainer container = parser.getAtomContainer();
// test if the created IAtomContainer is done with the Silent module...
// OK, this is not typical use, but maybe the above generate method should be private
Assert.assertTrue(container instanceof AtomContainer);
}

}

0 comments on commit 6d051a6

Please sign in to comment.