@Test public void testConnectMagnetsByLocation() { IControlHandleList headControlHandleList = new ControlHandleList(mock(Shape.class)); WiresMagnet headMagnet1 = mock(WiresMagnet.class); when(headMagnet1.getX()).thenReturn(10d); when(headMagnet1.getY()).thenReturn(20d); when(headMagnet1.getIndex()).thenReturn(0); IPrimitive ch1 = mock(IPrimitive.class); when(ch1.getLocation()).thenReturn(new Point2D(10d, 20d)); when(headMagnet1.getControl()).thenReturn(ch1); WiresMagnet headMagnet2 = mock(WiresMagnet.class); when(headMagnet2.getX()).thenReturn(100d); when(headMagnet2.getY()).thenReturn(200d); IPrimitive ch2 = mock(IPrimitive.class); when(ch2.getLocation()).thenReturn(new Point2D(100d, 200d)); when(headMagnet2.getControl()).thenReturn(ch2); headControlHandleList.add(headMagnet1); headControlHandleList.add(headMagnet2); MagnetManager.Magnets headMagnets = mock(MagnetManager.Magnets.class); when(headMagnets.getMagnets()).thenReturn(headControlHandleList); Point2D headAbs = new Point2D(0, 0); MagnetConnection headConnection = MagnetConnection.Builder.at(10, 20); IControlHandleList tailControlHandleList = new ControlHandleList(mock(Shape.class)); WiresMagnet tailMagnet1 = mock(WiresMagnet.class); when(tailMagnet1.getX()).thenReturn(10d); when(tailMagnet1.getY()).thenReturn(20d); IPrimitive th1 = mock(IPrimitive.class); when(th1.getLocation()).thenReturn(new Point2D(10d, 20d)); when(tailMagnet1.getControl()).thenReturn(th1); WiresMagnet tailMagnet2 = mock(WiresMagnet.class); when(tailMagnet2.getX()).thenReturn(100d); when(tailMagnet2.getY()).thenReturn(200d); when(tailMagnet2.getIndex()).thenReturn(2); IPrimitive th2 = mock(IPrimitive.class); when(th2.getLocation()).thenReturn(new Point2D(100d, 200d)); when(tailMagnet2.getControl()).thenReturn(th2); tailControlHandleList.add(tailMagnet1); tailControlHandleList.add(tailMagnet2); MagnetManager.Magnets tailMagnets = mock(MagnetManager.Magnets.class); when(tailMagnets.getMagnets()).thenReturn(tailControlHandleList); Point2D tailAbs = new Point2D(0, 0); MagnetConnection tailConnection = MagnetConnection.Builder.at(100, 200); WiresConnection headWiresConnection = mock(WiresConnection.class); WiresConnection tailWiresConnection = mock(WiresConnection.class); tested.setHeadConnection(headWiresConnection); tested.setTailConnection(tailWiresConnection); tested.connect(headMagnets, headAbs, headConnection, tailMagnets, tailAbs, tailConnection); verify(headWiresConnection, never()).setXOffset(anyDouble()); verify(headWiresConnection, never()).setYOffset(anyDouble()); verify(headWiresConnection, times(1)).setAutoConnection(eq(false)); verify(headWiresConnection, times(1)).setMagnet(eq(headMagnet1)); verify(tailWiresConnection, times(1)).setXOffset(eq(0d)); verify(tailWiresConnection, times(1)).setYOffset(eq(0d)); verify(tailWiresConnection, times(1)).setAutoConnection(eq(false)); verify(tailWiresConnection, times(1)).setMagnet(eq(tailMagnet2)); }
@SuppressWarnings("unchecked") public T connect(final ShapeView headShapeView, final Connection headConnection, final ShapeView tailShapeView, final Connection tailConnection) { final Optional<WiresShape> headWiresShape = Optional.ofNullable((WiresShape) headShapeView); final Optional<WiresShape> tailWiresShape = Optional.ofNullable((WiresShape) tailShapeView); return connect(headWiresShape.map(WiresShape::getMagnets).orElse(null), headWiresShape.map(s -> s.getGroup().getComputedLocation()).orElse(null), headConnection, tailWiresShape.map(WiresShape::getMagnets).orElse(null), tailWiresShape.map(s -> s.getGroup().getComputedLocation()).orElse(null), tailConnection); }
WiresConnectorView extends WiresConnector implements
        LienzoShapeView<T>,
        IsConnector<T>,
        HasManageableControlPoints<T> { @SuppressWarnings("unchecked") public T connect(final ShapeView headShapeView, final Connection headConnection, final ShapeView tailShapeView, final Connection tailConnection) { final Optional<WiresShape> headWiresShape = Optional.ofNullable((WiresShape) headShapeView); final Optional<WiresShape> tailWiresShape = Optional.ofNullable((WiresShape) tailShapeView); return connect(headWiresShape.map(WiresShape::getMagnets).orElse(null), headWiresShape.map(s -> s.getGroup().getComputedLocation()).orElse(null), headConnection, tailWiresShape.map(WiresShape::getMagnets).orElse(null), tailWiresShape.map(s -> s.getGroup().getComputedLocation()).orElse(null), tailConnection); } }
