Skip to content
Permalink
Browse files

refactor throttle GUI tests

  • Loading branch information...
pabender committed Sep 25, 2018
1 parent 1d43779 commit 8a515c79e457132901874a6998a2c6adf2eb61a4
Showing with 24 additions and 128 deletions.
  1. +24 −128 java/test/jmri/jmrit/throttle/ThrottleFrameTest.java
@@ -23,27 +23,20 @@

@Rule
public RetryRule retryRule = new RetryRule(3); // allow 3 retries

private ThrottleWindow frame = null;
private ThrottleFrame panel = null;
private ThrottleOperator to = null;

@Test
public void testCtor() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
Assert.assertNotNull("exists", panel);
JUnitUtil.dispose(frame);
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);
}

@Test
public void testSetAndReleaseAddress() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
panel.toFront();

ThrottleOperator to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));

to.setAddressValue(new DccLocoAddress(42,false));

@@ -57,21 +50,11 @@ public void testSetAndReleaseAddress() {
to.getAddressValue());

to.pushReleaseButton();
to.requestClose();
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);

}

@Test
public void testInitialFunctionStatus() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
panel.toFront();

ThrottleOperator to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));

to.setAddressValue(new DccLocoAddress(42,false));

@@ -84,22 +67,12 @@ public void testInitialFunctionStatus() {


to.pushReleaseButton();
to.requestClose();
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);
}

@Test
@Ignore("Works locally (Linux) and on Appveyor (Windows). Unable to find popup after click on Travis")
public void testToggleMomentaryStatus() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
frame.setExtendedState( frame.getExtendedState()|java.awt.Frame.MAXIMIZED_BOTH );
panel.toFront();

ThrottleOperator to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));

to.setAddressValue(new DccLocoAddress(42,false));

@@ -115,22 +88,14 @@ public void testToggleMomentaryStatus() {
}

to.pushReleaseButton();
to.requestClose();
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);
}

@Test
public void testToggleOnOffStatus() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
frame.setExtendedState( frame.getExtendedState()|java.awt.Frame.MAXIMIZED_BOTH );
panel.toFront();

ThrottleOperator to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));

to.setAddressValue(new DccLocoAddress(42,false));

// only check through function 5, since all the buttons
@@ -144,21 +109,11 @@ public void testToggleOnOffStatus() {
}

to.pushReleaseButton();
to.requestClose();
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);
}

@Test
public void testToggleOnOffStatusAltFunctions() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
frame.setExtendedState( frame.getExtendedState()|java.awt.Frame.MAXIMIZED_BOTH );
panel.toFront();

ThrottleOperator to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));

to.setAddressValue(new DccLocoAddress(42,false));

@@ -175,21 +130,11 @@ public void testToggleOnOffStatusAltFunctions() {
}

to.pushReleaseButton();
to.requestClose();
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);
}

@Test
public void testToggleAlt2() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
frame.setExtendedState( frame.getExtendedState()|java.awt.Frame.MAXIMIZED_BOTH );
panel.toFront();

ThrottleOperator to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));

to.setAddressValue(new DccLocoAddress(42,false));

@@ -198,23 +143,13 @@ public void testToggleAlt2() {
to.pushAlt1Button();

to.pushReleaseButton();
to.requestClose();
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);
}

// Tests for Control (Speed and Direction) panel.

@Test
public void testStopButton() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
frame.setExtendedState( frame.getExtendedState()|java.awt.Frame.MAXIMIZED_BOTH );
panel.toFront();

ThrottleOperator to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));

to.setAddressValue(new DccLocoAddress(42,false));

@@ -226,22 +161,14 @@ public void testStopButton() {
to.setSpeedSlider(28);

to.pushReleaseButton();
to.requestClose();
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);
}

@Test
public void testEStopButton() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
frame.setExtendedState( frame.getExtendedState()|java.awt.Frame.MAXIMIZED_BOTH );
panel.toFront();

ThrottleOperator to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));

