ConjugatedAtomEncoder implements AtomEncoder { @Override public int encode(IAtom atom, IAtomContainer container) { int hash = 179426549; for (AtomEncoder encoder : encoders) hash = 31 * hash + encoder.encode(atom, container); return hash; } ConjugatedAtomEncoder(List<AtomEncoder> encoders); @Override int encode(IAtom atom, IAtomContainer container); static AtomEncoder create(AtomEncoder encoder, AtomEncoder... encoders);  }
@Test public void testConstruction_Modification() { AtomEncoder a = mock(AtomEncoder.class); AtomEncoder b = mock(AtomEncoder.class); AtomEncoder c = mock(AtomEncoder.class); IAtom atom = mock(IAtom.class); IAtomContainer container = mock(IAtomContainer.class); List<AtomEncoder> encoders = new ArrayList<AtomEncoder>(); encoders.add(a); encoders.add(b); encoders.add(c); AtomEncoder encoder = new ConjugatedAtomEncoder(encoders); encoders.remove(2); encoder.encode(atom, container); InOrder order = inOrder(a, b, c); order.verify(a, times(1)).encode(atom, container); order.verify(b, times(1)).encode(atom, container); order.verify(c, times(1)).encode(atom, container); verifyNoMoreInteractions(a, b, c, atom, container); }
@Test public void testEncode_Single() throws Exception { AtomEncoder a = mock(AtomEncoder.class); IAtom atom = mock(IAtom.class); IAtomContainer container = mock(IAtomContainer.class); AtomEncoder encoder = new ConjugatedAtomEncoder(Arrays.asList(a)); encoder.encode(atom, container); verify(a, times(1)).encode(atom, container); verifyNoMoreInteractions(a, atom, container); }
@Test public void testEncode() throws Exception { AtomEncoder a = mock(AtomEncoder.class); AtomEncoder b = mock(AtomEncoder.class); AtomEncoder c = mock(AtomEncoder.class); IAtom atom = mock(IAtom.class); IAtomContainer container = mock(IAtomContainer.class); AtomEncoder encoder = new ConjugatedAtomEncoder(Arrays.asList(a, b, c)); encoder.encode(atom, container); InOrder order = inOrder(a, b, c); order.verify(a, times(1)).encode(atom, container); order.verify(b, times(1)).encode(atom, container); order.verify(c, times(1)).encode(atom, container); verifyNoMoreInteractions(a, b, c, atom, container); }