### Question:
CaseManagementShapeView extends SVGShapeViewImpl implements HasSize<SVGShapeViewImpl> { public void addShape(final WiresShape shape, final int targetIndex) { if (shape == null || (targetIndex < 0 || targetIndex > getChildShapes().size())) { return; } final List<WiresShape> childShapes = getChildShapes().toList(); childShapes.forEach(WiresShape::removeFromParent); final List<WiresShape> existingChildShapes = childShapes.stream() .filter(s -> !((WiresShapeView) s).getUUID().equals(((WiresShapeView) shape).getUUID())) .collect(Collectors.toList()); existingChildShapes.add(targetIndex, shape); existingChildShapes.forEach(this::add); } CaseManagementShapeView(final String name,
                                   final SVGPrimitiveShape svgPrimitive,
                                   final double width,
                                   final double height,
                                   final boolean resizable);  CaseManagementShapeView(final String name,
                                   final SVGPrimitiveShape svgPrimitive,
                                   final double width,
                                   final double height,
                                   final boolean resizable,
                                   final Optional<MultiPath> optDropZone); void setLabel(String shapeLabel); double getWidth(); double getHeight(); void logicallyReplace(final CaseManagementShapeView original, final CaseManagementShapeView replacement); void addShape(final WiresShape shape, final int targetIndex); int getIndex(final WiresShape shape); Optional<MultiPath> getDropZone(); CaseManagementShapeView getGhost(); void setCanvas(CaseManagementCanvas canvas);  }### Answer:
@Test public void checkAddShapeAtIndex0WithNoExistingChildren() { final CaseManagementShapeView child = createShapeView("child"); shape.addShape(child, 0); verify(layoutHandler, times(1)).requestLayout(shape); assertEquals(1, shape.getChildShapes().size()); assertEquals(child, shape.getChildShapes().get(0)); }
@Test public void checkAddShapeAtIndex1WithNoExistingChildren() { final CaseManagementShapeView child = createShapeView("child"); shape.addShape(child, 1); verify(layoutHandler, never()).requestLayout(shape); assertEquals(0, shape.getChildShapes().size()); }
@Test public void checkAddShapeAtNegativeIndexWithNoExistingChildren() { final CaseManagementShapeView child = createShapeView("child"); shape.addShape(child, -1); verify(layoutHandler, never()).requestLayout(shape); assertEquals(0, shape.getChildShapes().size()); }
@Test public void testAddShape() throws Exception { final CaseManagementShapeView child1 = createShapeView("child1"); final CaseManagementShapeView child2 = createShapeView("child2"); final CaseManagementShapeView child3 = createShapeView("child2"); { shape.addShape(child1, 0); verify(shape, times(1)).add(child1); verify(layoutHandler, times(1)).requestLayout(shape); assertEquals(1, shape.getChildShapes().size()); } { reset(shape); reset(layoutHandler); shape.addShape(child2, 0); final ArgumentCaptor<WiresShape> childShapes = ArgumentCaptor.forClass(WiresShape.class); verify(shape, times(2)).add(childShapes.capture()); assertTrue(childShapes.getAllValues().containsAll(Lists.newArrayList(child1, child2))); verify(layoutHandler, atLeast(2)).requestLayout(shape); assertEquals(2, shape.getChildShapes().size()); } { reset(shape); reset(layoutHandler); shape.addShape(child3, 1); final ArgumentCaptor<WiresShape> childShapes = ArgumentCaptor.forClass(WiresShape.class); verify(shape, times(3)).add(childShapes.capture()); assertTrue(childShapes.getAllValues().containsAll(Lists.newArrayList(child1, child2, child3))); verify(layoutHandler, atLeast(3)).requestLayout(shape); assertEquals(3, shape.getChildShapes().size()); } assertEquals(shape.getIndex(child1), 2); assertEquals(shape.getIndex(child2), 0); assertEquals(shape.getIndex(child3), 1); }