/*
   * Test method for 'br.org.archimedes.model.commands.MoveElementCommand.undoIt(Drawing)'
   */
  @Test
  public void testUndoIt() throws Exception {
    Selection selection = createOriginalSelection();
    UndoableCommand moveElement = new MoveCommand(getPoints(selection), vector);

    try {
      moveElement.undoIt(null);
      Assert.fail("Should throw a NullArgumentException");
    } catch (IllegalActionException e) {
      Assert.fail("Should not throw any exception");
    } catch (NullArgumentException e) {
    }

    try {
      moveElement.undoIt(drawing);
      Assert.fail("Should throw an IllegalActionException");
    } catch (IllegalActionException e) {
    } catch (NullArgumentException e) {
      Assert.fail("Should throw an IllegalActionException");
    }

    addsSelectionToDrawing(selection);
    moveElement.doIt(drawing);
    moveElement.undoIt(drawing);

    Collection<Element> expected = createOriginalSelection().getSelectedElements();
    assertCollectionTheSame(expected, selection.getSelectedElements());

    selection = createOriginalSelection();
    drawing.addLayer(new Layer(Constant.BLACK, "Layer2", LineStyle.CONTINUOUS, 1.0));
    drawing.setCurrentLayer(1);
    addsSelectionToDrawing(selection);

    moveElement = new MoveCommand(getPoints(selection), vector);
    moveElement.doIt(drawing);
    moveElement.doIt(drawing);
    moveElement.undoIt(drawing);

    expected = createOriginalExpected();
    assertCollectionTheSame(expected, selection.getSelectedElements());
  }
  /*
   * Test method for 'br.org.archimedes.model.commands.MoveElementCommand.doIt(Drawing)'
   */
  @Test
  public void testDoIt() throws Exception {

    Selection selection = createOriginalSelection();
    Command moveElement = new MoveCommand(getPoints(selection), vector);

    try {
      moveElement.doIt(drawing);
      Assert.fail("Should throw an IllegalActionException since nothing is on the drawing");
    } catch (IllegalActionException e) {
    } catch (NullArgumentException e) {
      Assert.fail("Should not throw a NullArgumentException");
    }

    addsSelectionToDrawing(selection);
    moveElement.doIt(drawing);
    Collection<Element> expected = createOriginalExpected();
    assertCollectionTheSame(expected, selection.getSelectedElements());

    removesSelectionToDrawing(selection);

    try {
      moveElement.doIt(drawing);
      Assert.fail("Should throw an IllegalActionException");
    } catch (IllegalActionException e) {
    } catch (NullArgumentException e) {
      Assert.fail("Should not throw a NullArgumentException");
    }

    addsSelectionToDrawing(selection);
    drawing.removeElement(circle);

    try {
      moveElement.doIt(drawing);
      Assert.fail("Should throw an IllegalActionException");
    } catch (IllegalActionException e) {
      // Should throw an exception for the circle
    } catch (NullArgumentException e) {
      Assert.fail("Should not throw a NullArgumentException");
    }

    expected = new ArrayList<Element>();
    expected.add(new Line(20, 20, 120, 120));
    expected.add(new InfiniteLine(30, 30, 70, 70));
    expected.add(new Semiline(30, 10, 70, 70));
    expected.add(circle);
    expected.add(new Arc(new Point(-80, 20), new Point(20, 120), new Point(120, 20)));

    assertCollectionTheSame(expected, selection.getSelectedElements());
  }
  /**
   * Removes the selection from the drawing.
   *
   * @param selection The selection to remove
   */
  private void removesSelectionToDrawing(Selection selection) throws Exception {

    for (Element element : selection.getSelectedElements()) {
      drawing.removeElement(element);
    }
  }
  /**
   * Adds the selection to the drawing.
   *
   * @param selection The selection to add
   */
  private void addsSelectionToDrawing(Selection selection) throws Exception {

    for (Element element : selection.getSelectedElements()) {
      drawing.putElement(element, drawing.getCurrentLayer());
    }
  }