Revision: 740
Author: allain.lalonde
Date: Mon Oct 19 06:45:38 2009
Log: Removing check for headless mode in tests. w00t.
http://code.google.com/p/piccolo2d/source/detail?r=740

Deleted:
   
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/SWTTest.java
Modified:
   
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTBoundsHandleTest.java
   
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTCanvasTest.java
   
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTHandleTest.java
   
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTImageTest.java
   
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTTextTest.java

=======================================
---  
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/SWTTest.java    
 
Fri Oct 16 09:14:56 2009
+++ /dev/null
@@ -1,25 +0,0 @@
-package edu.umd.cs.piccolox.swt;
-
-import java.awt.GraphicsEnvironment;
-
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-import junit.framework.TestCase;
-
-public abstract class SWTTest extends TestCase {
-       public final boolean isHeadless() {
-               return GraphicsEnvironment.isHeadless();
-       }
-
-       protected final boolean hasHead() {
-               return !isHeadless();
-       }
-
-       protected PSWTCanvas buildSimpleCanvas(Display display) {
-               final Shell shell = new Shell(display);
-               shell.setLayout(new FillLayout());
-               return new PSWTCanvas(shell, 0);
-       }
-}
=======================================
---  
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTBoundsHandleTest.java
        
Fri Oct 16 13:34:43 2009
+++  
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTBoundsHandleTest.java
        
Mon Oct 19 06:45:38 2009
@@ -1,76 +1,65 @@
  package edu.umd.cs.piccolox.swt;

+import junit.framework.TestCase;
  import edu.umd.cs.piccolo.PCamera;
  import edu.umd.cs.piccolo.PNode;
  import edu.umd.cs.piccolo.event.PInputEventListener;
  import edu.umd.cs.piccolox.util.PBoundsLocator;

