MoveLayerLeftAction extends AbstractAction { void moveLeft(Layer layer) { if (canMove(layer)) { Layer parentLayer = layer.getParent(); final Layer parentsParentLayer = parentLayer.getParent(); parentLayer.getChildren().remove(layer); final int parentIndex = parentsParentLayer.getChildIndex(parentLayer.getId()); if (parentIndex < parentsParentLayer.getChildren().size() - 1) { parentsParentLayer.getChildren().add(parentIndex + 1, layer); } else { parentsParentLayer.getChildren().add(layer); } } } MoveLayerLeftAction(AppContext appContext); @Override void actionPerformed(ActionEvent e); boolean canMove(Layer layer);  }
@Test public void testMoveLayer2Left() { layerLeftAction.moveLeft(layer2); 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")); }
@Test public void testMoveLayer4Left() { layerLeftAction.moveLeft(layer4); Assert.assertEquals(5, 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("layer4")); Assert.assertEquals(4, layer0.getChildIndex("layer6")); }
@Test public void testMoveLayer7Left() { layerLeftAction.moveLeft(layer7); Assert.assertEquals(5, 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")); Assert.assertEquals(4, layer0.getChildIndex("layer7")); }