public void testForDuplicateDefinitions() { IAtomType[] expectedTypesArray = getFactory().getAllAtomTypes(); Set<String> alreadyDefinedTypes = new HashSet<String>(); for (int i = 0; i < expectedTypesArray.length; i++) { String definedType = expectedTypesArray[i].getAtomTypeName(); if (alreadyDefinedTypes.contains(definedType)) { Assert.fail("Duplicate atom type definition in XML: " + definedType); } alreadyDefinedTypes.add(definedType); } }
IAtomType[] expectedTypesArray = factory.getAllAtomTypes(); for (int i = 0; i < expectedTypesArray.length; i++) { definedTypes.add(expectedTypesArray[i].getAtomTypeName());
/** * The test seems to be run by JUnit in order in which they found * in the source. Ugly, but @AfterClass does not work because that * methods does cannot assert anything. * * ...not anymore. Bad idea to do have such a test in the first place * but we can hack it by sorting by test name (see fix method order * annotation). */ @Test public void utestCountTestedAtomTypes() { AtomTypeFactory factory = AtomTypeFactory.getInstance( "org/openscience/cdk/config/data/structgen_atomtypes.xml", SilentChemObjectBuilder.getInstance()); IAtomType[] expectedTypes = factory.getAllAtomTypes(); if (expectedTypes.length != testedAtomTypes.size()) { String errorMessage = "Atom types not tested:"; for (IAtomType expectedType : expectedTypes) { if (!testedAtomTypes.containsKey(expectedType.getAtomTypeName())) errorMessage += " " + expectedType.getAtomTypeName(); } Assert.assertEquals(errorMessage, factory.getAllAtomTypes().length, testedAtomTypes.size()); } }
@Test public void testGetAllAtomTypes() throws Exception { AtomTypeFactory atf = AtomTypeFactory.getInstance(new ChemObject().getBuilder()); IAtomType[] types = atf.getAllAtomTypes(); Assert.assertNotNull(types); Assert.assertNotSame(0, types.length); }