Permalink
Browse files

Simplified the code using the new 'T read(T)' API used in MDLV2000Rea…

…der as defined by the ISimpleChemObjectReader

Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information...
1 parent d3f2f19 commit af12e8a69deb17f545f6d59fe9ea950fa4985452 @egonw committed with rajarshi Feb 27, 2010
Showing with 33 additions and 35 deletions.
  1. +33 −35 src/test/org/openscience/cdk/io/MDLV2000ReaderTest.java
View
68 src/test/org/openscience/cdk/io/MDLV2000ReaderTest.java
@@ -38,7 +38,6 @@
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.ChemModel;
-import org.openscience.cdk.ChemObject;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.PseudoAtom;
@@ -48,7 +47,6 @@
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemFile;
-import org.openscience.cdk.interfaces.IChemObject;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IPseudoAtom;
import org.openscience.cdk.io.IChemObjectReader.Mode;
@@ -92,7 +90,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
Assert.assertEquals(1, chemFile.getChemSequenceCount());
@@ -126,7 +124,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -139,7 +137,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -155,7 +153,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -169,7 +167,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -191,7 +189,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- Molecule mol = (Molecule)reader.read(new Molecule());
+ Molecule mol = reader.read(new Molecule());
Assert.assertEquals("a-pinen.mol", mol.getProperty(CDKConstants.TITLE));
}
@@ -200,7 +198,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -214,7 +212,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -228,7 +226,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -242,7 +240,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -255,7 +253,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -269,7 +267,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -283,7 +281,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -296,7 +294,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -310,7 +308,7 @@
MDLV2000Reader reader = new MDLV2000Reader(ins);
Molecule superspiro = new Molecule();
superspiro.setID("superspiro");
- Molecule result = (Molecule)reader.read(superspiro);
+ Molecule result = reader.read(superspiro);
Assert.assertEquals(superspiro.getID(), result.getID());
}
@@ -343,7 +341,7 @@
" 3 9 1 0 0 0\n" +
"M END\n";
MDLV2000Reader reader = new MDLV2000Reader(new StringReader(mdl));
- ChemFile chemFile = (ChemFile) reader.read(new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
Assert.assertEquals(1, chemFile.getChemSequenceCount());
org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0);
@@ -366,7 +364,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- Molecule mol = (Molecule)reader.read(new Molecule());
+ Molecule mol = reader.read(new Molecule());
Assert.assertEquals("R2",((PseudoAtom)mol.getAtom(19)).getLabel());
}
@@ -375,7 +373,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- Molecule mol = (Molecule)reader.read(new Molecule());
+ Molecule mol = reader.read(new Molecule());
IAtom atom = mol.getAtom(3);
Assert.assertTrue(atom instanceof PseudoAtom);
Assert.assertEquals("R1", ((PseudoAtom)atom).getLabel());
@@ -389,7 +387,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -407,7 +405,7 @@
"M CHG 1 1 1\n" +
"M END\n";
MDLV2000Reader reader = new MDLV2000Reader(new StringReader(mdl));
- Molecule mol = (Molecule)reader.read(new Molecule());
+ Molecule mol = reader.read(new Molecule());
Assert.assertNotNull(mol);
Assert.assertEquals(1, mol.getAtomCount());
Assert.assertEquals(0, mol.getBondCount());
@@ -421,15 +419,15 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- IChemFile chemFile = (IChemFile) reader.read((IChemObject) new org.openscience.cdk.ChemFile());
+ IChemFile chemFile = reader.read(new ChemFile());
Assert.assertEquals(1, chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getMolecule(0).getAtom(6).getFormalCharge().intValue());
Assert.assertEquals(-1, chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getMolecule(0).getAtom(8).getFormalCharge().intValue());
}
@Test public void testEmptyString() throws Exception {
String emptyString = "";
MDLV2000Reader reader = new MDLV2000Reader(new StringReader(emptyString));
- IMolecule mol = (IMolecule) reader.read(new NNMolecule());
+ IMolecule mol = reader.read(new NNMolecule());
Assert.assertNull(mol);
}
@@ -438,7 +436,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -471,7 +469,7 @@
reader.addChemObjectIOListener(listener);
reader.customizeJob();
- IMolecule mol = (IMolecule) reader.read(DefaultChemObjectBuilder.getInstance().newMolecule());
+ IMolecule mol = reader.read(DefaultChemObjectBuilder.getInstance().newMolecule());
Assert.assertNotNull(mol);
Assert.assertEquals(5, mol.getAtomCount());
@@ -488,7 +486,7 @@
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
try {
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- reader.read((ChemObject)new ChemFile());
+ reader.read(new ChemFile());
Assert.fail("Expected a CDKException");
} catch (Exception exception) {
// OK, that's what's is supposed to happen
@@ -503,7 +501,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.RELAXED);
- IChemFile chemFile = (IChemFile)reader.read((ChemObject)new ChemFile());
+ IChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertNotNull(containersList.get(0));
@@ -520,7 +518,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(1, containersList.size());
@@ -558,7 +556,7 @@
" 3 9 1 0 0 0\n" +
"M END\n";
MDLV2000Reader reader = new MDLV2000Reader(new StringReader(mdl));
- IMolecule molecule = (IMolecule) reader.read(new Molecule());
+ IMolecule molecule = reader.read(new Molecule());
Assert.assertNotNull(molecule);
Assert.assertEquals(9, molecule.getAtomCount());
Assert.assertEquals(9, molecule.getBondCount());
@@ -573,7 +571,7 @@
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- IMolecule mol = (IMolecule)reader.read(new NNMolecule());
+ IMolecule mol = reader.read(new NNMolecule());
Assert.assertEquals(IBond.Stereo.E_OR_Z,mol.getBond(1).getStereo());
Assert.assertEquals(IBond.Stereo.E_OR_Z,mol.getBond(6).getStereo());
Assert.assertEquals(IBond.Stereo.E_OR_Z,mol.getBond(7).getStereo());
@@ -589,7 +587,7 @@
InputStream ins = this.getClass().getClassLoader()
.getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList =
ChemFileManipulator.getAllAtomContainers(chemFile);
@@ -627,7 +625,7 @@
" 3 9 1 0 0 0\n" +
"M END\n";
MDLV2000Reader reader = new MDLV2000Reader(new StringReader(mdl));
- IMolecule mol = (IMolecule) reader.read(new Molecule());
+ IMolecule mol = reader.read(new Molecule());
Assert.assertNotNull(mol);
Assert.assertEquals(9, mol.getAtomCount());
Assert.assertEquals(9, mol.getBondCount());
@@ -641,7 +639,7 @@
InputStream ins = this.getClass().getClassLoader()
.getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
+ ChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList =
ChemFileManipulator.getAllAtomContainers(chemFile);
@@ -665,7 +663,7 @@ public void testQueryBondTypes() throws Exception {
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
- reader.read((ChemObject)new ChemFile());
+ reader.read(new ChemFile());
}
}

0 comments on commit af12e8a

Please sign in to comment.