modules/graphics/src/test/java/test/javafx/scene/ParentTest.java

Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:

@@ -21,16 +21,22 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
-package javafx.scene;
+package test.javafx.scene;
 
-import com.sun.javafx.pgstub.StubToolkit;
+import test.com.sun.javafx.pgstub.StubToolkit;
 import com.sun.javafx.sg.prism.NGGroup;
 import com.sun.javafx.tk.Toolkit;
 import java.util.concurrent.atomic.AtomicBoolean;
+import javafx.scene.Group;
+import javafx.scene.GroupShim;
+import javafx.scene.Node;
+import javafx.scene.Parent;
+import javafx.scene.ParentShim;
+import javafx.scene.Scene;
 import javafx.scene.shape.Rectangle;
 import javafx.stage.Stage;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;

@@ -142,30 +148,30 @@
         Group g = new Group();
         Scene s = new Scene(g);
         stage.setScene(s);
         stage.show();
 
-        g.getChildren().addAll(rect1, rect2, rect3, rect4, rect5, rect6);
+        ParentShim.getChildren(g).addAll(rect1, rect2, rect3, rect4, rect5, rect6);
         toolkit.fireTestPulse();
 
         // try removing node from the end of the observableArrayList
-        g.getChildren().remove(rect6);
+        ParentShim.getChildren(g).remove(rect6);
         toolkit.fireTestPulse();
         final NGGroup peer = g.impl_getPeer();
-        assertEquals(5, g.getChildren().size());
+        assertEquals(5, ParentShim.getChildren(g).size());
         assertEquals(5, peer.getChildren().size());
 
         // try removing node from the beginning of the observableArrayList
-        g.getChildren().remove(rect1);
+        ParentShim.getChildren(g).remove(rect1);
         toolkit.fireTestPulse();
-        assertEquals(4, g.getChildren().size());
+        assertEquals(4, ParentShim.getChildren(g).size());
         assertEquals(4, peer.getChildren().size());
 
         // try removing node from the middle of the observableArrayList
-        g.getChildren().remove(rect3);
+        ParentShim.getChildren(g).remove(rect3);
         toolkit.fireTestPulse();
