GeometricDoubleBondEncoderFactory implements StereoEncoderFactory { static boolean accept(IAtom atom, List<IBond> bonds) { int dbCount = 0; if (!IAtomType.Hybridization.SP2.equals(atom.getHybridization())) return false; if (bonds.size() == 1) return false; for (IBond bond : bonds) { if (DOUBLE.equals(bond.getOrder())) dbCount++; IBond.Stereo stereo = bond.getStereo(); if (IBond.Stereo.UP_OR_DOWN.equals(stereo) || IBond.Stereo.UP_OR_DOWN_INVERTED.equals(stereo)) return false; } return dbCount == 1; }  @Override StereoEncoder create(IAtomContainer container, int[][] graph);  }
@Test public void testAccept_Hybridization() throws Exception { IAtom atom = mock(IAtom.class); IBond a = mock(IBond.class); IBond b = mock(IBond.class); IBond c = mock(IBond.class); when(a.getOrder()).thenReturn(IBond.Order.DOUBLE); List<IBond> bonds = Arrays.asList(a, b, c); assertFalse(GeometricDoubleBondEncoderFactory.accept(atom, bonds)); when(atom.getHybridization()).thenReturn(IAtomType.Hybridization.SP2); assertTrue(GeometricDoubleBondEncoderFactory.accept(atom, bonds)); }
@Test public void testAccept_QueryBond() throws Exception { IAtom atom = mock(IAtom.class); IBond a = mock(IBond.class); IBond b = mock(IBond.class); IBond c = mock(IBond.class); List<IBond> bonds = Arrays.asList(a, b, c); when(atom.getHybridization()).thenReturn(IAtomType.Hybridization.SP2); when(a.getOrder()).thenReturn(IBond.Order.DOUBLE); assertTrue(GeometricDoubleBondEncoderFactory.accept(atom, bonds)); when(b.getStereo()).thenReturn(IBond.Stereo.UP_OR_DOWN); assertFalse(GeometricDoubleBondEncoderFactory.accept(atom, bonds)); when(b.getStereo()).thenReturn(IBond.Stereo.UP_OR_DOWN_INVERTED); assertFalse(GeometricDoubleBondEncoderFactory.accept(atom, bonds)); }
@Test public void testAccept_CumulatedDoubleBond() throws Exception { IAtom atom = mock(IAtom.class); IBond a = mock(IBond.class); IBond b = mock(IBond.class); IBond c = mock(IBond.class); List<IBond> bonds = Arrays.asList(a, b, c); when(atom.getHybridization()).thenReturn(IAtomType.Hybridization.SP2); when(a.getOrder()).thenReturn(IBond.Order.DOUBLE); assertTrue(GeometricDoubleBondEncoderFactory.accept(atom, bonds)); when(b.getOrder()).thenReturn(IBond.Order.DOUBLE); assertFalse(GeometricDoubleBondEncoderFactory.accept(atom, bonds)); }
@Test public void testAccept_NoSubstituents() throws Exception { IAtom atom = mock(IAtom.class); IBond a = mock(IBond.class); List<IBond> bonds = Arrays.asList(a); when(atom.getHybridization()).thenReturn(IAtomType.Hybridization.SP2); when(a.getOrder()).thenReturn(IBond.Order.DOUBLE); assertFalse(GeometricDoubleBondEncoderFactory.accept(atom, bonds)); }