MoveLayerDownAction extends AbstractAction { void moveDown(Layer layer) { if (canMove(layer)) { final Layer parentLayer = layer.getParent(); final int layerIndex = parentLayer.getChildIndex(layer.getId()); parentLayer.getChildren().remove(layer); parentLayer.getChildren().add(layerIndex + 1, layer); } } MoveLayerDownAction(AppContext appContext); @Override void actionPerformed(ActionEvent e); boolean canMove(Layer layer);  }
@Test public void testMoveLayer2Down() { layerDownAction.moveDown(layer2); Assert.assertEquals(4, layer0.getChildren().size()); Assert.assertEquals(0, layer0.getChildIndex("layer1")); Assert.assertEquals(1, layer0.getChildIndex("layer3")); Assert.assertEquals(2, layer0.getChildIndex("layer2")); Assert.assertEquals(3, layer0.getChildIndex("layer6")); }
@Test public void testMoveLayer4Down() { layerDownAction.moveDown(layer4); Assert.assertEquals(2, layer3.getChildren().size()); Assert.assertEquals(0, layer3.getChildIndex("layer5")); Assert.assertEquals(1, layer3.getChildIndex("layer4")); }
@Test public void testMoveLayer6Down() { layerDownAction.moveDown(layer6); Assert.assertEquals(4, layer0.getChildren().size()); Assert.assertEquals(0, layer0.getChildIndex("layer1")); Assert.assertEquals(1, layer0.getChildIndex("layer2")); Assert.assertEquals(2, layer0.getChildIndex("layer3")); Assert.assertEquals(3, layer0.getChildIndex("layer6")); }