BondDiff { public static IDifference difference(IChemObject first, IChemObject second) { if (!(first instanceof IBond && second instanceof IBond)) { return null; } IBond firstB = (IBond) first; IBond secondB = (IBond) second; IDifferenceList totalDiff = new ChemObjectDifference("BondDiff"); totalDiff.addChild(BondOrderDifference.construct("order", firstB.getOrder(), secondB.getOrder())); totalDiff.addChild(IntegerDifference.construct("atomCount", firstB.getAtomCount(), secondB.getAtomCount())); if (firstB.getAtomCount() == secondB.getAtomCount()) { totalDiff.addChild(AtomDiff.difference(firstB.getBegin(), secondB.getBegin())); totalDiff.addChild(AtomDiff.difference(firstB.getEnd(), secondB.getEnd())); for (int i = 2; i < firstB.getAtomCount(); i++) { totalDiff.addChild(AtomDiff.difference(firstB.getAtom(i), secondB.getAtom(i))); } } totalDiff.addChild(ElectronContainerDiff.difference(first, second)); if (totalDiff.childCount() > 0) { return totalDiff; } else { return null; } } private  BondDiff(); 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(oxygen.getSymbol()).thenReturn("O"); 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); }