MoveLayerUpAction extends AbstractAction { void moveUp(Layer layer) { if (canMove(layer)) { final Layer parentLayer = layer.getParent(); final int layerIndex = layer.getParent().getChildIndex(layer.getId()); parentLayer.getChildren().remove(layer); parentLayer.getChildren().add(layerIndex - 1, layer); } } MoveLayerUpAction(AppContext appContext); @Override void actionPerformed(ActionEvent e); boolean canMove(Layer layer);  }
@Test public void testMoveLayer1Up() { layerUpAction.moveUp(layer1); Assert.assertEquals(4, layer0.getChildren().size()); Assert.assertEquals(0, layer0.getChildIndex("layer1")); }
@Test public void testMoveLayer3Up() { layerUpAction.moveUp(layer3); Assert.assertEquals(2, layer3.getChildren().size()); Assert.assertEquals(4, layer0.getChildren().size()); Assert.assertEquals(0, layer0.getChildIndex("layer1")); Assert.assertEquals(1, layer0.getChildIndex("layer3")); Assert.assertEquals(2, layer0.getChildIndex("layer2")); }
@Test public void testMoveLayer5Up() { layerUpAction.moveUp(layer5); Assert.assertEquals(2, layer3.getChildren().size()); Assert.assertEquals(0, layer3.getChildIndex("layer5")); Assert.assertEquals(1, layer3.getChildIndex("layer4")); }
@Test public void testMoveLayer6Up() { layerUpAction.moveUp(layer6); Assert.assertEquals(4, layer0.getChildren().size()); Assert.assertEquals(0, layer0.getChildIndex("layer1")); Assert.assertEquals(1, layer0.getChildIndex("layer2")); Assert.assertEquals(2, layer0.getChildIndex("layer6")); Assert.assertEquals(3, layer0.getChildIndex("layer3")); }