< prev index next >

test/sanity/client/SwingSet/src/SplitPaneDemoTest.java

Print this page

        

@@ -19,26 +19,33 @@
  * 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.
  */
 
-import org.jtregext.GuiTestListener;
 import com.sun.swingset3.demos.splitpane.SplitPaneDemo;
 import static com.sun.swingset3.demos.splitpane.SplitPaneDemo.*;
+
+import java.awt.Component;
 import java.awt.event.KeyEvent;
 import javax.swing.JSplitPane;
-import static org.testng.AssertJUnit.*;
-import org.testng.annotations.Test;
+
+import static org.jemmy2ext.JemmyExt.*;
+
+import org.jtregext.GuiTestListener;
+
 import org.netbeans.jemmy.ClassReference;
+import org.netbeans.jemmy.ComponentChooser;
 import org.netbeans.jemmy.operators.JButtonOperator;
 import org.netbeans.jemmy.operators.JCheckBoxOperator;
 import org.netbeans.jemmy.operators.JFrameOperator;
 import org.netbeans.jemmy.operators.JRadioButtonOperator;
 import org.netbeans.jemmy.operators.JSplitPaneOperator;
 import org.netbeans.jemmy.operators.JTextFieldOperator;
-import static org.jemmy2ext.JemmyExt.*;
+
 import org.testng.annotations.Listeners;
+import org.testng.annotations.Test;
+import static org.testng.AssertJUnit.*;
 
 /*
  * @test
  * @key headful
  * @summary Verifies SwingSet3 SplitPaneDemo by performing OneClick expansion,

@@ -46,10 +53,11 @@
  *          and changing the divider orientation.
  *
  * @library /sanity/client/lib/jemmy/src
  * @library /sanity/client/lib/Extensions/src
  * @library /sanity/client/lib/SwingSet3/src
+ * @modules java.desktop
  * @build org.jemmy2ext.JemmyExt
  * @build com.sun.swingset3.demos.splitpane.SplitPaneDemo
  * @run testng SplitPaneDemoTest
  */
 @Listeners(GuiTestListener.class)

@@ -113,18 +121,37 @@
         splitPane.moveDivider(0.5);
         assertEquals("Move Middle, dividerLocation is at the artithmetic average of minimum and maximum DividerLocations",
                 (splitPane.getMaximumDividerLocation() + splitPane.getMinimumDividerLocation()) / 2, splitPane.getDividerLocation());
     }
 
+    private void waitDividerSize(JSplitPaneOperator splitPane, int size) {
+        splitPane.waitState(new ComponentChooser() {
+            public boolean checkComponent(Component c) {
+                return splitPane.getDividerSize() == size;
+            }
+            public String getDescription() {
+                return "Divider size to be " + size;
+            }
+        });
+    }
+
     // Check changing the size of the divider
     public void changeDividerSize(JFrameOperator frame, JSplitPaneOperator splitPane, int amount) throws Exception {
         JTextFieldOperator size = new JTextFieldOperator(getLabeledContainerOperator(frame, DIVIDER_SIZE));
-        size.clearText();
-        size.typeText(Integer.toString(amount));
-        size.pressKey(KeyEvent.VK_ENTER);
+        size.enterText(Integer.toString(amount));
+        waitDividerSize(splitPane, amount);
+    }
 
-        assertEquals("Change Divider Size", amount, splitPane.getDividerSize());
+    private void waitDividerLocation(JSplitPaneOperator splitPane, int location) {
+        splitPane.waitState(new ComponentChooser() {
+            public boolean checkComponent(Component c) {
+                return splitPane.getDividerLocation() == location;
+            }
+            public String getDescription() {
+                return "Divider location to be " + location;
+            }
+        });
     }
 
     public void checkOneTouch(JFrameOperator frame, JSplitPaneOperator splitPane, boolean oneTouch) throws Exception {
         JCheckBoxOperator checkBox = new JCheckBoxOperator(frame, ONE_TOUCH_EXPANDABLE);
         JButtonOperator buttonLeft = new JButtonOperator(splitPane.getDivider(), 0);

@@ -142,35 +169,38 @@
             int right = getUIValue(splitPane, (JSplitPane sp) -> sp.getInsets().right);
             System.out.println("right = " + right);
 
             // expand full left
             buttonLeft.push();
-            assertEquals("Expandable Left", left, splitPane.getDividerLocation());
+            waitDividerLocation(splitPane, left);
 
             // expand back from full left
             buttonRight.push();
-            assertEquals("Expandable Back to Original from Left",
-                    initDividerLocation, splitPane.getDividerLocation());
+            waitDividerLocation(splitPane, initDividerLocation);
 
             // expand all the way right
             buttonRight.push();
-            assertEquals("Expandable Right",
-                    splitPane.getWidth() - splitPane.getDividerSize() - right,
-                    splitPane.getDividerLocation());
+            waitDividerLocation(splitPane, splitPane.getWidth() - splitPane.getDividerSize() - right);
 
             // Click to move back from right expansion
             buttonLeft.push();
-            assertEquals("Expandable Back to Original from Right",
-                    initDividerLocation, splitPane.getDividerLocation());
+            waitDividerLocation(splitPane, initDividerLocation);
         }
 
         // Test for case where one touch expandable is disabled
         if (!oneTouch) {
             if (checkBox.isSelected()) {
                 // uncheck
                 checkBox.doClick();
             }
-            assertFalse("One Touch Expandable Off", splitPane.isOneTouchExpandable());
+            splitPane.waitState(new ComponentChooser() {
+                public boolean checkComponent(Component c) {
+                    return !splitPane.isOneTouchExpandable();
+                }
+                public String getDescription() {
+                    return "Split pane not to be one touch expandable";
+                }
+            });
         }
     }
 
 }
< prev index next >