Skip to content

Commit

Permalink
Unit test to expose a NPE happening when IAtoms do not have formal ch…
Browse files Browse the repository at this point in the history
…arges set

Change-Id: I22b4eb3c30bf23f0f80c6d92bf33b15f9d1c65d0
  • Loading branch information
egonw committed Sep 15, 2014
1 parent 5128600 commit 87bbe61
Showing 1 changed file with 16 additions and 0 deletions.
Expand Up @@ -27,6 +27,7 @@
import org.junit.Test;
import org.openscience.cdk.Atom;
import org.openscience.cdk.AtomContainer;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.DefaultChemObjectBuilder;
Expand Down Expand Up @@ -633,6 +634,21 @@ public void testGetMolecularFormula_IAtomContainer() {
Assert.assertEquals(MolecularFormulaManipulator.getElementCount(mf2, elemH),
MolecularFormulaManipulator.getElementCount(mf1, elemH));

}

@Test
public void testGetMolecularFormula_IAtomNullCharge(){
IAtomContainer ac = builder.newInstance(IAtomContainer.class);
ac.addAtom(builder.newInstance(IAtom.class,"C"));
ac.getAtom(0).setFormalCharge((Integer)CDKConstants.UNSET);
ac.addAtom(builder.newInstance(IAtom.class,"C"));
ac.addAtom(builder.newInstance(IAtom.class,"H"));
ac.addAtom(builder.newInstance(IAtom.class,"H"));
ac.addAtom(builder.newInstance(IAtom.class,"H"));
ac.addAtom(builder.newInstance(IAtom.class,"H"));

IMolecularFormula mf1 = MolecularFormulaManipulator.getMolecularFormula(ac);
Assert.assertNotNull(mf1);
}

@Test
Expand Down

0 comments on commit 87bbe61

Please sign in to comment.