to.setAddressValue(new DccLocoAddress(42,false));
to.setSpeedSlider(28);

@@ -251,21 +178,11 @@ public void testEStopButton() {
Assert.assertTrue("Throttle Speed EStop",to.getAttachedThrottle().getSpeedSetting()<0);

to.pushReleaseButton();
to.requestClose();
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);
}

@Test
public void testIdleButton() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
frame.setExtendedState( frame.getExtendedState()|java.awt.Frame.MAXIMIZED_BOTH );
panel.toFront();

ThrottleOperator to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));

to.setAddressValue(new DccLocoAddress(42,false));
to.setSpeedSlider(28);
@@ -277,23 +194,15 @@ public void testIdleButton() {


to.pushReleaseButton();
to.requestClose();
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);
}


@Test
public void testSliderMaximumSpeed() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
frame.setExtendedState( frame.getExtendedState()|java.awt.Frame.MAXIMIZED_BOTH );
panel.toFront();

ThrottleOperator to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));

to.setAddressValue(new DccLocoAddress(42,false));

to.speedSliderMaximum();
@@ -302,21 +211,11 @@ public void testSliderMaximumSpeed() {
Assert.assertEquals("Throttle Speed Maximum",1.0,to.getAttachedThrottle().getSpeedSetting(),0.005);

to.pushReleaseButton();
to.requestClose();
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);
}

@Test
public void testSliderMinimumSpeed() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
frame.setExtendedState( frame.getExtendedState()|java.awt.Frame.MAXIMIZED_BOTH );
panel.toFront();

ThrottleOperator to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));

to.setAddressValue(new DccLocoAddress(42,false));

@@ -326,62 +225,59 @@ public void testSliderMinimumSpeed() {
Assert.assertEquals("Speed set to Minimum",1,to.getSpeedSliderValue());

to.pushReleaseButton();
to.requestClose();
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);
}

@Test
public void testForwardButtonPress() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
frame.setExtendedState( frame.getExtendedState()|java.awt.Frame.MAXIMIZED_BOTH );
panel.toFront();

ThrottleOperator to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));

to.setAddressValue(new DccLocoAddress(42,false));

to.pushForwardButton(); // need to verify this took effect.
Assert.assertTrue("Forward Direction",to.getAttachedThrottle().getIsForward());

to.pushReleaseButton();
to.requestClose();
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
}

@Test
public void testReverseButtonPress() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ThrottleWindow frame = new ThrottleWindow();
ThrottleFrame panel = new ThrottleFrame(frame);
frame.setExtendedState( frame.getExtendedState()|java.awt.Frame.MAXIMIZED_BOTH );
panel.toFront();

ThrottleOperator to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));

to.setAddressValue(new DccLocoAddress(42,false));

to.pushReverseButton(); // need to verify this took effect.
Assert.assertFalse("Reverse Direction",to.getAttachedThrottle().getIsForward());
to.pushReleaseButton();
to.requestClose();
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
}

@Before
public void setUp() {
JUnitUtil.setUp();
JUnitUtil.resetProfileManager();
JUnitUtil.initDebugThrottleManager();

if(!GraphicsEnvironment.isHeadless()){
frame = new ThrottleWindow();
panel = new ThrottleFrame(frame);
frame.setExtendedState( frame.getExtendedState()|java.awt.Frame.MAXIMIZED_BOTH );
panel.toFront();
to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));
}
}

@After
public void tearDown() {
JUnitUtil.tearDown();
if(!GraphicsEnvironment.isHeadless()){
to.requestClose();
new org.netbeans.jemmy.QueueTool().waitEmpty(100); //pause for frame tot close
JUnitUtil.dispose(frame);
// the throttle list frame gets created above, but needs to be shown to be disposed
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);
}
panel = null;
frame = null;
to = null;
JUnitUtil.tearDown();
}
}

0 comments on commit 8a515c7

Please sign in to comment.
You can’t perform that action at this time.