Revision: 1036
Author: heuermh
Date: Wed Aug 4 15:04:12 2010
Log: unit test refactoring
http://code.google.com/p/piccolo2d/source/detail?r=1036
Added:
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/AbstractPPathTest.java
Deleted:
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathTest.java
Modified:
/piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PPath.java
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/AbstractPShapeTest.java
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PAreaTest.java
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathDoubleTest.java
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathFloatTest.java
=======================================
--- /dev/null
+++
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/AbstractPPathTest.java
Wed Aug 4 15:04:12 2010
@@ -0,0 +1,480 @@
+/*
+ * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
+ * Copyright (c) 1998-2008, University of Maryland
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
this list of conditions
+ * and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other
materials provided with the
+ * distribution.
+ *
+ * None of the name of the University of Maryland, the name of the
Piccolo2D project, or the names of its
+ * contributors may be used to endorse or promote products derived from
this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.piccolo2d.nodes;
+
+import java.awt.Color;
+import java.awt.Shape;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Arc2D;
+import java.awt.geom.PathIterator;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
+import org.piccolo2d.MockPropertyChangeListener;
+import org.piccolo2d.PiccoloAsserts;
+
+import org.piccolo2d.nodes.PPath;
+
+import org.piccolo2d.util.PBounds;
+import org.piccolo2d.util.PObjectOutputStream;
+
+/**
+ * Abstract unit test for subclasses of PPath.
+ */
+public abstract class AbstractPPathTest extends AbstractPShapeTest {
+
+ private static final double TOLERANCE = 0.0001d;
+ private static final double LOW_TOLERANCE = 1.0d;
+
+ private MockPropertyChangeListener mockListener;
+
+ /** {...@inheritdoc} */
+ protected PShape createShapeNode() {
+ return createPathNode();
+ }
+
+ /**
+ * Create a new instance of a subclass of PPath to test.
+ *
+ * @return a new instance of a subclass of PPath to test
+ */
+ protected abstract PPath createPathNode();
+
+ /** {...@inheritdoc} */
+ protected void setUp() {
+ super.setUp();
+ mockListener = new MockPropertyChangeListener();
+ }
+
+ // todo: rewrite in terms of createPathNode()
+
+ public void testClone() {
+ PPath p = PPath.createEllipse(0, 0, 100, 100);
+ PPath cloned = (PPath) p.clone();
+ assertEquals(p.getBounds(), cloned.getBounds());
+ //assertEquals(p.getPathReference()., cloned.getPathReference());
+ }
+
+ public void testSerialization() throws IOException,
ClassNotFoundException {
+ final PPath srcPath = PPath.createEllipse(0, 0, 100, 100);
+ final PBounds srcBounds = srcPath.getBounds();
+
+ final File file = File.createTempFile("test", "ser");
+
+ serializeToFile(srcPath, file);
+ final PPath resultPath = deserializeFromFile(srcBounds, file);
+ file.deleteOnExit();
+
+ assertEquals(resultPath.getBounds(), srcBounds);
+ }
+
+ private PPath deserializeFromFile(final PBounds b, final File file)
throws FileNotFoundException, IOException,
+ ClassNotFoundException {
+ PPath path;
+ final FileInputStream fin = new FileInputStream(file);
+ final ObjectInputStream in = new ObjectInputStream(fin);
+ path = (PPath) in.readObject();
+
+ return path;
+ }
+
+ private void serializeToFile(final PPath p, final File file) throws
FileNotFoundException, IOException {
+ final FileOutputStream fout = new FileOutputStream(file);
+ final PObjectOutputStream out = new PObjectOutputStream(fout);
+ out.writeObjectTree(p);
+ out.flush();
+ out.close();
+ }
+
+ public void testCreateRectangleReturnsValidPPath() {
+ final PPath path = PPath.createRectangle(0, 0, 100, 50);
+ assertNotNull(path);
+
+ // Seems like rounding is affecting the bounds greatly
+ PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 50),
path.getBounds(), 2.0d);
+ }
+
+ public void testCreateEllipseReturnsValidPPath() {
+ final PPath path = PPath.createEllipse(0, 0, 100, 50);
+ assertNotNull(path);
+
+ // Seems like rounding is affecting the bounds greatly
+ PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 50),
path.getBounds(), 2.0d);
+ }
+
+ public void testCreateRoundedRectReturnsValidPPath() {
+ final PPath path = PPath.createRoundRectangle(0, 0, 100, 50, 10,
10);
+ assertNotNull(path);
+
+ // Seems like rounding is affecting the bounds greatly
+ PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 50),
path.getBounds(), 2.0d);
+ }
+
+ public void testCreateLineReturnsValidPPath() {
+ final PPath path = PPath.createLine(0, 0, 100, 0);
+ assertNotNull(path);
+
+ // Seems like rounding is affecting the bounds greatly
+ PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 0),
path.getBounds(), 2.0d);
+ }
+
+ /*
+ public void testCreatePolyLinePoint2DReturnsValidPPath() {
+ final PPath path = PPath.createPolyline(new Point2D[] { new
Point2D.Double(0, 0), new Point2D.Double(100, 50),
+ new Point2D.Double(100, 0) });
+ assertNotNull(path);
+
+ // Seems like rounding is affecting the bounds greatly
+ PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 50),
path.getBounds(), 2.0d);
+ }
+
+ public void testCreatePolyLineFloatsReturnsValidPPath() {
+ final PPath path = PPath.createPolyline(new float[] { 0, 100, 100
}, new float[] { 0, 50, 0 });
+ assertNotNull(path);
+
+ // Seems like rounding is affecting the bounds greatly
+ PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 50),
path.getBounds(), 2.0d);
+ }
+ */
+
+ // todo: replace with commented out test methods below
+ public void testChangingPathFiresPropertyChangeEvent() {
+ final PPath path = new PPath.Double();
+ path.addPropertyChangeListener("path", mockListener);
+ path.append(new Rectangle2D.Double(0, 0, 100, 50), true);
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+
+ public void testCreateArcFloat() {
+ assertNotNull(PPath.createArc(0.0f, 0.0f, 50.0f, 100.0f, 25.0f,
75.0f, Arc2D.OPEN));
+ }
+
+ public void testCreateCubicCurveFloat() {
+ assertNotNull(PPath.createCubicCurve(0.0f, 0.0f, 25.0f, 75.0f,
75.0f, 25.0f, 50.0f, 100.0f));
+ }
+
+ public void testCreateEllipseFloat() {
+ assertNotNull(PPath.createEllipse(0.0f, 0.0f, 50.0f, 100.0f));
+ }
+
+ public void testCreateLineFloat() {
+ assertNotNull(PPath.createLine(0.0f, 0.0f, 50.0f, 100.0f));
+ }
+
+ public void testCreateQuadCurveFloat() {
+ assertNotNull(PPath.createQuadCurve(0.0f, 0.0f, 25.0f, 75.0f,
50.0f, 100.0f));
+ }
+
+ public void testCreateRectangleFloat() {
+ assertNotNull(PPath.createRectangle(0.0f, 0.0f, 50.0f, 100.0f));
+ }
+
+ public void testCreateRoundRectangleFloat() {
+ assertNotNull(PPath.createRoundRectangle(0.0f, 0.0f, 50.0f,
100.0f, 4.0f, 8.0f));
+ }
+
+ public void testCreateArcDouble() {
+ assertNotNull(PPath.createArc(0.0d, 0.0d, 50.0d, 100.0d, 25.0d,
75.0d, Arc2D.OPEN));
+ }
+
+ public void testCreateCubicCurveDouble() {
+ assertNotNull(PPath.createCubicCurve(0.0d, 0.0d, 25.0d, 75.0d,
75.0d, 25.0d, 50.0d, 100.0d));
+ }
+
+ public void testCreateEllipseDouble() {
+ assertNotNull(PPath.createEllipse(0.0d, 0.0d, 50.0d, 100.0d));
+ }
+
+ public void testCreateLineDouble() {
+ assertNotNull(PPath.createLine(0.0d, 0.0d, 50.0d, 100.0d));
+ }
+
+ public void testCreateQuadCurveDouble() {
+ assertNotNull(PPath.createQuadCurve(0.0d, 0.0d, 25.0d, 75.0d,
50.0d, 100.0d));
+ }
+
+ public void testCreateRectangleDouble() {
+ assertNotNull(PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d));
+ }
+
+ public void testCreateRoundRectangleDouble() {
+ assertNotNull(PPath.createRoundRectangle(0.0d, 0.0d, 50.0d,
100.0d, 4.0d, 8.0d));
+ }
+
+ public void testAppendShape() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ Rectangle2D rect = new Rectangle2D.Double(50.0d, 100.0d, 50.0d,
100.0d);
+ path.append(rect, true);
+ // todo: shouldn't this be width + 2 * strokeWidth?
+ assertEquals(101.0d, path.getWidth(), TOLERANCE);
+ assertEquals(201.0d, path.getHeight(), TOLERANCE);
+ }
+
+ public void testAppendShapeNullArgument() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ try {
+ path.append((Shape) null, true);
+ fail("append((Shape) null, true) expected
NullPointerException");
+ }
+ catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testAppendPathIterator() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ Rectangle2D rect = new Rectangle2D.Double(50.0d, 100.0d, 50.0d,
100.0d);
+ PathIterator pathIterator = rect.getPathIterator(new
AffineTransform());
+ path.append(pathIterator, true);
+ assertEquals(101.0d, path.getWidth(), TOLERANCE);
+ assertEquals(201.0d, path.getHeight(), TOLERANCE);
+ }
+
+ public void testAppendPathIteratorNullArgument() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ try {
+ path.append((PathIterator) null, true);
+ fail("append((PathIterator) null, true) expected
NullPointerException");
+ }
+ catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testCurveTo() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ path.curveTo(70.0d, 140.0d, 80.0d, 140.0d, 100.0d, 200.0d);
+ assertEquals(101.0d, path.getWidth(), LOW_TOLERANCE);
+ assertEquals(201.0d, path.getHeight(), LOW_TOLERANCE);
+ }
+
+ public void testLineTo() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ path.lineTo(100.0d, 200.0d);
+ assertEquals(101.0d, path.getWidth(), LOW_TOLERANCE);
+ assertEquals(201.0d, path.getHeight(), LOW_TOLERANCE);
+ }
+
+ public void testMoveTo() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ path.moveTo(100.0d, 200.0d);
+ assertEquals(51.0d, path.getWidth(), TOLERANCE);
+ assertEquals(101.0d, path.getHeight(), TOLERANCE);
+ }
+
+ public void testQuadTo() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ path.quadTo(70.0d, 140.0d, 100.0d, 200.0d);
+ assertEquals(101.0d, path.getWidth(), LOW_TOLERANCE);
+ assertEquals(201.0d, path.getHeight(), LOW_TOLERANCE);
+ }
+
+ public void testClosePath() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ path.lineTo(100.0d, 200.0d);
+ path.closePath();
+ }
+
+ public void testClosePathAlreadyClosed() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ path.lineTo(100.0d, 200.0d);
+ path.closePath();
+ path.closePath();
+ }
+
+ public void testIntersects() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ assertTrue(path.intersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
+ assertTrue(path.intersects(new Rectangle2D.Double(25.0d, 50.0d,
2.0d, 2.0d)));
+ assertTrue(path.intersects(new Rectangle2D.Double(49.0d, 99.0d,
2.0d, 2.0d)));
+ assertFalse(path.intersects(new Rectangle2D.Double(-10.0d, -10.0d,
2.0d, 2.0d)));
+ assertFalse(path.intersects(new Rectangle2D.Double(100.0d, 200.0d,
2.0d, 2.0d)));
+ }
+
+ public void testIntersectsNullStroke() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ path.setStroke(null);
+ assertTrue(path.intersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
+ assertTrue(path.intersects(new Rectangle2D.Double(25.0d, 50.0d,
2.0d, 2.0d)));
+ assertTrue(path.intersects(new Rectangle2D.Double(49.0d, 99.0d,
2.0d, 2.0d)));
+ assertFalse(path.intersects(new Rectangle2D.Double(-10.0d, -10.0d,
2.0d, 2.0d)));
+ assertFalse(path.intersects(new Rectangle2D.Double(100.0d, 200.0d,
2.0d, 2.0d)));
+ }
+
+ public void testIntersectsNullPaint() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ path.setPaint(null);
+ assertTrue(path.intersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
+ assertFalse(path.intersects(new Rectangle2D.Double(25.0d, 50.0d,
2.0d, 2.0d)));
+ assertTrue(path.intersects(new Rectangle2D.Double(49.0d, 99.0d,
2.0d, 2.0d)));
+ assertFalse(path.intersects(new Rectangle2D.Double(-10.0d, -10.0d,
2.0d, 2.0d)));
+ assertFalse(path.intersects(new Rectangle2D.Double(100.0d, 200.0d,
2.0d, 2.0d)));
+ }
+
+ public void testIntersectsNullPaintNullStroke() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ path.setPaint(null);
+ path.setStroke(null);
+ assertFalse(path.intersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
+ assertFalse(path.intersects(new Rectangle2D.Double(25.0d, 50.0d,
2.0d, 2.0d)));
+ assertFalse(path.intersects(new Rectangle2D.Double(49.0d, 99.0d,
2.0d, 2.0d)));
+ assertFalse(path.intersects(new Rectangle2D.Double(-10.0d, -10.0d,
2.0d, 2.0d)));
+ assertFalse(path.intersects(new Rectangle2D.Double(100.0d, 200.0d,
2.0d, 2.0d)));
+ }
+
+ public void testFullIntersects() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ assertTrue(path.fullIntersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
+ assertTrue(path.fullIntersects(new Rectangle2D.Double(25.0d,
50.0d, 2.0d, 2.0d)));
+ assertTrue(path.fullIntersects(new Rectangle2D.Double(49.0d,
99.0d, 2.0d, 2.0d)));
+ assertFalse(path.fullIntersects(new Rectangle2D.Double(-10.0d,
-10.0d, 2.0d, 2.0d)));
+ assertFalse(path.fullIntersects(new Rectangle2D.Double(100.0d,
200.0d, 2.0d, 2.0d)));
+ }
+
+ public void testFullIntersectsNullStroke() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ path.setStroke(null);
+ assertTrue(path.fullIntersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
+ assertTrue(path.fullIntersects(new Rectangle2D.Double(25.0d,
50.0d, 2.0d, 2.0d)));
+ assertTrue(path.fullIntersects(new Rectangle2D.Double(49.0d,
99.0d, 2.0d, 2.0d)));
+ assertFalse(path.fullIntersects(new Rectangle2D.Double(-10.0d,
-10.0d, 2.0d, 2.0d)));
+ assertFalse(path.fullIntersects(new Rectangle2D.Double(100.0d,
200.0d, 2.0d, 2.0d)));
+ }
+
+ public void testFullIntersectsNullPaint() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ path.setPaint(null);
+ assertTrue(path.fullIntersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
+ assertTrue(path.fullIntersects(new Rectangle2D.Double(25.0d,
50.0d, 2.0d, 2.0d)));
+ assertTrue(path.fullIntersects(new Rectangle2D.Double(49.0d,
99.0d, 2.0d, 2.0d)));
+ assertFalse(path.fullIntersects(new Rectangle2D.Double(-10.0d,
-10.0d, 2.0d, 2.0d)));
+ assertFalse(path.fullIntersects(new Rectangle2D.Double(100.0d,
200.0d, 2.0d, 2.0d)));
+ }
+
+ public void testFullIntersectsNullPaintNullStroke() {
+ PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
+ path.setPaint(null);
+ path.setStroke(null);
+ assertTrue(path.fullIntersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
+ assertTrue(path.fullIntersects(new Rectangle2D.Double(25.0d,
50.0d, 2.0d, 2.0d)));
+ assertTrue(path.fullIntersects(new Rectangle2D.Double(49.0d,
99.0d, 2.0d, 2.0d)));
+ assertFalse(path.fullIntersects(new Rectangle2D.Double(-10.0d,
-10.0d, 2.0d, 2.0d)));
+ assertFalse(path.fullIntersects(new Rectangle2D.Double(100.0d,
200.0d, 2.0d, 2.0d)));
+ }
+
+ /*
+ public void testPath() {
+ PPath path = createPathNode();
+ assertNotNull(path.getPath()); // or (Path) getShape(), or
getPathReference() ?
+ Path2D.Double rect = new Path2D.Double((new
Rectangle2D.Double(0.0d, 0.0d, 100.0d, 100.0d)));
+ path.setPath(rect);
+ assertEquals(rect, path.getPath());
+ }
+
+ public void testPathNullArgument() {
+ PPath path = createPathNode();
+ try {
+ path.setPath(null);
+ fail("setPath(null) expected IllegalArgumentException");
+ }
+ catch (IllegalArgumentException e) { // or NPE?
+ // expected
+ }
+ }
+
+ public void testPathBoundProperty() {
+ PPath path = createPathNode();
+ path.addPropertyChangeListener("path", mockListener);
+ Path2D.Double rect = new Path2D.Double((new
Rectangle2D.Double(0.0d, 0.0d, 100.0d, 100.0d)));
+ path.setPath(rect);
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+
+ public void testAppendShapeFiresPropertyChangeEvent() {
+ PPath path = createPathNode();
+ path.addPropertyChangeListener("path", mockListener);
+ Rectangle2D rect = new Rectangle2D.Double(50.0d, 100.0d, 50.0d,
100.0d);
+ path.append(rect, true);
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+
+ public void testAppendPathIteratorFiresPropertyChangeEvent() {
+ PPath path = createPathNode();
+ path.addPropertyChangeListener("path", mockListener);
+ Rectangle2D rect = new Rectangle2D.Double(50.0d, 100.0d, 50.0d,
100.0d);
+ PathIterator pathIterator = rect.getPathIterator(new
AffineTransform());
+ path.append(pathIterator, true);
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+
+ public void testCurveToFiresPropertyChangeEvent() {
+ PPath path = createPathNode();
+ path.addPropertyChangeListener("path", mockListener);
+ path.curveTo(70.0d, 140.0d, 80.0d, 140.0d, 100.0d, 200.0d);
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+
+ public void testLineToFiresPropertyChangeEvent() {
+ PPath path = createPathNode();
+ path.addPropertyChangeListener("path", mockListener);
+ path.lineTo(100.0d, 200.0d);
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+
+ public void testMoveToFiresPropertyChangeEvent() {
+ PPath path = createPathNode();
+ path.addPropertyChangeListener("path", mockListener);
+ path.moveTo(100.0d, 200.0d);
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+
+ public void testQuadToFiresPropertyChangeEvent() {
+ PPath path = createPathNode();
+ path.addPropertyChangeListener("path", mockListener);
+ path.quadTo(70.0d, 140.0d, 100.0d, 200.0d);
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+
+ public void testClosePathFiresPropertyChangeEvent() {
+ PPath path = createPathNode();
+ path.addPropertyChangeListener("path", mockListener);
+ path.lineTo(100.0d, 200.0d);
+ path.closePath();
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+ */
+}
=======================================
---
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathTest.java
Tue Aug 3 15:03:26 2010
+++ /dev/null
@@ -1,407 +0,0 @@
-/*
- * Copyright (c) 2008-2010, Piccolo2D project, http://piccolo2d.org
- * Copyright (c) 1998-2008, University of Maryland
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
modification, are permitted provided
- * that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice,
this list of conditions
- * and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions
- * and the following disclaimer in the documentation and/or other
materials provided with the
- * distribution.
- *
- * None of the name of the University of Maryland, the name of the
Piccolo2D project, or the names of its
- * contributors may be used to endorse or promote products derived from
this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package org.piccolo2d.nodes;
-
-import java.awt.Color;
-import java.awt.Shape;
-
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Arc2D;
-import java.awt.geom.PathIterator;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-
-import org.piccolo2d.MockPropertyChangeListener;
-import org.piccolo2d.PiccoloAsserts;
-
-import org.piccolo2d.nodes.PPath;
-
-import org.piccolo2d.util.PBounds;
-import org.piccolo2d.util.PObjectOutputStream;
-
-import junit.framework.TestCase;
-
-/**
- * Unit test for PPath.
- */
-public class PPathTest extends TestCase {
-
- private static final double TOLERANCE = 0.0001d;
- private static final double LOW_TOLERANCE = 1.0d;
-
- private MockPropertyChangeListener mockListener;
-
- public void setUp() {
- mockListener = new MockPropertyChangeListener();
- }
-
- public void testStrokeIsNotNullByDefault() {
- final PPath path = new PPath.Double();
- assertNotNull(path.getStroke());
- }
-
- public void testStrokePaintIsBlackByDefault() {
- final PPath path = new PPath.Double();
- assertEquals(Color.BLACK, path.getStrokePaint());
- }
-
- public void testClone() {
- PPath p = PPath.createEllipse(0, 0, 100, 100);
- PPath cloned = (PPath) p.clone();
- assertEquals(p.getBounds(), cloned.getBounds());
- //assertEquals(p.getPathReference()., cloned.getPathReference());
- }
-
- public void testSerialization() throws IOException,
ClassNotFoundException {
- final PPath srcPath = PPath.createEllipse(0, 0, 100, 100);
- final PBounds srcBounds = srcPath.getBounds();
-
- final File file = File.createTempFile("test", "ser");
-
- serializeToFile(srcPath, file);
- final PPath resultPath = deserializeFromFile(srcBounds, file);
- file.deleteOnExit();
-
- assertEquals(resultPath.getBounds(), srcBounds);
- }
-
- private PPath deserializeFromFile(final PBounds b, final File file)
throws FileNotFoundException, IOException,
- ClassNotFoundException {
- PPath path;
- final FileInputStream fin = new FileInputStream(file);
- final ObjectInputStream in = new ObjectInputStream(fin);
- path = (PPath) in.readObject();
-
- return path;
- }
-
- private void serializeToFile(final PPath p, final File file) throws
FileNotFoundException, IOException {
- final FileOutputStream fout = new FileOutputStream(file);
- final PObjectOutputStream out = new PObjectOutputStream(fout);
- out.writeObjectTree(p);
- out.flush();
- out.close();
- }
-
- public void testCreateRectangleReturnsValidPPath() {
- final PPath path = PPath.createRectangle(0, 0, 100, 50);
- assertNotNull(path);
-
- // Seems like rounding is affecting the bounds greatly
- PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 50),
path.getBounds(), 2.0d);
- }
-
- public void testCreateEllipseReturnsValidPPath() {
- final PPath path = PPath.createEllipse(0, 0, 100, 50);
- assertNotNull(path);
-
- // Seems like rounding is affecting the bounds greatly
- PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 50),
path.getBounds(), 2.0d);
- }
-
- public void testCreateRoundedRectReturnsValidPPath() {
- final PPath path = PPath.createRoundRectangle(0, 0, 100, 50, 10,
10);
- assertNotNull(path);
-
- // Seems like rounding is affecting the bounds greatly
- PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 50),
path.getBounds(), 2.0d);
- }
-
- public void testCreateLineReturnsValidPPath() {
- final PPath path = PPath.createLine(0, 0, 100, 0);
- assertNotNull(path);
-
- // Seems like rounding is affecting the bounds greatly
- PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 0),
path.getBounds(), 2.0d);
- }
-
- /*
- public void testCreatePolyLinePoint2DReturnsValidPPath() {
- final PPath path = PPath.createPolyline(new Point2D[] { new
Point2D.Double(0, 0), new Point2D.Double(100, 50),
- new Point2D.Double(100, 0) });
- assertNotNull(path);
-
- // Seems like rounding is affecting the bounds greatly
- PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 50),
path.getBounds(), 2.0d);
- }
-
- public void testCreatePolyLineFloatsReturnsValidPPath() {
- final PPath path = PPath.createPolyline(new float[] { 0, 100, 100
}, new float[] { 0, 50, 0 });
- assertNotNull(path);
-
- // Seems like rounding is affecting the bounds greatly
- PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 50),
path.getBounds(), 2.0d);
- }
- */
-
- public void testSetStrokePaintPersists() {
- final PPath path = new PPath.Double();
- path.setStrokePaint(Color.RED);
- assertEquals(Color.RED, path.getStrokePaint());
- }
-
- // todo: move these to PShape test, add stroke
- public void testSetStrokeFiresPropertyChangeEvent() {
- final PPath path = new PPath.Double();
- path.addPropertyChangeListener("strokePaint", mockListener);
- path.setStrokePaint(Color.RED);
- assertEquals(1, mockListener.getPropertyChangeCount());
- }
-
- public void testChangingPathFiresPropertyChangeEvent() {
- final PPath path = new PPath.Double();
- path.addPropertyChangeListener("path", mockListener); // "shape"
- path.append(new Rectangle2D.Double(0, 0, 100, 50), true);
- assertEquals(1, mockListener.getPropertyChangeCount());
- }
-
- public void testCreateArcFloat() {
- assertNotNull(PPath.createArc(0.0f, 0.0f, 50.0f, 100.0f, 25.0f,
75.0f, Arc2D.OPEN));
- }
-
- public void testCreateCubicCurveFloat() {
- assertNotNull(PPath.createCubicCurve(0.0f, 0.0f, 25.0f, 75.0f,
75.0f, 25.0f, 50.0f, 100.0f));
- }
-
- public void testCreateEllipseFloat() {
- assertNotNull(PPath.createEllipse(0.0f, 0.0f, 50.0f, 100.0f));
- }
-
- public void testCreateLineFloat() {
- assertNotNull(PPath.createLine(0.0f, 0.0f, 50.0f, 100.0f));
- }
-
- public void testCreateQuadCurveFloat() {
- assertNotNull(PPath.createQuadCurve(0.0f, 0.0f, 25.0f, 75.0f,
50.0f, 100.0f));
- }
-
- public void testCreateRectangleFloat() {
- assertNotNull(PPath.createRectangle(0.0f, 0.0f, 50.0f, 100.0f));
- }
-
- public void testCreateRoundRectangleFloat() {
- assertNotNull(PPath.createRoundRectangle(0.0f, 0.0f, 50.0f,
100.0f, 4.0f, 8.0f));
- }
-
- public void testCreateArcDouble() {
- assertNotNull(PPath.createArc(0.0d, 0.0d, 50.0d, 100.0d, 25.0d,
75.0d, Arc2D.OPEN));
- }
-
- public void testCreateCubicCurveDouble() {
- assertNotNull(PPath.createCubicCurve(0.0d, 0.0d, 25.0d, 75.0d,
75.0d, 25.0d, 50.0d, 100.0d));
- }
-
- public void testCreateEllipseDouble() {
- assertNotNull(PPath.createEllipse(0.0d, 0.0d, 50.0d, 100.0d));
- }
-
- public void testCreateLineDouble() {
- assertNotNull(PPath.createLine(0.0d, 0.0d, 50.0d, 100.0d));
- }
-
- public void testCreateQuadCurveDouble() {
- assertNotNull(PPath.createQuadCurve(0.0d, 0.0d, 25.0d, 75.0d,
50.0d, 100.0d));
- }
-
- public void testCreateRectangleDouble() {
- assertNotNull(PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d));
- }
-
- public void testCreateRoundRectangleDouble() {
- assertNotNull(PPath.createRoundRectangle(0.0d, 0.0d, 50.0d,
100.0d, 4.0d, 8.0d));
- }
-
- public void testAppendShape() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- Rectangle2D rect = new Rectangle2D.Double(50.0d, 100.0d, 50.0d,
100.0d);
- path.append(rect, true);
- // todo: shouldn't this be width + 2 * strokeWidth?
- assertEquals(101.0d, path.getWidth(), TOLERANCE);
- assertEquals(201.0d, path.getHeight(), TOLERANCE);
- }
-
- public void testAppendShapeNullArgument() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- try {
- path.append((Shape) null, true);
- fail("append((Shape) null, true) expected
NullPointerException");
- }
- catch (NullPointerException e) {
- // expected
- }
- }
-
- public void testAppendPathIterator() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- Rectangle2D rect = new Rectangle2D.Double(50.0d, 100.0d, 50.0d,
100.0d);
- PathIterator pathIterator = rect.getPathIterator(new
AffineTransform());
- path.append(pathIterator, true);
- assertEquals(101.0d, path.getWidth(), TOLERANCE);
- assertEquals(201.0d, path.getHeight(), TOLERANCE);
- }
-
- public void testAppendPathIteratorNullArgument() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- try {
- path.append((PathIterator) null, true);
- fail("append((PathIterator) null, true) expected
NullPointerException");
- }
- catch (NullPointerException e) {
- // expected
- }
- }
-
- public void testCurveTo() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- path.curveTo(70.0d, 140.0d, 80.0d, 140.0d, 100.0d, 200.0d);
- assertEquals(101.0d, path.getWidth(), LOW_TOLERANCE);
- assertEquals(201.0d, path.getHeight(), LOW_TOLERANCE);
- }
-
- public void testLineTo() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- path.lineTo(100.0d, 200.0d);
- assertEquals(101.0d, path.getWidth(), LOW_TOLERANCE);
- assertEquals(201.0d, path.getHeight(), LOW_TOLERANCE);
- }
-
- public void testMoveTo() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- path.moveTo(100.0d, 200.0d);
- assertEquals(51.0d, path.getWidth(), TOLERANCE);
- assertEquals(101.0d, path.getHeight(), TOLERANCE);
- }
-
- public void testQuadTo() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- path.quadTo(70.0d, 140.0d, 100.0d, 200.0d);
- assertEquals(101.0d, path.getWidth(), LOW_TOLERANCE);
- assertEquals(201.0d, path.getHeight(), LOW_TOLERANCE);
- }
-
- public void testClosePath() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- path.lineTo(100.0d, 200.0d);
- path.closePath();
- }
-
- public void testClosePathAlreadyClosed() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- path.lineTo(100.0d, 200.0d);
- path.closePath();
- path.closePath();
- }
-
- public void testIntersects() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- assertTrue(path.intersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
- assertTrue(path.intersects(new Rectangle2D.Double(25.0d, 50.0d,
2.0d, 2.0d)));
- assertTrue(path.intersects(new Rectangle2D.Double(49.0d, 99.0d,
2.0d, 2.0d)));
- assertFalse(path.intersects(new Rectangle2D.Double(-10.0d, -10.0d,
2.0d, 2.0d)));
- assertFalse(path.intersects(new Rectangle2D.Double(100.0d, 200.0d,
2.0d, 2.0d)));
- }
-
- public void testIntersectsNullStroke() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- path.setStroke(null);
- assertTrue(path.intersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
- assertTrue(path.intersects(new Rectangle2D.Double(25.0d, 50.0d,
2.0d, 2.0d)));
- assertTrue(path.intersects(new Rectangle2D.Double(49.0d, 99.0d,
2.0d, 2.0d)));
- assertFalse(path.intersects(new Rectangle2D.Double(-10.0d, -10.0d,
2.0d, 2.0d)));
- assertFalse(path.intersects(new Rectangle2D.Double(100.0d, 200.0d,
2.0d, 2.0d)));
- }
-
- public void testIntersectsNullPaint() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- path.setPaint(null);
- assertTrue(path.intersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
- assertFalse(path.intersects(new Rectangle2D.Double(25.0d, 50.0d,
2.0d, 2.0d)));
- assertTrue(path.intersects(new Rectangle2D.Double(49.0d, 99.0d,
2.0d, 2.0d)));
- assertFalse(path.intersects(new Rectangle2D.Double(-10.0d, -10.0d,
2.0d, 2.0d)));
- assertFalse(path.intersects(new Rectangle2D.Double(100.0d, 200.0d,
2.0d, 2.0d)));
- }
-
- public void testIntersectsNullPaintNullStroke() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- path.setPaint(null);
- path.setStroke(null);
- assertFalse(path.intersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
- assertFalse(path.intersects(new Rectangle2D.Double(25.0d, 50.0d,
2.0d, 2.0d)));
- assertFalse(path.intersects(new Rectangle2D.Double(49.0d, 99.0d,
2.0d, 2.0d)));
- assertFalse(path.intersects(new Rectangle2D.Double(-10.0d, -10.0d,
2.0d, 2.0d)));
- assertFalse(path.intersects(new Rectangle2D.Double(100.0d, 200.0d,
2.0d, 2.0d)));
- }
-
- public void testFullIntersects() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- assertTrue(path.fullIntersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
- assertTrue(path.fullIntersects(new Rectangle2D.Double(25.0d,
50.0d, 2.0d, 2.0d)));
- assertTrue(path.fullIntersects(new Rectangle2D.Double(49.0d,
99.0d, 2.0d, 2.0d)));
- assertFalse(path.fullIntersects(new Rectangle2D.Double(-10.0d,
-10.0d, 2.0d, 2.0d)));
- assertFalse(path.fullIntersects(new Rectangle2D.Double(100.0d,
200.0d, 2.0d, 2.0d)));
- }
-
- public void testFullIntersectsNullStroke() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- path.setStroke(null);
- assertTrue(path.fullIntersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
- assertTrue(path.fullIntersects(new Rectangle2D.Double(25.0d,
50.0d, 2.0d, 2.0d)));
- assertTrue(path.fullIntersects(new Rectangle2D.Double(49.0d,
99.0d, 2.0d, 2.0d)));
- assertFalse(path.fullIntersects(new Rectangle2D.Double(-10.0d,
-10.0d, 2.0d, 2.0d)));
- assertFalse(path.fullIntersects(new Rectangle2D.Double(100.0d,
200.0d, 2.0d, 2.0d)));
- }
-
- public void testFullIntersectsNullPaint() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- path.setPaint(null);
- assertTrue(path.fullIntersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
- assertTrue(path.fullIntersects(new Rectangle2D.Double(25.0d,
50.0d, 2.0d, 2.0d)));
- assertTrue(path.fullIntersects(new Rectangle2D.Double(49.0d,
99.0d, 2.0d, 2.0d)));
- assertFalse(path.fullIntersects(new Rectangle2D.Double(-10.0d,
-10.0d, 2.0d, 2.0d)));
- assertFalse(path.fullIntersects(new Rectangle2D.Double(100.0d,
200.0d, 2.0d, 2.0d)));
- }
-
- public void testFullIntersectsNullPaintNullStroke() {
- PPath path = PPath.createRectangle(0.0d, 0.0d, 50.0d, 100.0d);
- path.setPaint(null);
- path.setStroke(null);
- assertTrue(path.fullIntersects(new Rectangle2D.Double(0.0d, 0.0d,
2.0d, 2.0d)));
- assertTrue(path.fullIntersects(new Rectangle2D.Double(25.0d,
50.0d, 2.0d, 2.0d)));
- assertTrue(path.fullIntersects(new Rectangle2D.Double(49.0d,
99.0d, 2.0d, 2.0d)));
- assertFalse(path.fullIntersects(new Rectangle2D.Double(-10.0d,
-10.0d, 2.0d, 2.0d)));
- assertFalse(path.fullIntersects(new Rectangle2D.Double(100.0d,
200.0d, 2.0d, 2.0d)));
- }
-}
=======================================
---
/piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PPath.java
Tue Aug 3 13:33:18 2010
+++
/piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PPath.java
Wed Aug 4 15:04:12 2010
@@ -552,7 +552,12 @@
* @param x3 x coordinate of the final end point
* @param y3 y coordinate of the final end point
*/
- public final void curveTo(final double x1, final double y1, final
double x2, final double y2, final double x3, final double y3) {
+ public final void curveTo(final double x1,
+ final double y1,
+ final double x2,
+ final double y2,
+ final double x3,
+ final double y3) {
path.curveTo(x1, y1, x2, y2, x3, y3);
updateBoundsFromShape();
}
=======================================
---
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/AbstractPShapeTest.java
Tue Aug 3 15:03:26 2010
+++
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/AbstractPShapeTest.java
Wed Aug 4 15:04:12 2010
@@ -28,7 +28,13 @@
*/
package org.piccolo2d.nodes;
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Paint;
+import java.awt.Stroke;
+
import org.piccolo2d.AbstractPNodeTest;
+import org.piccolo2d.MockPropertyChangeListener;
import org.piccolo2d.PNode;
/**
@@ -36,6 +42,14 @@
*/
public abstract class AbstractPShapeTest extends AbstractPNodeTest {
+ private MockPropertyChangeListener mockListener;
+
+ /** {...@inheritdoc} */
+ protected void setUp() {
+ super.setUp();
+ mockListener = new MockPropertyChangeListener();
+ }
+
/** {...@inheritdoc} */
protected PNode createNode() {
return createShapeNode();
@@ -66,4 +80,34 @@
PShape shape = createShapeNode();
assertEquals(PShape.DEFAULT_STROKE_PAINT, shape.getStrokePaint());
}
-}
+
+ public void testStroke() {
+ PShape shape = createShapeNode();
+ Stroke stroke = new BasicStroke(2.0f);
+ shape.setStroke(stroke);
+ assertEquals(stroke, shape.getStroke());
+ }
+
+ public void testStrokeBoundProperty() {
+ PShape shape = createShapeNode();
+ shape.addPropertyChangeListener("stroke", mockListener);
+ Stroke stroke = new BasicStroke(2.0f);
+ shape.setStroke(stroke);
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+
+ public void testStrokePaint() {
+ PShape shape = createShapeNode();
+ Paint strokePaint = Color.RED;
+ shape.setStrokePaint(strokePaint);
+ assertEquals(strokePaint, shape.getStrokePaint());
+ }
+
+ public void testStrokePaintBoundProperty() {
+ PShape shape = createShapeNode();
+ shape.addPropertyChangeListener("strokePaint", mockListener);
+ Paint strokePaint = Color.RED;
+ shape.setStrokePaint(strokePaint);
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+}
=======================================
---
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PAreaTest.java
Wed Aug 4 10:08:52 2010
+++
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PAreaTest.java
Wed Aug 4 15:04:12 2010
@@ -548,4 +548,71 @@
assertFalse(exclusiveOr.isSingular());
}
-}
+
+ /*
+ public void testArea() {
+ PArea area = new PArea();
+ assertNotNull(area.getArea()); // or (Area) getShape(), or
getAreaReference() ?
+ Area rect = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d,
100.0d));
+ area.setArea(rect);
+ assertEquals(rect, area.getArea());
+ }
+
+ public void testAreaNullArgument() {
+ PArea area = new PArea();
+ try {
+ area.setArea(null);
+ fail("setArea(null) expected IllegalArgumentException");
+ }
+ catch (IllegalArgumentException e) { // or NPE?
+ // expected
+ }
+ }
+
+ public void testAreaBoundProperty() {
+ PArea area = new PArea();
+ area.addPropertyChangeListener("area", mockListener);
+ Area rect = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d,
100.0d));
+ area.setArea(rect);
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+
+ public void testAddFiresPropertyChangeEvent() {
+ PArea area = new PArea();
+ area.addPropertyChangeListener("area", mockListener);
+ Area rect = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d,
100.0d));
+ area.add(rect);
+ assertEquals(1, mockListener.getPropertyChangeCount());
+ }
+
+ public void testExclusiveOrFiresPropertyChangeEvent() {
+ PArea area = new PArea();
+ area.addPropertyChangeListener("area", mockListener);
+ Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d,
100.0d));
+ area.add(rect0);
+ Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d,
100.0d));
+ area.exclusiveOr(rect1);
+ assertEquals(2, mockListener.getPropertyChangeCount());
+ }
+
+ public void testIntersectFiresPropertyChangeEvent() {
+ PArea area = new PArea();
+ area.addPropertyChangeListener("area", mockListener);
+ Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d,
100.0d));
+ area.add(rect0);
+ Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d,
100.0d));
+ area.intersect(rect1);
+ assertEquals(2, mockListener.getPropertyChangeCount());
+ }
+
+ public void testSubtractFiresPropertyChangeEvent() {
+ PArea area = new PArea();
+ area.addPropertyChangeListener("area", mockListener);
+ Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d,
100.0d));
+ area.add(rect0);
+ Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d,
100.0d));
+ area.subtract(rect1);
+ assertEquals(2, mockListener.getPropertyChangeCount());
+ }
+ */
+}
=======================================
---
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathDoubleTest.java
Tue Aug 3 13:33:18 2010
+++
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathDoubleTest.java
Wed Aug 4 15:04:12 2010
@@ -38,10 +38,10 @@
/**
* Unit test for PPath.Double.
*/
-public class PPathDoubleTest extends AbstractPShapeTest {
+public class PPathDoubleTest extends AbstractPPathTest {
/** {...@inheritdoc} */
- protected PShape createShapeNode() {
+ protected PPath createPathNode() {
return new PPath.Double();
}
=======================================
---
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathFloatTest.java
Tue Aug 3 13:33:18 2010
+++
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathFloatTest.java
Wed Aug 4 15:04:12 2010
@@ -38,10 +38,10 @@
/**
* Unit test for PPath.Float.
*/
-public class PPathFloatTest extends AbstractPShapeTest {
+public class PPathFloatTest extends AbstractPPathTest {
/** {...@inheritdoc} */
- protected PShape createShapeNode() {
+ protected PPath createPathNode() {
return new PPath.Float();
}
--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en