SingleElectronDiff { public static IDifference difference(IChemObject first, IChemObject second) { if (!(first instanceof ISingleElectron && second instanceof ISingleElectron)) { return null; } ISingleElectron firstB = (ISingleElectron) first; ISingleElectron secondB = (ISingleElectron) second; IDifferenceList totalDiff = new ChemObjectDifference("SingleElectronDiff"); totalDiff.addChild(AtomDiff.difference(firstB.getAtom(), secondB.getAtom())); totalDiff.addChild(ElectronContainerDiff.difference(first, second)); if (totalDiff.childCount() > 0) { return totalDiff; } else { return null; } } private  SingleElectronDiff(); static String diff(IChemObject first, IChemObject second); static IDifference difference(IChemObject first, IChemObject second);  }
@Test public void testDifference() { IAtom carbon = mock(IAtom.class); IAtom oxygen = mock(IAtom.class); when(carbon.getSymbol()).thenReturn("C"); when(carbon.getSymbol()).thenReturn("H"); IBond bond1 = mock(IBond.class); IBond bond2 = mock(IBond.class); when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); when(bond2.getOrder()).thenReturn(IBond.Order.DOUBLE); when(bond1.getAtomCount()).thenReturn(2); when(bond2.getAtomCount()).thenReturn(2); when(bond1.getBegin()).thenReturn(carbon); when(bond1.getEnd()).thenReturn(carbon); when(bond2.getBegin()).thenReturn(carbon); when(bond2.getEnd()).thenReturn(oxygen); bond1.setOrder(IBond.Order.SINGLE); bond2.setOrder(IBond.Order.DOUBLE); IDifference difference = BondDiff.difference(bond1, bond2); Assert.assertNotNull(difference); }