Skip to content

Commit

Permalink
Added unit test for bug #2993609 for not removing listeners with setA…
Browse files Browse the repository at this point in the history
…toms(IAtom[])

Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information
egonw authored and rajarshi committed Jun 25, 2011
1 parent 3c15ff3 commit cd07ebc
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,6 +48,37 @@ public abstract class AbstractAtomContainerTest extends AbstractChemObjectTest {
//Assert.assertEquals(4, ac.getAtoms().length); //Assert.assertEquals(4, ac.getAtoms().length);
} }


/**
* @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. * Only test whether the atoms are correctly cloned.
*/ */
Expand Down

0 comments on commit cd07ebc

Please sign in to comment.