Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Tests] Modify spinner test for Xvfb compatibility

TestMenuItemSpinner was failing under Xvfb
(but not other environments). Appears that
cause is some difference (possibly in layout)
regarding the way spinners respond to clicks
from FEST under that environment.

Test is modified such that clicks are now
directed explicitly to the text field in
the spinner, such that subsequent typing
exercises the intended behavior.
  • Loading branch information...
commit e247325ef58aef95b91f44637f80a0dc0b003788 1 parent bfec9f6
@VWoeltjen VWoeltjen authored
View
52 fastPlotViews/src/test/java/gov/nasa/arc/mct/fastplot/util/TestMenuItemSpinner.java
@@ -4,17 +4,20 @@
import java.awt.event.KeyEvent;
import java.lang.reflect.InvocationTargetException;
-import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JPopupMenu;
+import javax.swing.JSpinner.NumberEditor;
+import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingUtilities;
import org.fest.swing.core.BasicRobot;
import org.fest.swing.core.Robot;
+import org.fest.swing.edt.GuiActionRunner;
+import org.fest.swing.edt.GuiQuery;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
@@ -24,6 +27,7 @@
public class TestMenuItemSpinner {
MenuItemSpinner spinner;
+ JTextField spinnerField;
JFrame f;
JPopupMenu menu;
JMenu spinnerMenu;
@@ -37,15 +41,16 @@ public void setupFrame() {
@BeforeMethod
public void setup() throws InterruptedException, InvocationTargetException {
- menu = new JPopupMenu();
- spinnerMenu = new JMenu("Test");
- spinner = new MenuItemSpinner(new SpinnerNumberModel(5,1,10,1), spinnerMenu);
- spinnerMenu.add(spinner);
- menu.add(spinnerMenu);
-
-
+
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
+ menu = new JPopupMenu();
+ spinnerMenu = new JMenu("Test");
+ spinner = new MenuItemSpinner(new SpinnerNumberModel(5,1,10,1), spinnerMenu);
+ spinnerField = ((NumberEditor)spinner.getEditor()).getTextField();
+ spinnerMenu.add(spinner);
+ menu.add(spinnerMenu);
+
JLabel label = new JLabel("label");
f.getContentPane().removeAll();
f.getContentPane().add(label);
@@ -74,26 +79,25 @@ public void tearDown() {
@Test
public void testAppearsInSubMenu() {
robot.click(spinnerMenu);
- robot.click(spinner); // Will cause exception if spinner isn't visible
+ robot.click(spinnerField); // Will cause exception if spinner isn't visible
}
@Test
public void testTyping() {
robot.click(spinnerMenu);
- robot.click(spinner);
+ robot.click(spinnerField);
// Should still be 5
Assert.assertEquals(getSpinnerValue(), 5);
// Changing to two and hitting enter should update value
- robot.click(spinner);
+ robot.click(spinnerField);
robot.pressAndReleaseKeys(KeyEvent.VK_BACK_SPACE, KeyEvent.VK_DELETE, '2', KeyEvent.VK_ENTER);
- robot.waitForIdle();
Assert.assertEquals(getSpinnerValue(), 2);
// Empty box should be reset
- robot.click(spinner);
+ robot.click(spinnerField);
robot.pressAndReleaseKeys(KeyEvent.VK_BACK_SPACE, KeyEvent.VK_DELETE, KeyEvent.VK_ENTER);
Assert.assertEquals(getSpinnerValue(), 2);
}
@@ -101,7 +105,7 @@ public void testTyping() {
@Test
public void testTabOut() {
robot.click(spinnerMenu);
- robot.click(spinner);
+ robot.click(spinnerField);
// Should still be 5
Assert.assertEquals(getSpinnerValue(), 5);
robot.pressAndReleaseKeys(KeyEvent.VK_BACK_SPACE, KeyEvent.VK_DELETE, '2', KeyEvent.VK_TAB);
@@ -110,16 +114,14 @@ public void testTabOut() {
// Retrieve spinner value from EDT to avoid intermittent test failures.
private int getSpinnerValue() {
- final AtomicInteger value = new AtomicInteger(0);
- try {
- SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- value.set((Integer)spinner.getValue());
- }
- });
- } catch (Exception e) {
- Assert.fail(); // Cannot complete tests without spinner value
- }
- return value.get();
+ robot.waitForIdle();
+ Integer i = GuiActionRunner.execute(new GuiQuery<Integer>() {
+ @Override
+ protected Integer executeInEDT() throws Throwable {
+ return (Integer) spinner.getValue();
+ }
+ });
+ robot.waitForIdle();
+ return i;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.