-public class PSWTBoundsHandleTest extends SWTTest {
+public class PSWTBoundsHandleTest extends TestCase {
      private PNode node;

      public void setUp() {
-        if (hasHead()) {
-            node = new PNode();
-            node.setBounds(0, 0, 100, 100);
-        }
+        node = new PNode();
+        node.setBounds(0, 0, 100, 100);
      }

      public void testAddBoundsHandlesToNodeAddsHandles() {
-        if (hasHead()) {
-            PSWTBoundsHandle.addBoundsHandlesTo(node);
-            assertEquals(8, node.getChildrenCount());
-
-            for (int i=0; i<8; i++) {
-                PNode child = node.getChild(i);
-                assertTrue(child instanceof PSWTBoundsHandle);
-            }
+        PSWTBoundsHandle.addBoundsHandlesTo(node);
+        assertEquals(8, node.getChildrenCount());
+
+        for (int i = 0; i < 8; i++) {
+            PNode child = node.getChild(i);
+            assertTrue(child instanceof PSWTBoundsHandle);
          }
      }
-
+
      public void testAddStickyBoundsHandlesToNodeAddsHandles() {
-        if (hasHead()) {
-            PCamera camera = new PCamera();
-            PSWTBoundsHandle.addStickyBoundsHandlesTo(node, camera);
-            assertEquals(0, node.getChildrenCount());
-            assertEquals(8, camera.getChildrenCount());
-
-            for (int i=0; i<8; i++) {
-                PNode child = camera.getChild(i);
-                assertTrue(child instanceof PSWTBoundsHandle);
-            }
+        PCamera camera = new PCamera();
+        PSWTBoundsHandle.addStickyBoundsHandlesTo(node, camera);
+        assertEquals(0, node.getChildrenCount());
+        assertEquals(8, camera.getChildrenCount());
+
+        for (int i = 0; i < 8; i++) {
+            PNode child = camera.getChild(i);
+            assertTrue(child instanceof PSWTBoundsHandle);
          }
      }
-
+
      public void testRemoveBoundsHandlesRemovesOnlyHandles() {
-        if (hasHead()) {
-            PNode child = new PNode();
-            node.addChild(child);
-            PSWTBoundsHandle.addBoundsHandlesTo(node);
-            PSWTBoundsHandle.removeBoundsHandlesFrom(node);
-            assertEquals(1, node.getChildrenCount());
-            assertEquals(child, node.getChild(0));
-        }
-    }
-
+        PNode child = new PNode();
+        node.addChild(child);
+        PSWTBoundsHandle.addBoundsHandlesTo(node);
+        PSWTBoundsHandle.removeBoundsHandlesFrom(node);
+        assertEquals(1, node.getChildrenCount());
+        assertEquals(child, node.getChild(0));
+    }
+
      public void testRemoveBoundsHandlesDoesNothingWhenNoHandles() {
-        if (hasHead()) {
-            PNode child = new PNode();
-            node.addChild(child);
-            PSWTBoundsHandle.removeBoundsHandlesFrom(node);
-            assertEquals(1, node.getChildrenCount());
-        }
-    }
-
+        PNode child = new PNode();
+        node.addChild(child);
+        PSWTBoundsHandle.removeBoundsHandlesFrom(node);
+        assertEquals(1, node.getChildrenCount());
+    }
+
      public void testCursorHandlerIsInstalledByDefault() {
-        if (hasHead()) {
-            PSWTBoundsHandle handle = new  
PSWTBoundsHandle(PBoundsLocator.createEastLocator(node));
-            PInputEventListener dragHandler =  
handle.getHandleDraggerHandler();
-            PInputEventListener cursorHandler =  
handle.getHandleCursorEventHandler();
-            assertNotNull(cursorHandler);
-            PInputEventListener[] listeners =  
handle.getInputEventListeners();
-            assertEquals(2, listeners.length);
-            assertTrue(cursorHandler == listeners[0] || cursorHandler ==  
listeners[1]);
-            assertTrue(dragHandler == listeners[0] || dragHandler ==  
listeners[1]);
-        }
-    }
-}
+        PSWTBoundsHandle handle = new  
PSWTBoundsHandle(PBoundsLocator.createEastLocator(node));
+        PInputEventListener dragHandler = handle.getHandleDraggerHandler();
+        PInputEventListener cursorHandler =  
handle.getHandleCursorEventHandler();
+        assertNotNull(cursorHandler);
+        PInputEventListener[] listeners = handle.getInputEventListeners();
+        assertEquals(2, listeners.length);
+        assertTrue(cursorHandler == listeners[0] || cursorHandler ==  
listeners[1]);
+        assertTrue(dragHandler == listeners[0] || dragHandler ==  
listeners[1]);
+    }
+}
=======================================
---  
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTCanvasTest.java
      
Fri Oct 16 13:34:43 2009
+++  
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTCanvasTest.java
      
Mon Oct 19 06:45:38 2009
@@ -1,95 +1,82 @@
  package edu.umd.cs.piccolox.swt;

+import junit.framework.TestCase;
+
+import org.eclipse.swt.layout.FillLayout;
  import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;

  import edu.umd.cs.piccolo.event.PInputEventListener;
  import edu.umd.cs.piccolo.event.PPanEventHandler;
  import edu.umd.cs.piccolo.event.PZoomEventHandler;