-        assertEquals(3, g.getChildren().size());
+        assertEquals(3, ParentShim.getChildren(g).size());
         assertEquals(3, peer.getChildren().size());
     }
 
     @Test
     public void testSetChild() {

@@ -176,17 +182,17 @@
         Group g = new Group();
         Scene s = new Scene(g);
         stage.setScene(s);
         stage.show();
 
-        g.getChildren().addAll(rect1, rect2);
+        ParentShim.getChildren(g).addAll(rect1, rect2);
         toolkit.fireTestPulse();
 
         // try setting node at given index
-        g.getChildren().set(1, rect3);
+        ParentShim.getChildren(g).set(1, rect3);
         toolkit.fireTestPulse();
-        assertEquals(2, g.getChildren().size());
+        assertEquals(2, ParentShim.getChildren(g).size());
         assertEquals(2, ((NGGroup)g.impl_getPeer()).getChildren().size());
     }
 
     @Test
     public void testSetSameChild() {

@@ -196,18 +202,18 @@
         Group g = new Group();
         Scene s = new Scene(g);
         stage.setScene(s);
         stage.show();
 
-        g.getChildren().addAll(rect1, rect2);
+        ParentShim.getChildren(g).addAll(rect1, rect2);
         toolkit.fireTestPulse();
 
         // try setting the same node at given index
-        g.getChildren().set(1, rect2);
+        ParentShim.getChildren(g).set(1, rect2);
 
         toolkit.fireTestPulse();
-        assertEquals(2, g.getChildren().size());
+        assertEquals(2, ParentShim.getChildren(g).size());
         assertEquals(2, ((NGGroup)g.impl_getPeer()).getChildren().size());
     }
 
     @Test
     public void testRemoveAddSameChild() {

@@ -221,19 +227,19 @@
         Group g = new Group();
         Scene s = new Scene(g);
         stage.setScene(s);
         stage.show();
 
-        g.getChildren().addAll(rect1, rect2, rect3, rect4, rect5, rect6);
+        ParentShim.getChildren(g).addAll(rect1, rect2, rect3, rect4, rect5, rect6);
         toolkit.fireTestPulse();
 
         // try removing node from the end of the observableArrayList
         // and add it afterwords
-        g.getChildren().remove(rect6);
-        g.getChildren().add(rect6);
+        ParentShim.getChildren(g).remove(rect6);
+        ParentShim.getChildren(g).add(rect6);
         toolkit.fireTestPulse();
-        assertEquals(6, g.getChildren().size());
+        assertEquals(6, ParentShim.getChildren(g).size());
         assertEquals(6, ((NGGroup)g.impl_getPeer()).getChildren().size());
     }
 
     @Test
     public void testRemoveAddDiferentChild() {

@@ -247,30 +253,30 @@
         Group g = new Group();
         Scene s = new Scene(g);
         stage.setScene(s);
         stage.show();
 
-        g.getChildren().addAll(rect1, rect2, rect3, rect4, rect5);
+        ParentShim.getChildren(g).addAll(rect1, rect2, rect3, rect4, rect5);
         toolkit.fireTestPulse();
 
         // try removing node from the end of the observableArrayList
         // and add a different one
-        g.getChildren().remove(rect5);
-        g.getChildren().add(rect6);
+        ParentShim.getChildren(g).remove(rect5);
+        ParentShim.getChildren(g).add(rect6);
         toolkit.fireTestPulse();
-        assertEquals(5, g.getChildren().size());
+        assertEquals(5, ParentShim.getChildren(g).size());
         assertEquals(5, ((NGGroup)g.impl_getPeer()).getChildren().size());
     }
 
     @Test
     public void testGetChildrenUnmodifiable() {
         Rectangle rect1 = new Rectangle();
         Rectangle rect2 = new Rectangle();
         Rectangle rect3 = new Rectangle();
 
         Group g = new Group();
-        g.getChildren().addAll(rect1,rect2,rect3);
+        ParentShim.getChildren(g).addAll(rect1,rect2,rect3);
 
         assertEquals(3, g.getChildrenUnmodifiable().size());
         assertSame(rect1, g.getChildrenUnmodifiable().get(0));
         assertSame(rect2, g.getChildrenUnmodifiable().get(1));
         assertSame(rect3, g.getChildrenUnmodifiable().get(2));

@@ -281,11 +287,11 @@
         Rectangle rect1 = new Rectangle();
         Rectangle rect2 = new Rectangle();
         Rectangle rect3 = new Rectangle();
 
         Group g = new Group();
-        g.getChildren().addAll(rect1,rect2,rect3);
+        ParentShim.getChildren(g).addAll(rect1,rect2,rect3);
 
         try {
             g.getChildrenUnmodifiable().add(new Rectangle());
             fail("UnsupportedOperationException should have been thrown.");
         } catch (UnsupportedOperationException uoe) {

@@ -312,11 +318,11 @@
 
     @Test
     public void testRequestLayoutClearsCache() {
         Group g = new Group();
         Rectangle r = new Rectangle(100,200);
-        g.getChildren().add(r);
+        ParentShim.getChildren(g).add(r);
 
         g.requestLayout();
         assertEquals(100, g.prefWidth(-1), 1e-100);
         assertEquals(200, g.prefHeight(-1), 1e-100);
 

@@ -354,28 +360,28 @@
         Rectangle r2 = new Rectangle();
         Rectangle r3 = new Rectangle();
         Rectangle r4 = new Rectangle();
 
         try {
-        g.getChildren().addAll(r1, r2, r3, r4);
-        g.getChildren().add(r2);
+        ParentShim.getChildren(g).addAll(r1, r2, r3, r4);
+        ParentShim.getChildren(g).add(r2);
         fail();
         } catch (IllegalArgumentException e) {
 
         }
     }
 
     @Test(expected=NullPointerException.class)
     public void testAddingNullChild() {
         Group g = new Group();
-        g.getChildren().add(null);
+        ParentShim.getChildren(g).add(null);
     }
 
     @Test(expected=NullPointerException.class)
     public void testNullCheckIsDoneBeforeTestForDuplicates() {
         Group g = new Group();
-        g.getChildren().addAll(null, new Rectangle(), null);
+        ParentShim.getChildren(g).addAll(null, new Rectangle(), null);
     }
 
     @Test(expected=IllegalArgumentException.class)
     public void testAddingClipNodeTwice() {
         Group g = new Group();

@@ -384,17 +390,17 @@
         Node clipNode = new Rectangle();
 
         clipParent.setClip(clipNode);
         try {
             // try to add node which is already set as a clip
-            g.getChildren().add(clipNode);
+            ParentShim.getChildren(g).add(clipNode);
             fail();
         } catch (IllegalArgumentException e) {
         }
 
         // try again
-        g.getChildren().add(clipNode);
+        ParentShim.getChildren(g).add(clipNode);
     }
 
     @Test
     public void testAddingFixedClipNode() {
         Group g = new Group();

@@ -403,18 +409,18 @@
         Node clipNode = new Rectangle();
 
         clipParent.setClip(clipNode);
         try {
             // try to add node which is already set as a clip
-            g.getChildren().add(clipNode);
+            ParentShim.getChildren(g).add(clipNode);
             fail();
         } catch (IllegalArgumentException e) {
         }
 
         // fix the problem and add again
         clipParent.setClip(null);
-        g.getChildren().add(clipNode);
+        ParentShim.getChildren(g).add(clipNode);
     }
 
     @Test(expected=IllegalArgumentException.class)
     public void testFalsePermutation() {
         Group g = new Group();

@@ -422,12 +428,12 @@
         Rectangle r1 = new Rectangle();
         Rectangle r2 = new Rectangle();
         Rectangle r3 = new Rectangle();
         Rectangle r4 = new Rectangle();
 
-        g.getChildren().addAll(r1, r2, r3, r4);
-        g.getChildren().setAll(r1, r2, r2, r4);
+        ParentShim.getChildren(g).addAll(r1, r2, r3, r4);
+        ParentShim.getChildren(g).setAll(r1, r2, r2, r4);
     }
 
     @Test
     public void testFalseDuplicates() {
         Group g = new Group();

@@ -435,18 +441,18 @@
         Rectangle r1 = new Rectangle();
         Rectangle r2 = new Rectangle();
         Rectangle r3 = new Rectangle();
         Rectangle r4 = new Rectangle();
 
-        g.getChildren().addAll(r1, r2);
+        ParentShim.getChildren(g).addAll(r1, r2);
         try {
-            g.getChildren().addAll(r3, r4, r2);
+            ParentShim.getChildren(g).addAll(r3, r4, r2);
             fail();
         } catch (IllegalArgumentException e) {
         }
         try {
-            g.getChildren().add(r3);
+            ParentShim.getChildren(g).add(r3);
         } catch (IllegalArgumentException e) {
             fail();
         }
 
     }

@@ -456,11 +462,11 @@
         final Rectangle rect = new Rectangle(100, 100);
         final Group g = new Group(rect);
 
         Group root = new Group() {
             @Override protected void layoutChildren() {
-                getChildren().setAll(g);
+                ParentShim.getChildren(this).setAll(g);
             }
         };
 
         Scene scene = new Scene(root);
 

@@ -494,13 +500,13 @@
     @Test
     public void requestLayoutAlwaysCalledUpToTheLayoutRoot() {
         final Group root = new Group();
         final LGroup lroot = new LGroup();
         lroot.setManaged(false);
-        root.getChildren().add(lroot);
+        ParentShim.getChildren(root).add(lroot);
         final LGroup sub = new LGroup();
-        lroot.getChildren().add(sub);
+        ParentShim.getChildren(lroot).add(sub);
 
         lroot.clear();
         sub.clear();
         root.layout();
 

@@ -562,13 +568,13 @@
     @Test
     public void requestLayoutTriggersPulse() {
         final Group root = new Group();
         final LGroup lroot = new LGroup();
         lroot.setManaged(false);
-        root.getChildren().add(lroot);
+        ParentShim.getChildren(root).add(lroot);
         final LGroup sub = new LGroup();
-        lroot.getChildren().add(sub);
+        ParentShim.getChildren(lroot).add(sub);
 
         toolkit.clearPulseRequested();
         sub.requestLayout();
         Scene scene = new Scene(root);
         assertTrue(toolkit.isPulseRequested());

@@ -586,16 +592,16 @@
         lroot.setManaged(false);
         final LGroup sub = new LGroup() {
 
             @Override
             protected void layoutChildren() {
-                super.layoutChildren();
+                GroupShim.layoutChildren((Group)getParent());
                 requestLayout();
             }
 
         };
-        lroot.getChildren().add(sub);
+        ParentShim.getChildren(lroot).add(sub);
         lroot.clear();
         sub.clear();
 
         sub.requestLayout();
         lroot.assertAndClear(true);

@@ -611,24 +617,24 @@
     public void testChildrenPermutationInvalidatesManagedChildrenAndLayout() {
         LGroup root = new LGroup();
         Rectangle r1 = new Rectangle();
         Rectangle r2 = new Rectangle();
 
-        root.getChildren().addAll(r1, r2);
+        ParentShim.getChildren(root).addAll(r1, r2);
 
         root.clear();
 
-        root.getManagedChildren().equals(root.getChildren());
+        ParentShim.getManagedChildren(root).equals(ParentShim.getChildren(root));
 
-        root.getChildren().setAll(r2, r1);
+        ParentShim.getChildren(root).setAll(r2, r1);
 
-        root.getManagedChildren().equals(root.getChildren());
+        ParentShim.getManagedChildren(root).equals(ParentShim.getChildren(root));
         root.assertAndClear(true);
 
         r2.toFront();
 
-        root.getManagedChildren().equals(root.getChildren());
+        ParentShim.getManagedChildren(root).equals(ParentShim.getChildren(root));
         root.assertAndClear(true);
     }
 
     @Test
     public void newChildInvalidatesLayoutWhenLayoutBoundsAreValidatedImmediately() {

@@ -644,39 +650,39 @@
                     layoutCalled.set(true);
                 }
             }
 
         };
-        root.getChildren().add(sub);
+        ParentShim.getChildren(root).add(sub);
         root.getLayoutBounds(); // validate
         sub.getBoundsInParent(); // validate
 
         root.layoutBoundsProperty().addListener((observable, oldValue, newValue) -> {
             // ChangeListener will immediately validate the bounds
         });
         sub.clear();
 
         testReady.set(true);
-        sub.getChildren().add(new Rectangle());
+        ParentShim.getChildren(sub).add(new Rectangle());
         assertTrue(layoutCalled.get());
     }
 
     @Test
     public void sceneListenerCanAddChild() {
         final Group root = new Group();
         final Scene scene = new Scene(root, 600, 450);
 
         final Group child = new Group(new Group(), new Group(), new Group());
 
-        child.getChildren().get(1).sceneProperty().addListener(o -> child.getChildren().add(2, new Group()));
+        ParentShim.getChildren(child).get(1).sceneProperty().addListener(o -> ParentShim.getChildren(child).add(2, new Group()));
 
-        root.getChildren().add(child);
+        ParentShim.getChildren(root).add(child);
 
-        assertSame(scene, child.getChildren().get(3).getScene());
+        assertSame(scene, ParentShim.getChildren(child).get(3).getScene());
     }
 
     public static class MockParent extends Parent {
         public MockParent(Node... children) {
-            getChildren().addAll(children);
+            ParentShim.getChildren(this).addAll(children);
         }
     }
 }