Revision: 626 Author: mr0...@mro.name Date: Thu Jul 30 02:15:41 2009 Log: issue#116 - tests accessing non-final fields to prevent code-clean finalization. Code Clean. http://code.google.com/p/piccolo2d/source/detail?r=626
Added: /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/util/PUtilTest.java Modified: /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/nodes/PText.java /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/event/PInputEventFilterTest.java /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java ======================================= --- /dev/null +++ /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/util/PUtilTest.java Thu Jul 30 02:15:41 2009 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2008-2009, Piccolo2D project, http://piccolo2d.org + * 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 edu.umd.cs.piccolo.util; + +import java.io.OutputStream; +import java.util.Enumeration; +import java.util.Iterator; + +import junit.framework.TestCase; + +public class PUtilTest extends TestCase { + + // see http://code.google.com/p/piccolo2d/issues/detail?id=116 + public void testPreventCodeCleanFinal() { + final Enumeration ne = PUtil.NULL_ENUMERATION; + try { + PUtil.NULL_ENUMERATION = null; + } + finally { + PUtil.NULL_ENUMERATION = ne; + } + + final Iterator ni = PUtil.NULL_ITERATOR; + try { + PUtil.NULL_ITERATOR = null; + } + finally { + PUtil.NULL_ITERATOR = ni; + } + + final OutputStream no = PUtil.NULL_OUTPUT_STREAM; + try { + PUtil.NULL_OUTPUT_STREAM = null; + } + finally { + PUtil.NULL_OUTPUT_STREAM = no; + } + } + +} ======================================= --- /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java Thu Jul 30 02:01:10 2009 +++ /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java Thu Jul 30 02:15:41 2009 @@ -53,9 +53,9 @@ */ public class PInputEventFilter { - public static int ALL_MODIFIERS_MASK = InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK - | InputEvent.BUTTON3_MASK | InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK | InputEvent.ALT_MASK - | InputEvent.ALT_GRAPH_MASK | InputEvent.META_MASK; + public static int ALL_MODIFIERS_MASK = InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK + | InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK | InputEvent.ALT_MASK | InputEvent.ALT_GRAPH_MASK + | InputEvent.META_MASK; private int andMask; private int orMask; ======================================= --- /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/nodes/PText.java Wed Jul 29 20:11:27 2009 +++ /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/nodes/PText.java Thu Jul 30 02:15:41 2009 @@ -76,17 +76,24 @@ /** * The property name that identifies a change of this node's text paint (see - * {...@link #getTextPaint getTextPaint}). Both old and new value will be set in any - * property change event. + * {...@link #getTextPaint getTextPaint}). Both old and new value will be set + * in any property change event. */ public static final String PROPERTY_TEXT_PAINT = "text paint"; public static final int PROPERTY_CODE_TEXT_PAINT = 1 << 21; - /** Default font, 12 point <code>"SansSerif"</code>. Will be made final in version 2.0. */ - //public static final Font DEFAULT_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 12); jdk 1.6+ + /** + * Default font, 12 point <code>"SansSerif"</code>. Will be made final in + * version 2.0. + */ + // public static final Font DEFAULT_FONT = new Font(Font.SANS_SERIF, + // Font.PLAIN, 12); jdk 1.6+ public static Font DEFAULT_FONT = new Font("SansSerif", Font.PLAIN, 12); - /** Default greek threshold, <code>5.5d</code>. Will be made final in version 2.0. */ + /** + * Default greek threshold, <code>5.5d</code>. Will be made final in version + * 2.0. + */ public static double DEFAULT_GREEK_THRESHOLD = 5.5d; /** Default horizontal alignment, <code>Component.LEFT_ALIGNMENT</code>. */ @@ -109,7 +116,6 @@ private boolean constrainWidthToTextWidth = true; private transient TextLayout[] lines; - /** * Create a new text node with no text (<code>""</code>). */ @@ -119,30 +125,31 @@ /** * Create a new text node with the specified text. - * + * * @param text text for this text node */ public PText(final String text) { this(); setText(text); } - /** @deprecated by {...@link #getHorizontalAlignment()} */ public float getJustification() { return getHorizontalAlignment(); } - /** @deprecated by {...@link #setHorizontalAlignment(float)} */ + /** @deprecated by {...@link #setHorizontalAlignment(float)} */ public void setJustification(final float justification) { setHorizontalAlignment(justification); } /** - * Return the horizontal alignment for this text node. The horizontal alignment will be one of - * <code>Component.LEFT_ALIGNMENT</code>, <code>Component.CENTER_ALIGNMENT</code>, - * or <code>Component.RIGHT_ALIGNMENT</code>. Defaults to {...@link #DEFAULT_HORIZONTAL_ALIGNMENT}. - * + * Return the horizontal alignment for this text node. The horizontal + * alignment will be one of <code>Component.LEFT_ALIGNMENT</code>, + * <code>Component.CENTER_ALIGNMENT</code>, or + * <code>Component.RIGHT_ALIGNMENT</code>. Defaults to + * {...@link #DEFAULT_HORIZONTAL_ALIGNMENT}. + * * @return the horizontal alignment for this text node */ public float getHorizontalAlignment() { @@ -150,11 +157,13 @@ } /** - * Set the horizontal alignment for this text node to <code>horizontalAlignment</code>. - * + * Set the horizontal alignment for this text node to + * <code>horizontalAlignment</code>. + * * @param horizontalAlignment horizontal alignment, must be one of - * <code>Component.LEFT_ALIGNMENT</code>, <code>Component.CENTER_ALIGNMENT</code>, - * or <code>Component.RIGHT_ALIGNMENT</code> + * <code>Component.LEFT_ALIGNMENT</code>, + * <code>Component.CENTER_ALIGNMENT</code>, or + * <code>Component.RIGHT_ALIGNMENT</code> */ public void setHorizontalAlignment(final float horizontalAlignment) { if (!validHorizontalAlignment(horizontalAlignment)) { @@ -165,16 +174,19 @@ } /** - * Return true if the specified horizontal alignment is one of <code>Component.LEFT_ALIGNMENT</code>, - * <code>Component.CENTER_ALIGNMENT</code>, or <code>Component.RIGHT_ALIGNMENT</code>. - * + * Return true if the specified horizontal alignment is one of + * <code>Component.LEFT_ALIGNMENT</code>, + * <code>Component.CENTER_ALIGNMENT</code>, or + * <code>Component.RIGHT_ALIGNMENT</code>. + * * @param horizontalAlignment horizontal alignment - * @return true if the specified horizontal alignment is one of <code>Component.LEFT_ALIGNMENT</code>, - * <code>Component.CENTER_ALIGNMENT</code>, or <code>Component.RIGHT_ALIGNMENT</code> + * @return true if the specified horizontal alignment is one of + * <code>Component.LEFT_ALIGNMENT</code>, + * <code>Component.CENTER_ALIGNMENT</code>, or + * <code>Component.RIGHT_ALIGNMENT</code> */ private static boolean validHorizontalAlignment(final float horizontalAlignment) { - return Component.LEFT_ALIGNMENT == horizontalAlignment - || Component.CENTER_ALIGNMENT == horizontalAlignment + return Component.LEFT_ALIGNMENT == horizontalAlignment || Component.CENTER_ALIGNMENT == horizontalAlignment || Component.RIGHT_ALIGNMENT == horizontalAlignment; } @@ -189,9 +201,11 @@ /** * Set the paint used to paint this node's text to <code>textPaint</code>. - * - * <p>This is a <b>bound</b> property.</p> - * + * + * <p> + * This is a <b>bound</b> property. + * </p> + * * @param textPaint text paint */ public void setTextPaint(final Paint textPaint) { @@ -205,19 +219,22 @@ } /** - * Return true if this text node should constrain its width to the width of its text. - * Defaults to <code>true</code>. - * - * @return true if this text node should constrain its width to the width of its text + * Return true if this text node should constrain its width to the width of + * its text. Defaults to <code>true</code>. + * + * @return true if this text node should constrain its width to the width of + * its text */ public boolean isConstrainWidthToTextWidth() { return constrainWidthToTextWidth; } /** - * Set to <code>true</code> if this text node should constrain its width the width of its text. - * - * @param constrainWidthToTextWidth true if this text node should constrain its width to the width of its text + * Set to <code>true</code> if this text node should constrain its width the + * width of its text. + * + * @param constrainWidthToTextWidth true if this text node should constrain + * its width to the width of its text */ public void setConstrainWidthToTextWidth(final boolean constrainWidthToTextWidth) { this.constrainWidthToTextWidth = constrainWidthToTextWidth; @@ -225,19 +242,22 @@ } /** - * Return true if this text node should constrain its height to the height of its text. - * Defaults to <code>true</code>. - * - * @return true if this text node should constrain its height to the height of its text + * Return true if this text node should constrain its height to the height + * of its text. Defaults to <code>true</code>. + * + * @return true if this text node should constrain its height to the height + * of its text */ public boolean isConstrainHeightToTextHeight() { return constrainHeightToTextHeight; } /** - * Set to <code>true</code> if this text node should constrain its height the height of its text. - * - * @param constrainHeightToTextHeight true if this text node should constrain its height to the width of its height + * Set to <code>true</code> if this text node should constrain its height + * the height of its text. + * + * @param constrainHeightToTextHeight true if this text node should + * constrain its height to the width of its height */ public void setConstrainHeightToTextHeight(final boolean constrainHeightToTextHeight) { this.constrainHeightToTextHeight = constrainHeightToTextHeight; @@ -245,10 +265,10 @@ } /** - * Return the greek threshold in screen font size. When the screen font size will be - * below this threshold the text is rendered as 'greek' instead of drawing - * the text glyphs. Defaults to {...@link DEFAULT_GREEK_THRESHOLD}. - * + * Return the greek threshold in screen font size. When the screen font size + * will be below this threshold the text is rendered as 'greek' instead of + * drawing the text glyphs. Defaults to {...@link DEFAULT_GREEK_THRESHOLD}. + * * @return the current greek threshold in screen font size */ public double getGreekThreshold() { @@ -256,9 +276,10 @@ } /** - * Set the greek threshold in screen font size to <code>greekThreshold</code>. When the - * screen font size will be below this threshold the text is rendered as 'greek' instead of drawing the - * text glyphs. + * Set the greek threshold in screen font size to + * <code>greekThreshold</code>. When the screen font size will be below this + * threshold the text is rendered as 'greek' instead of drawing the text + * glyphs. * * @param greekThreshold greek threshold in screen font size */ @@ -268,8 +289,8 @@ } /** - * Return the text for this text node. Defaults to {...@link #DEFAULT_TEXT}. - * + * Return the text for this text node. Defaults to {...@link #DEFAULT_TEXT}. + * * @return the text for this text node */ public String getText() { @@ -277,11 +298,14 @@ } /** - * Set the text for this node to <code>text</code>. The text will be broken up into multiple - * lines based on the size of the text and the bounds width of this node. - * - * <p>This is a <b>bound</b> property.</p> - * + * Set the text for this node to <code>text</code>. The text will be broken + * up into multiple lines based on the size of the text and the bounds width + * of this node. + * + * <p> + * This is a <b>bound</b> property. + * </p> + * * @param text text for this text node */ public void setText(final String text) { @@ -297,8 +321,8 @@ } /** - * Return the font for this text node. Defaults to {...@link #DEFAULT_FONT}. - * + * Return the font for this text node. Defaults to {...@link #DEFAULT_FONT}. + * * @return the font for this text node */ public Font getFont() { @@ -306,12 +330,15 @@ } /** - * Set the font for this text node to <code>font</code>. Note that in Piccolo if you want to change - * the size of a text object it's often a better idea to scale the PText node instead of changing the font - * size to get that same effect. Using very large font sizes can slow performance. - * - * <p>This is a <b>bound</b> property.</p> - * + * Set the font for this text node to <code>font</code>. Note that in + * Piccolo if you want to change the size of a text object it's often a + * better idea to scale the PText node instead of changing the font size to + * get that same effect. Using very large font sizes can slow performance. + * + * <p> + * This is a <b>bound</b> property. + * </p> + * * @param font font for this text node */ public void setFont(final Font font) { @@ -389,14 +416,14 @@ } /** - * Compute the next layout using the specified line break measurer, available width, - * and next line break offset. - * + * Compute the next layout using the specified line break measurer, + * available width, and next line break offset. + * * @param lineBreakMeasurer line break measurer * @param availableWidth available width * @param nextLineBreakOffset next line break offset - * @return the next layout computed using the specified line break measurer, available width, - * and next line break offset + * @return the next layout computed using the specified line break measurer, + * available width, and next line break offset */ protected TextLayout computeNextLayout(final LineBreakMeasurer lineBreakMeasurer, final float availableWidth, final int nextLineBreakOffset) { @@ -405,7 +432,7 @@ /** * Paint greek with the specified paint context. - * + * * @param paintContext paint context */ protected void paintGreek(final PPaintContext paintContext) { @@ -414,7 +441,7 @@ /** * Paint text with the specified paint context. - * + * * @param paintContext paint context */ protected void paintText(final PPaintContext paintContext) { ======================================= --- /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java Wed Jul 29 12:09:45 2009 +++ /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java Thu Jul 30 02:15:41 2009 @@ -53,7 +53,6 @@ import edu.umd.cs.piccolo.activities.PTransformActivity; import edu.umd.cs.piccolo.activities.PColorActivity.Target; import edu.umd.cs.piccolo.event.PBasicInputEventHandler; -import edu.umd.cs.piccolo.event.PInputEvent; import edu.umd.cs.piccolo.util.PAffineTransform; import edu.umd.cs.piccolo.util.PAffineTransformException; import edu.umd.cs.piccolo.util.PBounds; @@ -1292,25 +1291,25 @@ node.setOccluded(true); assertTrue(node.getOccluded()); } - + public void testHiddenNodesAreNotPickable() { - PCanvas canvas = new PCanvas(); + final PCanvas canvas = new PCanvas(); canvas.setBounds(0, 0, 400, 400); - canvas.setPreferredSize(new Dimension(400, 400)); - PNode node1 = new PNode(); + canvas.setPreferredSize(new Dimension(400, 400)); + final PNode node1 = new PNode(); node1.setBounds(0, 0, 100, 100); node1.setPaint(Color.RED); - canvas.getLayer().addChild(node1); - - PNode node2 = (PNode) node1.clone(); + canvas.getLayer().addChild(node1); + + final PNode node2 = (PNode) node1.clone(); node2.setPaint(Color.BLUE); - - PLayer layer2 = new PLayer(); + + final PLayer layer2 = new PLayer(); layer2.addChild(node2); layer2.setVisible(false); canvas.getCamera().addLayer(layer2); - - PPickPath path = canvas.getCamera().pick(5, 5, 5); - assertSame(node1, path.getPickedNode()); + + final PPickPath path = canvas.getCamera().pick(5, 5, 5); + assertSame(node1, path.getPickedNode()); } } ======================================= --- /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/event/PInputEventFilterTest.java Tue Jul 28 12:46:54 2009 +++ /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/event/PInputEventFilterTest.java Thu Jul 30 02:15:41 2009 @@ -1,3 +1,30 @@ +/* + * Copyright (c) 2008-2009, Piccolo2D project, http://piccolo2d.org + * 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 edu.umd.cs.piccolo.event; import java.awt.event.InputEvent; @@ -15,6 +42,17 @@ public void setUp() { filter = new PInputEventFilter(); } + + // http://code.google.com/p/piccolo2d/issues/detail?id=116 + public void testPreventCodeCleanFinal() { + final int pre = PInputEventFilter.ALL_MODIFIERS_MASK; + try { + PInputEventFilter.ALL_MODIFIERS_MASK = 0; + } + finally { + PInputEventFilter.ALL_MODIFIERS_MASK = pre; + } + } public void testAcceptsAlreadyHandledEventsFalseByDefault() { assertFalse(filter.getAcceptsAlreadyHandledEvents()); ======================================= --- /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java Wed Jul 29 19:55:26 2009 +++ /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java Thu Jul 30 02:15:41 2009 @@ -116,37 +116,37 @@ try { textNode.setHorizontalAlignment(-2.0f); } - catch (IllegalArgumentException e) { + catch (final IllegalArgumentException e) { // expected } try { textNode.setHorizontalAlignment(2.0f); } - catch (IllegalArgumentException e) { + catch (final IllegalArgumentException e) { // expected } try { textNode.setHorizontalAlignment(-Float.MAX_VALUE); } - catch (IllegalArgumentException e) { + catch (final IllegalArgumentException e) { // expected } try { textNode.setHorizontalAlignment(Float.MAX_VALUE); } - catch (IllegalArgumentException e) { + catch (final IllegalArgumentException e) { // expected } try { textNode.setHorizontalAlignment(-1.00f); } - catch (IllegalArgumentException e) { + catch (final IllegalArgumentException e) { // expected } try { textNode.setHorizontalAlignment(1.00f); } - catch (IllegalArgumentException e) { + catch (final IllegalArgumentException e) { // expected } } --~--~---------~--~----~------------~-------~--~----~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~----------~----~----~----~------~----~------~--~---