-public class PSWTCanvasTest extends SWTTest {
+public class PSWTCanvasTest extends TestCase {
      private PSWTCanvas canvas;

-    public void setUp() {
-        if (hasHead()) {
-            canvas = buildSimpleCanvas(Display.getDefault());
-        }
-    }
-
+    public void setUp() {
+        final Shell shell = new Shell(Display.getDefault());
+        shell.setLayout(new FillLayout());
+        canvas = new PSWTCanvas(shell, 0);
+    }
+
      public void testPanEventListenerIsInstalledByDefault() {
-        if (hasHead()) {
-            PPanEventHandler handler = canvas.getPanEventHandler();
-            assertNotNull(handler);
-
-            int handlerIndex = getHandlerIndex(handler);
-            assertFalse("Pan Event Handler not installed", handlerIndex ==  
-1);
-        }
+        PPanEventHandler handler = canvas.getPanEventHandler();
+        assertNotNull(handler);
+
+        int handlerIndex = getHandlerIndex(handler);
+        assertFalse("Pan Event Handler not installed", handlerIndex == -1);
      }

-    private int getHandlerIndex(PInputEventListener handler) {
+    public void testZoomEventListenerIsInstalledByDefault() {
+        PZoomEventHandler handler = canvas.getZoomEventHandler();
+        assertNotNull(handler);
+
+        int handlerIndex = getHandlerIndex(handler);
+        assertFalse("Zoom Event Handler not installed", handlerIndex ==  
-1);
+    }
+
+    private int getHandlerIndex(PInputEventListener handler) {
          PInputEventListener[] listeners =  
canvas.getCamera().getInputEventListeners();
          int handlerIndex = -1;
-        for (int i=0; i<listeners.length; i++) {
+        for (int i = 0; i < listeners.length; i++) {
              if (listeners[i] == handler) {
                  handlerIndex = i;
              }
          }
          return handlerIndex;
      }
-
-    public void testZoomEventListenerIsInstalledByDefault() {
-        if (hasHead()) {
-            PZoomEventHandler handler = canvas.getZoomEventHandler();
-            assertNotNull(handler);
-
-            int handlerIndex = getHandlerIndex(handler);
-            assertFalse("Zoom Event Handler not installed", handlerIndex  
== -1);
-        }
-    }
-
+
      public void testAnimatingDefaultsToFalse() {
-        if (hasHead()) {
-            assertFalse(canvas.getAnimating());
-        }
-    }
-
+        assertFalse(canvas.getAnimating());
+    }
+
      public void testInteractingDefaultsToFalse() {
-        if (hasHead()) {
-            assertFalse(canvas.getInteracting());
-        }
-    }
-
+        assertFalse(canvas.getInteracting());
+    }
+
      public void testInteractingWorksByCountingCallsToSetInteracting() {
-        if (hasHead()) {
-            canvas.setInteracting(true);
-            assertTrue(canvas.getInteracting());
-
-            canvas.setInteracting(true);
-            assertTrue(canvas.getInteracting());
-
-            canvas.setInteracting(false);
-            //This is terrible
-            assertTrue(canvas.getInteracting());
-
-            canvas.setInteracting(false);
-            assertFalse(canvas.getInteracting());
-
-        }
-    }
-
+        canvas.setInteracting(true);
+        assertTrue(canvas.getInteracting());
+
+        canvas.setInteracting(true);
+        assertTrue(canvas.getInteracting());
+
+        canvas.setInteracting(false);
+        // This is terrible
+        assertTrue(canvas.getInteracting());
+
+        canvas.setInteracting(false);
+        assertFalse(canvas.getInteracting());
+    }
+
      public void testCanvasIsDoubleBufferedByDefault() {
-        if (hasHead()) {
-            assertTrue(canvas.getDoubleBuffered());
-        }
-    }
-
-
+        assertTrue(canvas.getDoubleBuffered());
+    }
+
      public void testDoubleBufferingPersists() {
-        if (hasHead()) {
-            canvas.setDoubleBuffered(false);
-            assertFalse(canvas.getDoubleBuffered());
-            canvas.setDoubleBuffered(true);
-            assertTrue(canvas.getDoubleBuffered());
-        }
-    }
-
-}
+        canvas.setDoubleBuffered(false);
+        assertFalse(canvas.getDoubleBuffered());
+        canvas.setDoubleBuffered(true);
+        assertTrue(canvas.getDoubleBuffered());
+    }
+}
=======================================
---  
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTHandleTest.java
      
Fri Oct 16 12:15:32 2009
+++  
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTHandleTest.java
      
Mon Oct 19 06:45:38 2009
@@ -1,66 +1,57 @@
  package edu.umd.cs.piccolox.swt;

+import junit.framework.TestCase;
  import edu.umd.cs.piccolo.PNode;
  import edu.umd.cs.piccolo.event.PInputEventListener;
  import edu.umd.cs.piccolox.util.PBoundsLocator;
  import edu.umd.cs.piccolox.util.PLocator;