WiresConnectorView extends WiresConnector implements
        LienzoShapeView<T>,
        IsConnector<T>,
        HasManageableControlPoints<T> { @SuppressWarnings("unchecked") public T connect(final ShapeView headShapeView, final Connection headConnection, final ShapeView tailShapeView, final Connection tailConnection) { final Optional<WiresShape> headWiresShape = Optional.ofNullable((WiresShape) headShapeView); final Optional<WiresShape> tailWiresShape = Optional.ofNullable((WiresShape) tailShapeView); return connect(headWiresShape.map(WiresShape::getMagnets).orElse(null), headWiresShape.map(s -> s.getGroup().getComputedLocation()).orElse(null), headConnection, tailWiresShape.map(WiresShape::getMagnets).orElse(null), tailWiresShape.map(s -> s.getGroup().getComputedLocation()).orElse(null), tailConnection); } WiresConnectorView(final AbstractDirectionalMultiPointShape<?> line,
                              final MultiPathDecorator headDecorator,
                              final MultiPathDecorator tailDecorator);  WiresConnectorView(final WiresMagnet headMagnet,
                              final WiresMagnet tailMagnet,
                              final AbstractDirectionalMultiPointShape<?> line,
                              final MultiPathDecorator headDecorator,
                              final MultiPathDecorator tailDecorator); }
WiresConnectorView extends WiresConnector implements
        LienzoShapeView<T>,
        IsConnector<T>,
        HasManageableControlPoints<T> { @SuppressWarnings("unchecked") public T connect(final ShapeView headShapeView, final Connection headConnection, final ShapeView tailShapeView, final Connection tailConnection) { final Optional<WiresShape> headWiresShape = Optional.ofNullable((WiresShape) headShapeView); final Optional<WiresShape> tailWiresShape = Optional.ofNullable((WiresShape) tailShapeView); return connect(headWiresShape.map(WiresShape::getMagnets).orElse(null), headWiresShape.map(s -> s.getGroup().getComputedLocation()).orElse(null), headConnection, tailWiresShape.map(WiresShape::getMagnets).orElse(null), tailWiresShape.map(s -> s.getGroup().getComputedLocation()).orElse(null), tailConnection); } WiresConnectorView(final AbstractDirectionalMultiPointShape<?> line,
                              final MultiPathDecorator headDecorator,
                              final MultiPathDecorator tailDecorator);  WiresConnectorView(final WiresMagnet headMagnet,
                              final WiresMagnet tailMagnet,
                              final AbstractDirectionalMultiPointShape<?> line,
                              final MultiPathDecorator headDecorator,
                              final MultiPathDecorator tailDecorator); @Override @SuppressWarnings("unchecked") T setUUID(final String uuid); @Override String getUUID(); T setListening(final boolean listening); @Override ControlPoint[] getManageableControlPoints(); @Override T addControlPoint(final ControlPoint controlPoint,
                             final int index); @Override T updateControlPoints(final ControlPoint[] controlPoints); @Override T deleteControlPoint(final int index); @SuppressWarnings("unchecked") T connect(final ShapeView headShapeView,
                     final Connection headConnection,
                     final ShapeView tailShapeView,
                     final Connection tailConnection); @Override double getShapeX(); @Override double getShapeY(); @Override T setShapeLocation(final Point2D location); @Override double getAlpha(); @Override @SuppressWarnings("unchecked") T setAlpha(final double alpha); @Override Point2D getShapeAbsoluteLocation(); @Override String getFillColor(); @Override @SuppressWarnings("unchecked") T setFillColor(final String color); @Override double getFillAlpha(); @Override @SuppressWarnings("unchecked") T setFillAlpha(final double alpha); @Override String getStrokeColor(); @Override @SuppressWarnings("unchecked") T setStrokeColor(final String color); @Override double getStrokeAlpha(); @Override @SuppressWarnings("unchecked") T setStrokeAlpha(final double alpha); @Override double getStrokeWidth(); @Override @SuppressWarnings("unchecked") T setStrokeWidth(final double width); @Override T setDragEnabled(boolean draggable); @Override @SuppressWarnings("unchecked") T moveToTop(); @Override @SuppressWarnings("unchecked") T moveToBottom(); @Override @SuppressWarnings("unchecked") T moveUp(); @Override @SuppressWarnings("unchecked") T moveDown(); @Override @SuppressWarnings("unchecked") T showControlPoints(final ControlPointType type); @Override @SuppressWarnings("unchecked") T hideControlPoints(); @Override boolean areControlsVisible(); @Override List<Shape<?>> getDecorators(); @Override BoundingBox getBoundingBox(); @Override void removeFromParent(); @Override T setShadow(final String color,
                       final int blur,
                       final double offx,
                       final double offy); @Override T removeShadow(); T setDashArray(DashArray dashArray); @Override Object getUserData(); @Override void setUserData(Object userData); }
