GeometricDoubleBondEncoderFactory implements StereoEncoderFactory { @Override public StereoEncoder create(IAtomContainer container, int[][] graph) { List<StereoEncoder> encoders = new ArrayList<StereoEncoder>(5); for (IBond bond : container.bonds()) { if (DOUBLE.equals(bond.getOrder()) && !E_OR_Z.equals(bond.getStereo())) { IAtom left = bond.getBegin(); IAtom right = bond.getEnd(); if (Integer.valueOf(7).equals(left.getAtomicNumber()) && Integer.valueOf(7).equals(right.getAtomicNumber())) continue; StereoEncoder encoder = newEncoder(container, left, right, right, left, graph); if (encoder != null) { encoders.add(encoder); } } } return encoders.isEmpty() ? StereoEncoder.EMPTY : new MultiStereoEncoder(encoders); }  @Override StereoEncoder create(IAtomContainer container, int[][] graph);  }
@Test public void testCreate() throws Exception { IAtomContainer mol = mock(IAtomContainer.class); IAtom a = mock(IAtom.class); IAtom b = mock(IAtom.class); IAtom c = mock(IAtom.class); IAtom d = mock(IAtom.class); IAtom e = mock(IAtom.class); IAtom f = mock(IAtom.class); when(mol.indexOf(a)).thenReturn(0); when(mol.indexOf(b)).thenReturn(1); when(mol.indexOf(c)).thenReturn(2); when(mol.indexOf(d)).thenReturn(3); when(mol.indexOf(e)).thenReturn(4); when(mol.indexOf(f)).thenReturn(5); when(mol.getAtom(0)).thenReturn(a); when(mol.getAtom(1)).thenReturn(b); when(mol.getAtom(2)).thenReturn(c); when(mol.getAtom(3)).thenReturn(d); when(mol.getAtom(4)).thenReturn(e); when(mol.getAtom(5)).thenReturn(f); when(b.getHybridization()).thenReturn(IAtomType.Hybridization.SP2); when(c.getHybridization()).thenReturn(IAtomType.Hybridization.SP2); when(a.getPoint2d()).thenReturn(new Point2d()); when(b.getPoint2d()).thenReturn(new Point2d()); when(c.getPoint2d()).thenReturn(new Point2d()); when(d.getPoint2d()).thenReturn(new Point2d()); when(e.getPoint2d()).thenReturn(new Point2d()); when(f.getPoint2d()).thenReturn(new Point2d()); IBond ba = mock(IBond.class); IBond be = mock(IBond.class); IBond bc = mock(IBond.class); IBond cd = mock(IBond.class); IBond cf = mock(IBond.class); when(ba.getBegin()).thenReturn(b); when(ba.getEnd()).thenReturn(a); when(be.getBegin()).thenReturn(b); when(be.getEnd()).thenReturn(e); when(bc.getBegin()).thenReturn(b); when(bc.getEnd()).thenReturn(c); when(cd.getBegin()).thenReturn(c); when(cd.getEnd()).thenReturn(d); when(cf.getBegin()).thenReturn(c); when(cf.getEnd()).thenReturn(f); when(bc.getOrder()).thenReturn(IBond.Order.DOUBLE); when(mol.bonds()).thenReturn(Arrays.asList(ba, be, bc, cd, cf)); when(mol.getConnectedBondsList(a)).thenReturn(Arrays.asList(ba)); when(mol.getConnectedBondsList(b)).thenReturn(Arrays.asList(ba, bc, be)); when(mol.getConnectedBondsList(c)).thenReturn(Arrays.asList(bc, cd, cf)); when(mol.getConnectedBondsList(d)).thenReturn(Arrays.asList(cd)); when(mol.getConnectedBondsList(e)).thenReturn(Arrays.asList(be)); when(mol.getConnectedBondsList(f)).thenReturn(Arrays.asList(cf)); StereoEncoderFactory factory = new GeometricDoubleBondEncoderFactory(); int[][] g = new int[][]{{1}, {0, 2, 4}, {1, 3, 5}, {2}, {1}, {2}}; assertTrue(factory.create(mol, g) instanceof MultiStereoEncoder); }
@Test public void testCreate_NoCoordinates() throws Exception { IAtomContainer mol = mock(IAtomContainer.class); IAtom a = mock(IAtom.class); IAtom b = mock(IAtom.class); IAtom c = mock(IAtom.class); IAtom d = mock(IAtom.class); IAtom e = mock(IAtom.class); IAtom f = mock(IAtom.class); when(mol.indexOf(a)).thenReturn(0); when(mol.indexOf(b)).thenReturn(1); when(mol.indexOf(c)).thenReturn(2); when(mol.indexOf(d)).thenReturn(3); when(mol.indexOf(e)).thenReturn(4); when(mol.indexOf(f)).thenReturn(5); when(mol.getAtom(0)).thenReturn(a); when(mol.getAtom(1)).thenReturn(b); when(mol.getAtom(2)).thenReturn(c); when(mol.getAtom(3)).thenReturn(d); when(mol.getAtom(4)).thenReturn(e); when(mol.getAtom(5)).thenReturn(f); when(b.getHybridization()).thenReturn(IAtomType.Hybridization.SP2); when(c.getHybridization()).thenReturn(IAtomType.Hybridization.SP2); IBond ba = mock(IBond.class); IBond be = mock(IBond.class); IBond bc = mock(IBond.class); IBond cd = mock(IBond.class); IBond cf = mock(IBond.class); when(ba.getBegin()).thenReturn(b); when(ba.getEnd()).thenReturn(a); when(be.getBegin()).thenReturn(b); when(be.getEnd()).thenReturn(e); when(bc.getBegin()).thenReturn(b); when(bc.getEnd()).thenReturn(c); when(cd.getBegin()).thenReturn(c); when(cd.getEnd()).thenReturn(d); when(cf.getBegin()).thenReturn(c); when(cf.getEnd()).thenReturn(f); when(bc.getOrder()).thenReturn(IBond.Order.DOUBLE); when(mol.bonds()).thenReturn(Arrays.asList(ba, be, bc, cd, cf)); when(mol.getConnectedBondsList(a)).thenReturn(Arrays.asList(ba)); when(mol.getConnectedBondsList(b)).thenReturn(Arrays.asList(ba, bc, be)); when(mol.getConnectedBondsList(c)).thenReturn(Arrays.asList(bc, cd, cf)); when(mol.getConnectedBondsList(d)).thenReturn(Arrays.asList(cd)); when(mol.getConnectedBondsList(e)).thenReturn(Arrays.asList(be)); when(mol.getConnectedBondsList(f)).thenReturn(Arrays.asList(cf)); StereoEncoderFactory factory = new GeometricDoubleBondEncoderFactory(); int[][] g = new int[][]{{1}, {0, 2, 4}, {1, 3, 5}, {2}, {1}, {2}}; assertTrue(factory.create(mol, g) == StereoEncoder.EMPTY); }