MoveLayerRightAction extends AbstractAction { void moveRight(Layer layer) { if (canMove(layer)) { final Layer parentLayer = layer.getParent(); final int layerIndex = parentLayer.getChildIndex(layer.getId()); final Layer targetLayer = parentLayer.getChildren().get(layerIndex - 1); parentLayer.getChildren().remove(layer); targetLayer.getChildren().add(layer); } } MoveLayerRightAction(AppContext appContext); @Override void actionPerformed(ActionEvent e); boolean canMove(Layer layer);  }
@Test public void testMoveLayer1Right() { layerRightAction.moveRight(layer1); Assert.assertEquals(4, layer0.getChildren().size()); Assert.assertEquals(0, layer0.getChildIndex("layer1")); }
@Test public void testMoveLayer2Right() { layerRightAction.moveRight(layer2); Assert.assertEquals(3, layer0.getChildren().size()); Assert.assertEquals(0, layer1.getChildIndex("layer2")); }
@Test public void testMoveLayer3Right() { layerRightAction.moveRight(layer3); Assert.assertEquals(3, layer0.getChildren().size()); Assert.assertSame(layer1, layer0.getChildren().get(0)); Assert.assertSame(layer2, layer0.getChildren().get(1)); Assert.assertSame(layer6, layer0.getChildren().get(2)); Assert.assertEquals(1, layer2.getChildren().size()); Assert.assertSame(layer3, layer2.getChildren().get(0)); Assert.assertEquals(0, layer2.getChildIndex("layer3")); Assert.assertSame(layer7, layer6.getChildren().get(0)); }
@Test public void testMoveLayer4Right() { layerRightAction.moveRight(layer4); Assert.assertEquals(4, layer0.getChildren().size()); Assert.assertEquals(2, layer3.getChildren().size()); Assert.assertEquals(2, layer0.getChildIndex("layer3")); }
@Test public void testMoveLayer6Right() { layerRightAction.moveRight(layer6); Assert.assertEquals(3, layer0.getChildren().size()); Assert.assertEquals(3, layer3.getChildren().size()); Assert.assertEquals(0, layer3.getChildIndex("layer4")); Assert.assertEquals(1, layer3.getChildIndex("layer5")); Assert.assertEquals(2, layer3.getChildIndex("layer6")); }