WiresConnectorView extends WiresConnector implements
        LienzoShapeView<T>,
        IsConnector<T>,
        HasManageableControlPoints<T> { @SuppressWarnings("unchecked") public T connect(final ShapeView headShapeView, final Connection headConnection, final ShapeView tailShapeView, final Connection tailConnection) { final Optional<WiresShape> headWiresShape = Optional.ofNullable((WiresShape) headShapeView); final Optional<WiresShape> tailWiresShape = Optional.ofNullable((WiresShape) tailShapeView); return connect(headWiresShape.map(WiresShape::getMagnets).orElse(null), headWiresShape.map(s -> s.getGroup().getComputedLocation()).orElse(null), headConnection, tailWiresShape.map(WiresShape::getMagnets).orElse(null), tailWiresShape.map(s -> s.getGroup().getComputedLocation()).orElse(null), tailConnection); } WiresConnectorView(final AbstractDirectionalMultiPointShape<?> line,
                              final MultiPathDecorator headDecorator,
                              final MultiPathDecorator tailDecorator);  WiresConnectorView(final WiresMagnet headMagnet,
                              final WiresMagnet tailMagnet,
                              final AbstractDirectionalMultiPointShape<?> line,
                              final MultiPathDecorator headDecorator,
                              final MultiPathDecorator tailDecorator); @Override @SuppressWarnings("unchecked") T setUUID(final String uuid); @Override String getUUID(); T setListening(final boolean listening); @Override ControlPoint[] getManageableControlPoints(); @Override T addControlPoint(final ControlPoint controlPoint,
                             final int index); @Override T updateControlPoints(final ControlPoint[] controlPoints); @Override T deleteControlPoint(final int index); @SuppressWarnings("unchecked") T connect(final ShapeView headShapeView,
                     final Connection headConnection,
                     final ShapeView tailShapeView,
                     final Connection tailConnection); @Override double getShapeX(); @Override double getShapeY(); @Override T setShapeLocation(final Point2D location); @Override double getAlpha(); @Override @SuppressWarnings("unchecked") T setAlpha(final double alpha); @Override Point2D getShapeAbsoluteLocation(); @Override String getFillColor(); @Override @SuppressWarnings("unchecked") T setFillColor(final String color); @Override double getFillAlpha(); @Override @SuppressWarnings("unchecked") T setFillAlpha(final double alpha); @Override String getStrokeColor(); @Override @SuppressWarnings("unchecked") T setStrokeColor(final String color); @Override double getStrokeAlpha(); @Override @SuppressWarnings("unchecked") T setStrokeAlpha(final double alpha); @Override double getStrokeWidth(); @Override @SuppressWarnings("unchecked") T setStrokeWidth(final double width); @Override T setDragEnabled(boolean draggable); @Override @SuppressWarnings("unchecked") T moveToTop(); @Override @SuppressWarnings("unchecked") T moveToBottom(); @Override @SuppressWarnings("unchecked") T moveUp(); @Override @SuppressWarnings("unchecked") T moveDown(); @Override @SuppressWarnings("unchecked") T showControlPoints(final ControlPointType type); @Override @SuppressWarnings("unchecked") T hideControlPoints(); @Override boolean areControlsVisible(); @Override List<Shape<?>> getDecorators(); @Override BoundingBox getBoundingBox(); @Override void removeFromParent(); @Override T setShadow(final String color,
                       final int blur,
                       final double offx,
                       final double offy); @Override T removeShadow(); T setDashArray(DashArray dashArray); @Override Object getUserData(); @Override void setUserData(Object userData);  }