-public class PSWTHandleTest extends SWTTest {
+public class PSWTHandleTest extends TestCase {
      private PNode node;
      private PSWTHandle handle;
      private PBoundsLocator locator;

      public void setUp() throws Exception {
-        if (hasHead()) {
-            node = new PNode();
-            locator = PBoundsLocator.createEastLocator(node);
-            handle = new PSWTHandle(locator);
-            node.setBounds(0, 0, 100, 100);
-            node.addChild(handle);
-        }
+        node = new PNode();
+        locator = PBoundsLocator.createEastLocator(node);
+        handle = new PSWTHandle(locator);
+        node.setBounds(0, 0, 100, 100);
+        node.addChild(handle);
      }

      public void testDefaultsAreCorrect() {
-        if (hasHead()) {
-            assertEquals(PSWTHandle.DEFAULT_COLOR, handle.getPaint());
-            assertEquals(PSWTHandle.DEFAULT_HANDLE_SIZE + 2 /** for border  
pen */
-            , handle.getHeight(), Float.MIN_VALUE);
-        }
+        assertEquals(PSWTHandle.DEFAULT_COLOR, handle.getPaint());
+        assertEquals(PSWTHandle.DEFAULT_HANDLE_SIZE + 2 /** for border pen  
*/
+        , handle.getHeight(), Float.MIN_VALUE);
      }

      public void testLocatorPersists() {
-        if (hasHead()) {
-            assertSame(locator, handle.getLocator());
-
-            PLocator newLocator = PBoundsLocator.createWestLocator(node);
-            handle.setLocator(newLocator);
-            assertSame(newLocator, handle.getLocator());
-        }
+        assertSame(locator, handle.getLocator());
+
+        PLocator newLocator = PBoundsLocator.createWestLocator(node);
+        handle.setLocator(newLocator);
+        assertSame(newLocator, handle.getLocator());
      }

      public void testHandleHasDragHandlerInstalled() {
-        if (hasHead()) {
-            PInputEventListener dragHandler =  
handle.getHandleDraggerHandler();
-            assertNotNull(dragHandler);
-
-            PInputEventListener[] installedListeners =  
handle.getInputEventListeners();
-            assertEquals(1, installedListeners.length);
-            assertSame(dragHandler, installedListeners[0]);
-        }
+        PInputEventListener dragHandler = handle.getHandleDraggerHandler();
+        assertNotNull(dragHandler);
+
+        PInputEventListener[] installedListeners =  
handle.getInputEventListeners();
+        assertEquals(1, installedListeners.length);
+        assertSame(dragHandler, installedListeners[0]);
      }

      public void testChangingParentDoesNotChangeLocatorNode() {
-        if (hasHead()) {
-            handle.relocateHandle();
-            PNode newParent = new PNode();
-            newParent.setBounds(50, 50, 100, 100);
-
-            final double originalX = handle.getX();
-            handle.setParent(newParent);
-
-            final double newX = handle.getX();
-
-            assertEquals(newX, originalX, Double.MIN_VALUE);
-        }
+        handle.relocateHandle();
+        PNode newParent = new PNode();
+        newParent.setBounds(50, 50, 100, 100);
+
+        final double originalX = handle.getX();
+        handle.setParent(newParent);
+
+        final double newX = handle.getX();
+
+        assertEquals(newX, originalX, Double.MIN_VALUE);
      }
  }
=======================================
---  
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTImageTest.java
       
Fri Oct 16 09:14:56 2009
+++  
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTImageTest.java
       
Mon Oct 19 06:45:38 2009
@@ -2,57 +2,53 @@

  import java.io.File;

+import junit.framework.TestCase;
+
  import org.eclipse.swt.graphics.Image;
  import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
  import org.eclipse.swt.widgets.Display;
-
-public class PSWTImageTest extends SWTTest {
-       File imageFile;
-       PSWTCanvas canvas;
-       PSWTImage imageNode;
-       Image image;
-
-       public void setUp() throws Exception {
-               if (hasHead()) {
-                       final Display display = Display.getDefault();
-                       canvas = buildSimpleCanvas(display);
-                       imageNode = new PSWTImage(canvas);
-                       image = new Image(display, new Rectangle(0, 0, 100, 
100));
-               }
-       }
-
-       public void testImageShouldDefaultToNull() {
-               if (hasHead()) {
-                       assertNull(imageNode.getImage());
-               }
-       }
-
-       public void testPaintShouldDoNothingWhenImageIsNull() {
-               if (hasHead()) {
-                       // if it tries to use the graphics context, it would 
throw a NPE
-                       imageNode.paint(null);
-               }
-       }
-
-       public void testImageInConstructorPersists() {
-               if (hasHead()) {
-                       imageNode = new PSWTImage(canvas, image);
-                       assertSame(image, imageNode.getImage());
-               }
-       }
-
-       public void testDisposingCanvasDisposesImage() {
-               if (hasHead()) {
-                       final boolean[] called = new boolean[1];
-                       called[0] = false;
-                       imageNode = new PSWTImage(canvas, image) {
-                               protected void disposeImage() {
-                                       called[0] = true;
-                                       super.disposeImage();
-                               }
-                       };
-                       canvas.dispose();
-                       assertTrue(called[0]);
-               }
-       }
-}
+import org.eclipse.swt.widgets.Shell;
+
+public class PSWTImageTest extends TestCase {
+    File imageFile;
+    PSWTCanvas canvas;
+    PSWTImage imageNode;
+    Image image;
+
+    public void setUp() throws Exception {
+        final Display display = Display.getDefault();
+        final Shell shell = new Shell(display);
+        shell.setLayout(new FillLayout());
+        canvas = new PSWTCanvas(shell, 0);
+        imageNode = new PSWTImage(canvas);
+        image = new Image(display, new Rectangle(0, 0, 100, 100));
+    }
+
+    public void testImageShouldDefaultToNull() {
+        assertNull(imageNode.getImage());
+    }
+
+    public void testPaintShouldDoNothingWhenImageIsNull() {
+        // if it tries to use the graphics context, it would throw a NPE
+        imageNode.paint(null);
+    }
+
+    public void testImageInConstructorPersists() {
+        imageNode = new PSWTImage(canvas, image);
+        assertSame(image, imageNode.getImage());
+    }
+
+    public void testDisposingCanvasDisposesImage() {
+        final boolean[] called = new boolean[1];
+        called[0] = false;
+        imageNode = new PSWTImage(canvas, image) {
+            protected void disposeImage() {
+                called[0] = true;
+                super.disposeImage();
+            }
+        };
+        canvas.dispose();
+        assertTrue(called[0]);
+    }
+}
=======================================
---  
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTTextTest.java
        
Mon Oct 19 06:30:11 2009
+++  
/piccolo2d.java/trunk/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTTextTest.java
        
Mon Oct 19 06:45:38 2009
@@ -4,151 +4,122 @@
  import java.awt.Font;
  import java.awt.geom.Point2D;

+import junit.framework.TestCase;
  import edu.umd.cs.piccolo.util.PBounds;

-public class PSWTTextTest extends SWTTest {
-       private PSWTText textNode;
-
-       public void setUp() {
-               textNode = new PSWTText();
-       }
-
-       public void testConstructorRemembersTextValue() {
-               if (hasHead()) {
-                       textNode = new PSWTText("Hello World\n\n");
-                       assertEquals("Hello World\n\n", textNode.getText());
-               }
-       }
-
-       public void testTextPersistsTrainingAndInternalNewlines() {
-               if (hasHead()) {
-                       textNode.setText("Hello\nWorld\n\n");
-                       assertEquals("Hello\nWorld\n\n", textNode.getText());
-               }
-       }
-
-       public void testDefaultPropertiesAreCorrect() {
-               if (hasHead()) {
-                       assertEquals(Color.BLACK, textNode.getPenColor());
-                       assertEquals(Color.BLACK, textNode.getPenPaint());
-                       assertNull(textNode.getBackgroundColor());
-                       assertNull(textNode.getPaint());
-                       assertEquals(5.5, textNode.getGreekThreshold(), 
Double.MIN_VALUE);
-                       assertFalse(textNode.isTransparent());
-               }
-       }
-
-       public void testDefaultFontIsCorrect() {
-               if (hasHead()) {
-                       Font font = textNode.getFont();
-                       assertNotNull(font);
-                       assertFalse(font.isBold());
-                       assertEquals(12, font.getSize());
-               }
-       }
-
-       public void testPenColorPersists() {
-               if (hasHead()) {
-                       textNode.setPenColor(Color.RED);
-                       assertEquals(Color.RED, textNode.getPenColor());
-               }
-       }
-
-       public void testPenPaintPersists() {
-               if (hasHead()) {
-                       textNode.setPenPaint(Color.RED);
-                       assertEquals(Color.RED, textNode.getPenPaint());
-               }
-       }
-
-       public void testTransparencyPersists() {
-               if (hasHead()) {
-                       textNode.setTransparent(true);
-                       assertTrue(textNode.isTransparent());
-               }
-       }
-
-       public void testBackgroundColor() {
-               if (hasHead()) {
-                       textNode.setBackgroundColor(Color.RED);
-                       assertEquals(Color.RED, textNode.getBackgroundColor());
-               }
-       }
-
-       public void testPenPaintAndPenColorAreSameThing() {
-               if (hasHead()) {
-                       textNode.setPenColor(Color.RED);
-                       assertEquals(Color.RED, textNode.getPenPaint());
-
-                       textNode.setPenPaint(Color.BLUE);
-                       assertEquals(Color.BLUE, textNode.getPenColor());
-               }
-       }
-
-       public void testBackgroundColorAndPaintAreSameThing() {
-               if (hasHead()) {
-                       textNode.setBackgroundColor(Color.RED);
-                       assertEquals(Color.RED, textNode.getPaint());
-
-                       textNode.setPaint(Color.BLUE);
-                       assertEquals(Color.BLUE, textNode.getBackgroundColor());
-               }
-       }
-
-       public void testGreekThresholdPersists() {
-               if (hasHead()) {
-                       textNode.setGreekThreshold(0.1);
-                       assertEquals(0.1, textNode.getGreekThreshold(), 
Double.MIN_VALUE);
-               }
-       }
-
-       public void testShrinkingFontShrinksBounds() {
-               if (hasHead()) {
-                       textNode.setText("Hello\nWorld");
-
-                       PBounds startBounds = textNode.getBounds();
-                       Font startFont = textNode.getFont();
-                       Font newFont = new Font(startFont.getFontName(), 
startFont
-                                       .getStyle(), 8);
-
-                       textNode.setFont(newFont);
-                       assertSame(newFont, textNode.getFont());
-
-                       PBounds endBounds = textNode.getBounds();
-                       assertTrue(startBounds.width > endBounds.width);
-                       assertTrue(startBounds.height > endBounds.height);
-               }
-       }
-
-       public void testTranslationsBehaveLogically() {
-               if (hasHead()) {
-                       textNode.setTranslation(1, 2);
-                       assertEquals(1, textNode.getTranslateX(), 
Double.MIN_VALUE);
-                       assertEquals(2, textNode.getTranslateY(), 
Double.MIN_VALUE);
-
-                       textNode.setTranslateX(3);
-                       assertEquals(3, textNode.getTranslateX(), 
Double.MIN_VALUE);
-
-                       textNode.setTranslateY(4);
-                       assertEquals(4, textNode.getTranslateY(), 
Double.MIN_VALUE);
-
-                       assertEquals(new Point2D.Double(3, 4), 
textNode.getTranslation());
-
-                       textNode.setTranslation(new Point2D.Double(5,6));
-                       assertEquals(new Point2D.Double(5,6), 
textNode.getTranslation());
-               }
-       }
-
-       public void testTranslatingDoesntAffectSize() {
-               if (hasHead()) {
-                       textNode.setText("Hello");
-                       PBounds startBounds = textNode.getBounds();
-                       textNode.translate(1, 2);
-                       PBounds endBounds = textNode.getBounds();
-                       assertEquals(startBounds.width, endBounds.width, 
Double.MIN_VALUE);
-                       assertEquals(startBounds.height, endBounds.height, 
Double.MIN_VALUE);
-
-               }
-       }
+public class PSWTTextTest extends TestCase {
+    private PSWTText textNode;
+
+    public void setUp() {
+        textNode = new PSWTText();
+    }
+
+    public void testConstructorRemembersTextValue() {
+        textNode = new PSWTText("Hello World\n\n");
+        assertEquals("Hello World\n\n", textNode.getText());
+    }
+
+    public void testTextPersistsTrainingAndInternalNewlines() {
+        textNode.setText("Hello\nWorld\n\n");
+        assertEquals("Hello\nWorld\n\n", textNode.getText());
+    }
+
+    public void testDefaultPropertiesAreCorrect() {
+        assertEquals(Color.BLACK, textNode.getPenColor());
+        assertEquals(Color.BLACK, textNode.getPenPaint());
+        assertNull(textNode.getBackgroundColor());
+        assertNull(textNode.getPaint());
+        assertEquals(5.5, textNode.getGreekThreshold(), Double.MIN_VALUE);
+        assertFalse(textNode.isTransparent());
+    }
+
+    public void testDefaultFontIsCorrect() {
+        Font font = textNode.getFont();
+        assertNotNull(font);
+        assertFalse(font.isBold());
+        assertEquals(12, font.getSize());
+    }
+
+    public void testPenColorPersists() {
+        textNode.setPenColor(Color.RED);
+        assertEquals(Color.RED, textNode.getPenColor());
+    }
+
+    public void testPenPaintPersists() {
+        textNode.setPenPaint(Color.RED);
+        assertEquals(Color.RED, textNode.getPenPaint());
+    }
+
+    public void testTransparencyPersists() {
+        textNode.setTransparent(true);
+        assertTrue(textNode.isTransparent());
+    }
+
+    public void testBackgroundColor() {
+        textNode.setBackgroundColor(Color.RED);
+        assertEquals(Color.RED, textNode.getBackgroundColor());
+    }
+
+    public void testPenPaintAndPenColorAreSameThing() {
+        textNode.setPenColor(Color.RED);
+        assertEquals(Color.RED, textNode.getPenPaint());
+
+        textNode.setPenPaint(Color.BLUE);
+        assertEquals(Color.BLUE, textNode.getPenColor());
+    }
+
+    public void testBackgroundColorAndPaintAreSameThing() {
+        textNode.setBackgroundColor(Color.RED);
+        assertEquals(Color.RED, textNode.getPaint());
+
+        textNode.setPaint(Color.BLUE);
+        assertEquals(Color.BLUE, textNode.getBackgroundColor());
+    }
+
+    public void testGreekThresholdPersists() {
+        textNode.setGreekThreshold(0.1);
+        assertEquals(0.1, textNode.getGreekThreshold(), Double.MIN_VALUE);
+    }
+
+    public void testShrinkingFontShrinksBounds() {
+        textNode.setText("Hello\nWorld");
+
+        PBounds startBounds = textNode.getBounds();
+        Font startFont = textNode.getFont();
+        Font newFont = new Font(startFont.getFontName(),  
startFont.getStyle(), 8);
+
+        textNode.setFont(newFont);
+        assertSame(newFont, textNode.getFont());
+
+        PBounds endBounds = textNode.getBounds();
+        assertTrue(startBounds.width > endBounds.width);
+        assertTrue(startBounds.height > endBounds.height);
+    }
+
+    public void testTranslationsBehaveLogically() {
+        textNode.setTranslation(1, 2);
+        assertEquals(1, textNode.getTranslateX(), Double.MIN_VALUE);
+        assertEquals(2, textNode.getTranslateY(), Double.MIN_VALUE);
+
+        textNode.setTranslateX(3);
+        assertEquals(3, textNode.getTranslateX(), Double.MIN_VALUE);
+
+        textNode.setTranslateY(4);
+        assertEquals(4, textNode.getTranslateY(), Double.MIN_VALUE);
+
+        assertEquals(new Point2D.Double(3, 4), textNode.getTranslation());
+
+        textNode.setTranslation(new Point2D.Double(5, 6));
+        assertEquals(new Point2D.Double(5, 6), textNode.getTranslation());
+    }
+
+    public void testTranslatingDoesntAffectSize() {
+        textNode.setText("Hello");
+        PBounds startBounds = textNode.getBounds();
+        textNode.translate(1, 2);
+        PBounds endBounds = textNode.getBounds();
+        assertEquals(startBounds.width, endBounds.width, Double.MIN_VALUE);
+        assertEquals(startBounds.height, endBounds.height,  
Double.MIN_VALUE);
+    }

  }

--~--~---------~--~----~------------~-------~--~----~
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to