Skip to content
Browse files

Added unit test for bug #2993609 for not removing listeners with setA…

…toms(IAtom[])

Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information...
1 parent 3c15ff3 commit cd07ebccb9f81b496a17e89a956b553f1acfe3bc @egonw egonw committed with rajarshi Jun 25, 2011
Showing with 31 additions and 0 deletions.
  1. +31 −0 src/test/org/openscience/cdk/interfaces/AbstractAtomContainerTest.java
View
31 src/test/org/openscience/cdk/interfaces/AbstractAtomContainerTest.java
@@ -49,6 +49,37 @@
}
/**
+ * @cdk.bug 2993609
+ */
+ @Test public void testSetAtoms_removeListener() {
+ IAtomContainer ac = (IAtomContainer)newChemObject();
+
+ IAtom[] atoms = new IAtom[4];
+ atoms[0] = ac.getBuilder().newInstance(IAtom.class,"C");
+ atoms[1] = ac.getBuilder().newInstance(IAtom.class,"C");
+ atoms[2] = ac.getBuilder().newInstance(IAtom.class,"C");
+ atoms[3] = ac.getBuilder().newInstance(IAtom.class,"O");
+ ac.setAtoms(atoms);
+
+ // if an atom changes, the atomcontainer will throw a change event too
+ ChemObjectListenerImpl listener = new ChemObjectListenerImpl();
+ ac.addListener(listener);
+ Assert.assertFalse(listener.changed);
+
+ // ok, change the atom, and make sure we do get an event
+ atoms[0].setAtomTypeName("C.sp2");
+ Assert.assertTrue(listener.changed);
+
+ // reset the listener, overwrite the atoms, and change an old atom.
+ // if all is well, we should not get a change event this time
+ listener.reset();
+ Assert.assertFalse(listener.changed); // make sure the reset worked
+ ac.setAtoms(new IAtom[0]);
+ atoms[1].setAtomTypeName("C.sp2"); // make a change to an old atom
+ Assert.assertFalse(listener.changed); // but no change event should happen
+ }
+
+ /**
* Only test whether the atoms are correctly cloned.
*/
@Test public void testClone() throws Exception {

0 comments on commit cd07ebc

Please sign in to comment.
Something went wrong with that request. Please try again.