/* * 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); } }