diff --git a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/AbstractFigureTest.java b/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/AbstractFigureTest.java index 605d7f92b..71f6cdc03 100644 --- a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/AbstractFigureTest.java +++ b/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/AbstractFigureTest.java @@ -29,12 +29,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -/** - * Unit tests for AbstractFigure using JUnit 4 and AssertJ. - * Tests focus on core figure behavior, attribute management, and geometric operations. - * - * @author tw - */ public class AbstractFigureTest { @Mock diff --git a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/RectangleFigureTest.java b/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/RectangleFigureTest.java deleted file mode 100644 index aae6219ba..000000000 --- a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/RectangleFigureTest.java +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Copyright (C) 2015 JHotDraw. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package org.jhotdraw.draw.figure; - -import java.awt.Graphics2D; -import java.awt.geom.AffineTransform; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import org.junit.*; -import static org.assertj.core.api.Assertions.*; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import static org.mockito.Mockito.*; - -/** - * Comprehensive unit tests for RectangleFigure using JUnit 4, AssertJ, and Mockito. - * Tests focus on geometric operations, boundary conditions, and drawing behavior. - */ -public class RectangleFigureTest { - - @Mock - private Graphics2D mockGraphics; - - private RectangleFigure rectangle; - - @BeforeClass - public static void setUpClass() { - // Class-level setup if needed - } - - @AfterClass - public static void tearDownClass() { - // Class-level cleanup if needed - } - - @Before - public void setUp() { - MockitoAnnotations.openMocks(this); - rectangle = new RectangleFigure(); - } - - @After - public void tearDown() { - rectangle = null; - } - - // CONSTRUCTOR TESTS - - /** - * Test default constructor creates rectangle at origin with zero dimensions. - */ - @Test - public void testDefaultConstructor() { - RectangleFigure rect = new RectangleFigure(); - Rectangle2D.Double bounds = rect.getBounds(); - - assertThat(bounds.x).isZero(); - assertThat(bounds.y).isZero(); - assertThat(bounds.width).isZero(); - assertThat(bounds.height).isZero(); - } - - /** - * Test parameterized constructor sets dimensions correctly. - */ - @Test - public void testParameterizedConstructor() { - RectangleFigure rect = new RectangleFigure(10, 20, 100, 50); - Rectangle2D.Double bounds = rect.getBounds(); - - assertThat(bounds.x).isEqualTo(10.0); - assertThat(bounds.y).isEqualTo(20.0); - assertThat(bounds.width).isEqualTo(100.0); - assertThat(bounds.height).isEqualTo(50.0); - } - - // BOUNDARY TESTS - - /** - * Test setBounds with normal positive values. - */ - @Test - public void testSetBounds() { - Point2D.Double anchor = new Point2D.Double(10, 10); - Point2D.Double lead = new Point2D.Double(50, 30); - - rectangle.setBounds(anchor, lead); - Rectangle2D.Double bounds = rectangle.getBounds(); - - assertThat(bounds.x).isEqualTo(10.0); - assertThat(bounds.y).isEqualTo(10.0); - assertThat(bounds.width).isEqualTo(40.0); - assertThat(bounds.height).isEqualTo(20.0); - } - - /** - * Test setBounds with inverted anchor and lead points (lead before anchor). - */ - @Test - public void testSetBoundsInvertedPoints() { - Point2D.Double anchor = new Point2D.Double(50, 30); - Point2D.Double lead = new Point2D.Double(10, 10); - - rectangle.setBounds(anchor, lead); - Rectangle2D.Double bounds = rectangle.getBounds(); - - // Should normalize to proper rectangle - assertThat(bounds.x).isEqualTo(10.0); - assertThat(bounds.y).isEqualTo(10.0); - assertThat(bounds.width).isEqualTo(40.0); - assertThat(bounds.height).isEqualTo(20.0); - } - - /** - * Test setBounds with zero-width rectangle enforces minimum width. - */ - @Test - public void testSetBoundsZeroWidth() { - Point2D.Double anchor = new Point2D.Double(10, 10); - Point2D.Double lead = new Point2D.Double(10, 30); // Same x-coordinate - - rectangle.setBounds(anchor, lead); - Rectangle2D.Double bounds = rectangle.getBounds(); - - assertThat(bounds.width).isEqualTo(0.1); // Minimum width enforced - assertThat(bounds.height).isEqualTo(20.0); - } - - /** - * Test setBounds with zero-height rectangle enforces minimum height. - */ - @Test - public void testSetBoundsZeroHeight() { - Point2D.Double anchor = new Point2D.Double(10, 10); - Point2D.Double lead = new Point2D.Double(30, 10); // Same y-coordinate - - rectangle.setBounds(anchor, lead); - Rectangle2D.Double bounds = rectangle.getBounds(); - - assertThat(bounds.width).isEqualTo(20.0); - assertThat(bounds.height).isEqualTo(0.1); // Minimum height enforced - } - - // CONTAINMENT TESTS - - /** - * Test contains method for point inside rectangle. - */ - @Test - public void testContainsPointInside() { - RectangleFigure rect = new RectangleFigure(10, 10, 20, 15); - Point2D.Double insidePoint = new Point2D.Double(20, 17); - - assertThat(rect.contains(insidePoint)).isTrue(); - } - - /** - * Test contains method for point outside rectangle. - */ - @Test - public void testContainsPointOutside() { - RectangleFigure rect = new RectangleFigure(10, 10, 20, 15); - Point2D.Double outsidePoint = new Point2D.Double(5, 5); - - assertThat(rect.contains(outsidePoint)).isFalse(); - } - - /** - * Test contains method for point on rectangle boundary. - */ - @Test - public void testContainsPointOnBoundary() { - RectangleFigure rect = new RectangleFigure(10, 10, 20, 15); - Point2D.Double boundaryPoint = new Point2D.Double(10, 10); // Top-left corner - - // Due to hit growth, boundary points should be contained - assertThat(rect.contains(boundaryPoint)).isTrue(); - } - - // TRANSFORMATION TESTS - - /** - * Test transform with identity transformation. - */ - @Test - public void testTransformIdentity() { - RectangleFigure rect = new RectangleFigure(10, 10, 20, 15); - Rectangle2D.Double originalBounds = rect.getBounds(); - - AffineTransform identity = new AffineTransform(); - rect.transform(identity); - - Rectangle2D.Double newBounds = rect.getBounds(); - assertThat(newBounds).isEqualTo(originalBounds); - } - - /** - * Test transform with translation. - */ - @Test - public void testTransformTranslation() { - RectangleFigure rect = new RectangleFigure(10, 10, 20, 15); - - AffineTransform translation = AffineTransform.getTranslateInstance(5, -3); - rect.transform(translation); - - Rectangle2D.Double bounds = rect.getBounds(); - assertThat(bounds.x).isEqualTo(15.0); - assertThat(bounds.y).isEqualTo(7.0); - assertThat(bounds.width).isEqualTo(20.0); - assertThat(bounds.height).isEqualTo(15.0); - } - - /** - * Test transform with scaling. - */ - @Test - public void testTransformScaling() { - RectangleFigure rect = new RectangleFigure(10, 10, 20, 15); - - AffineTransform scaling = AffineTransform.getScaleInstance(2.0, 0.5); - rect.transform(scaling); - - Rectangle2D.Double bounds = rect.getBounds(); - assertThat(bounds.x).isEqualTo(20.0); - assertThat(bounds.y).isEqualTo(5.0); - assertThat(bounds.width).isEqualTo(40.0); - assertThat(bounds.height).isEqualTo(7.5); - } - - // DRAWING AREA TESTS - - /** - * Test that drawing area is larger than bounds due to stroke growth. - */ - @Test - public void testGetDrawingAreaLargerThanBounds() { - RectangleFigure rect = new RectangleFigure(10, 10, 20, 15); - - Rectangle2D.Double bounds = rect.getBounds(); - Rectangle2D.Double drawingArea = rect.getDrawingArea(); - - assertThat(drawingArea.width).isGreaterThan(bounds.width); - assertThat(drawingArea.height).isGreaterThan(bounds.height); - } - - // DRAWING BEHAVIOR TESTS (with mocking) - - /** - * Test that draw method calls appropriate Graphics2D methods. - * Note: This is a simplified test - in reality we'd need to set up proper attributes. - */ - @Test - public void testDrawCallsGraphicsMethods() { - RectangleFigure rect = new RectangleFigure(10, 10, 20, 15); - - // Create a real graphics context for testing - BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); - Graphics2D g2d = image.createGraphics(); - - // This should not throw any exceptions - assertThatCode(() -> rect.draw(g2d)).doesNotThrowAnyException(); - - g2d.dispose(); - } - - // EDGE CASES AND ERROR CONDITIONS - - /** - * Test drawing with null graphics context should throw NPE. - */ - @Test - public void testDrawWithNullGraphics() { - RectangleFigure rect = new RectangleFigure(10, 10, 20, 15); - - // Should throw NullPointerException - this is the correct behavior - assertThatThrownBy(() -> rect.draw(null)) - .isInstanceOf(NullPointerException.class); - } - - /** - * Test negative dimensions behavior. - */ - @Test - public void testNegativeDimensions() { - RectangleFigure rect = new RectangleFigure(10, 10, -20, -15); - Rectangle2D.Double bounds = rect.getBounds(); - - // Should handle negative dimensions appropriately - assertThat(bounds.width).isEqualTo(-20.0); // Current behavior - might need adjustment - assertThat(bounds.height).isEqualTo(-15.0); - } - - // JAVA ASSERTIONS FOR INVARIANTS - - /** - * Test invariant: bounds should never be null. - */ - @Test - public void testBoundsInvariant() { - assert rectangle.getBounds() != null : "Bounds should never be null"; - - rectangle.setBounds(new Point2D.Double(0, 0), new Point2D.Double(10, 10)); - assert rectangle.getBounds() != null : "Bounds should never be null after setBounds"; - - rectangle.transform(AffineTransform.getScaleInstance(2, 2)); - assert rectangle.getBounds() != null : "Bounds should never be null after transform"; - } - - /** - * Test invariant: drawing area should always contain bounds. - */ - @Test - public void testDrawingAreaContainsBoundsInvariant() { - RectangleFigure rect = new RectangleFigure(10, 10, 20, 15); - - Rectangle2D.Double bounds = rect.getBounds(); - Rectangle2D.Double drawingArea = rect.getDrawingArea(); - - assert drawingArea.contains(bounds) : "Drawing area should always contain bounds"; - } -} diff --git a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/bdd/GivenFigureCreation.java b/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/bdd/GivenFigureCreation.java deleted file mode 100644 index e75719eca..000000000 --- a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/bdd/GivenFigureCreation.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2015 JHotDraw. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package org.jhotdraw.draw.figure.bdd; - -import com.tngtech.jgiven.Stage; -import com.tngtech.jgiven.annotation.ScenarioState; -import com.tngtech.jgiven.annotation.ScenarioState.Resolution; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import org.jhotdraw.draw.figure.RectangleFigure; -import static org.assertj.core.api.Assertions.*; - -public class GivenFigureCreation extends Stage { - - @ScenarioState - protected RectangleFigure rectangle; - - @ScenarioState(resolution = Resolution.NAME) - protected Point2D.Double startPoint; - - @ScenarioState(resolution = Resolution.NAME) - protected Point2D.Double endPoint; - - public GivenFigureCreation a_new_rectangle_figure() { - rectangle = new RectangleFigure(); - return self(); - } - - public GivenFigureCreation a_rectangle_figure_with_dimensions(double x, double y, double width, double height) { - rectangle = new RectangleFigure(x, y, width, height); - return self(); - } - - public GivenFigureCreation an_existing_rectangle_at_position(double x, double y) { - rectangle = new RectangleFigure(x, y, 50, 30); // Default size - return self(); - } - - public GivenFigureCreation a_start_point_at(double x, double y) { - startPoint = new Point2D.Double(x, y); - return self(); - } - - public GivenFigureCreation an_end_point_at(double x, double y) { - endPoint = new Point2D.Double(x, y); - return self(); - } - - public GivenFigureCreation a_rectangle_with_zero_dimensions() { - rectangle = new RectangleFigure(10, 10, 0, 0); - return self(); - } -} diff --git a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/bdd/RectangleFigureBDDTest.java b/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/bdd/RectangleFigureBDDTest.java deleted file mode 100644 index f5d1f292a..000000000 --- a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/bdd/RectangleFigureBDDTest.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.jhotdraw.draw.figure.bdd; - -import com.tngtech.jgiven.junit.ScenarioTest; -import org.junit.Test; - -public class RectangleFigureBDDTest extends ScenarioTest { - - @Test - public void user_can_create_rectangle_by_dragging() { - given().a_new_rectangle_figure() - .and().a_start_point_at(10, 10) - .and().an_end_point_at(50, 40); - - when().the_user_creates_a_rectangle_by_dragging_from_start_to_end(); - - then().the_rectangle_should_have_position(10, 10) - .and().the_rectangle_should_have_dimensions(40, 30); - } - - @Test - public void user_can_resize_existing_rectangle() { - given().a_rectangle_figure_with_dimensions(10, 10, 50, 30); - - when().the_user_resizes_the_rectangle_to(100, 60); - - then().the_rectangle_should_have_dimensions(100, 60) - .and().the_rectangle_should_be_positioned_at(10, 10); - } - - @Test - public void user_can_move_rectangle_to_new_position() { - given().a_rectangle_figure_with_dimensions(10, 10, 50, 30); - - when().the_user_moves_the_figure_by(20, 15); - - then().the_rectangle_should_have_position(30, 25) - .and().the_rectangle_should_have_dimensions(50, 30); - } - - @Test - public void user_can_scale_rectangle_proportionally() { - given().a_rectangle_figure_with_dimensions(10, 10, 40, 20); - - when().the_user_scales_the_figure_by(2.0, 2.0); - - then().the_rectangle_should_maintain_aspect_ratio_after_uniform_scaling(40, 20, 2.0); - } - - @Test - public void rectangle_enforces_minimum_dimensions_when_dragging() { - given().a_new_rectangle_figure() - .and().a_start_point_at(10, 10) - .and().an_end_point_at(10, 10); // Same point - zero dimensions - - when().the_user_creates_a_rectangle_by_dragging_from_start_to_end(); - - then().the_rectangle_should_enforce_minimum_width(0.1) - .and().the_rectangle_should_enforce_minimum_height(0.1); - } - - @Test - public void rectangle_normalizes_bounds_when_dragging_backwards() { - given().a_new_rectangle_figure() - .and().a_start_point_at(50, 40) // Start from bottom-right - .and().an_end_point_at(10, 10); // End at top-left - - when().the_user_creates_a_rectangle_by_dragging_from_start_to_end(); - - then().the_rectangle_should_have_position(10, 10) // Should normalize to top-left - .and().the_rectangle_should_have_dimensions(40, 30) - .and().the_rectangle_should_be_normalized(); - } - - @Test - public void point_inside_rectangle_is_detected_correctly() { - given().a_rectangle_figure_with_dimensions(10, 10, 40, 30); - - when().checking_if_point_$_$_is_contained(25, 20); // Point inside - - then().the_point_should_be_contained(); - } - - @Test - public void point_outside_rectangle_is_detected_correctly() { - given().a_rectangle_figure_with_dimensions(10, 10, 40, 30); - - when().checking_if_point_$_$_is_contained(5, 5); // Point outside - - then().the_point_should_not_be_contained(); - } - - @Test - public void rectangle_drawing_area_accommodates_stroke_width() { - given().a_rectangle_figure_with_dimensions(10, 10, 40, 30); - - when().the_user_moves_the_figure_by(0, 0); // Trigger bounds calculation - - then().the_drawing_area_should_be_larger_than_bounds(); - } - - @Test - public void user_can_create_thin_horizontal_line() { - given().a_new_rectangle_figure() - .and().a_start_point_at(10, 20) - .and().an_end_point_at(50, 20); // Same y-coordinate - - when().the_user_creates_a_rectangle_by_dragging_from_start_to_end(); - - then().the_rectangle_should_have_position(10, 20) - .and().the_rectangle_should_have_dimensions(40, 0.1); // Minimum height enforced - } - - @Test - public void user_can_create_thin_vertical_line() { - given().a_new_rectangle_figure() - .and().a_start_point_at(15, 10) - .and().an_end_point_at(15, 40); // Same x-coordinate - - when().the_user_creates_a_rectangle_by_dragging_from_start_to_end(); - - then().the_rectangle_should_have_position(15, 10) - .and().the_rectangle_should_have_dimensions(0.1, 30); // Minimum width enforced - } -} diff --git a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/bdd/ThenFigureBehavior.java b/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/bdd/ThenFigureBehavior.java deleted file mode 100644 index f578300ef..000000000 --- a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/bdd/ThenFigureBehavior.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) 2015 JHotDraw. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package org.jhotdraw.draw.figure.bdd; - -import com.tngtech.jgiven.Stage; -import com.tngtech.jgiven.annotation.ScenarioState; -import com.tngtech.jgiven.annotation.ScenarioState.Resolution; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import org.jhotdraw.draw.figure.RectangleFigure; -import static org.assertj.core.api.Assertions.*; - -public class ThenFigureBehavior extends Stage { - - @ScenarioState - protected RectangleFigure rectangle; - - @ScenarioState - protected Rectangle2D.Double resultingBounds; - - @ScenarioState - protected boolean containmentResult; - - @ScenarioState(resolution = Resolution.NAME) - protected Point2D.Double testPoint; - - public ThenFigureBehavior the_rectangle_should_have_position(double x, double y) { - assertThat(resultingBounds.x).isEqualTo(x); - assertThat(resultingBounds.y).isEqualTo(y); - return self(); - } - - public ThenFigureBehavior the_rectangle_should_have_dimensions(double width, double height) { - assertThat(resultingBounds.width).isEqualTo(width); - assertThat(resultingBounds.height).isEqualTo(height); - return self(); - } - - public ThenFigureBehavior the_rectangle_should_be_positioned_at(double x, double y) { - Rectangle2D.Double bounds = rectangle.getBounds(); - assertThat(bounds.x).isEqualTo(x); - assertThat(bounds.y).isEqualTo(y); - return self(); - } - - public ThenFigureBehavior the_rectangle_should_have_size(double width, double height) { - Rectangle2D.Double bounds = rectangle.getBounds(); - assertThat(bounds.width).isEqualTo(width); - assertThat(bounds.height).isEqualTo(height); - return self(); - } - - public ThenFigureBehavior the_point_should_be_contained() { - assertThat(containmentResult).as("Point %s should be contained in rectangle", testPoint).isTrue(); - return self(); - } - - public ThenFigureBehavior the_point_should_not_be_contained() { - assertThat(containmentResult).as("Point %s should not be contained in rectangle", testPoint).isFalse(); - return self(); - } - - public ThenFigureBehavior the_rectangle_should_enforce_minimum_width(double minimumWidth) { - assertThat(resultingBounds.width).isGreaterThanOrEqualTo(minimumWidth); - return self(); - } - - public ThenFigureBehavior the_rectangle_should_enforce_minimum_height(double minimumHeight) { - assertThat(resultingBounds.height).isGreaterThanOrEqualTo(minimumHeight); - return self(); - } - - public ThenFigureBehavior the_rectangle_should_be_normalized() { - // A normalized rectangle should have positive width and height - assertThat(resultingBounds.width).isGreaterThanOrEqualTo(0); - assertThat(resultingBounds.height).isGreaterThanOrEqualTo(0); - return self(); - } - - public ThenFigureBehavior the_drawing_area_should_be_larger_than_bounds() { - Rectangle2D.Double bounds = rectangle.getBounds(); - Rectangle2D.Double drawingArea = rectangle.getDrawingArea(); - - assertThat(drawingArea.width).isGreaterThan(bounds.width); - assertThat(drawingArea.height).isGreaterThan(bounds.height); - return self(); - } - - public ThenFigureBehavior the_rectangle_should_maintain_aspect_ratio_after_uniform_scaling(double originalWidth, double originalHeight, double scaleFactor) { - double expectedWidth = originalWidth * scaleFactor; - double expectedHeight = originalHeight * scaleFactor; - - assertThat(resultingBounds.width).isCloseTo(expectedWidth, within(0.01)); - assertThat(resultingBounds.height).isCloseTo(expectedHeight, within(0.01)); - return self(); - } -} diff --git a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/bdd/WhenFigureManipulation.java b/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/bdd/WhenFigureManipulation.java deleted file mode 100644 index 9160d95ae..000000000 --- a/jhotdraw-core/src/test/java/org/jhotdraw/draw/figure/bdd/WhenFigureManipulation.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2015 JHotDraw. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package org.jhotdraw.draw.figure.bdd; - -import com.tngtech.jgiven.Stage; -import com.tngtech.jgiven.annotation.ScenarioState; -import com.tngtech.jgiven.annotation.ScenarioState.Resolution; -import java.awt.geom.AffineTransform; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import org.jhotdraw.draw.figure.RectangleFigure; - -public class WhenFigureManipulation extends Stage { - - @ScenarioState - protected RectangleFigure rectangle; - - @ScenarioState(resolution = Resolution.NAME) - protected Point2D.Double startPoint; - - @ScenarioState(resolution = Resolution.NAME) - protected Point2D.Double endPoint; - - @ScenarioState - protected Rectangle2D.Double resultingBounds; - - @ScenarioState - protected boolean containmentResult; - - @ScenarioState(resolution = Resolution.NAME) - protected Point2D.Double testPoint; - - public WhenFigureManipulation the_user_sets_bounds_from_start_to_end_point() { - rectangle.setBounds(startPoint, endPoint); - resultingBounds = rectangle.getBounds(); - return self(); - } - - public WhenFigureManipulation the_user_moves_the_figure_by(double deltaX, double deltaY) { - AffineTransform translation = AffineTransform.getTranslateInstance(deltaX, deltaY); - rectangle.transform(translation); - resultingBounds = rectangle.getBounds(); - return self(); - } - - public WhenFigureManipulation the_user_scales_the_figure_by(double scaleX, double scaleY) { - AffineTransform scaling = AffineTransform.getScaleInstance(scaleX, scaleY); - rectangle.transform(scaling); - resultingBounds = rectangle.getBounds(); - return self(); - } - - public WhenFigureManipulation checking_if_point_$_$_is_contained(double x, double y) { - testPoint = new Point2D.Double(x, y); - containmentResult = rectangle.contains(testPoint); - return self(); - } - - public WhenFigureManipulation the_user_resizes_the_rectangle_to(double width, double height) { - Rectangle2D.Double currentBounds = rectangle.getBounds(); - Point2D.Double anchor = new Point2D.Double(currentBounds.x, currentBounds.y); - Point2D.Double lead = new Point2D.Double(currentBounds.x + width, currentBounds.y + height); - rectangle.setBounds(anchor, lead); - resultingBounds = rectangle.getBounds(); - return self(); - } - - public WhenFigureManipulation the_user_creates_a_rectangle_by_dragging_from_start_to_end() { - rectangle.setBounds(startPoint, endPoint); - resultingBounds = rectangle.getBounds(); - return self(); - } -}