Skip to content
Permalink
Browse files

more equals tests

  • Loading branch information...
icklesteve committed Jun 3, 2019
1 parent 86c6f24 commit b964866299376e0e2c788bd9d8eef1f7fbc0b1b1
@@ -119,5 +119,26 @@ public void testLight() {
t.setState(Light.OFF);
Assert.assertTrue("Light is ON", t.getKnownState() == Light.OFF);
}

// add a LightControl
@Test
public void testAddLightControls() {

Assert.assertTrue("0 controls attached", t.getLightControlList().size() == 0);
jmri.implementation.LightControl lc = new jmri.implementation.LightControl(t);
lc.setControlType(Light.SENSOR_CONTROL);
t.addLightControl(lc);
Assert.assertTrue("1 control attached", t.getLightControlList().size() == 1);
t.addLightControl(lc);
Assert.assertTrue("1 control attached", t.getLightControlList().size() == 1);
Assert.assertTrue("control attached", t.getLightControlList().get(0) == lc);
t.addLightControl(new jmri.implementation.LightControl(t));
Assert.assertTrue("2 controls attached", t.getLightControlList().size() == 2);
Assert.assertTrue("2 controls attached", t.getLightControlList().get(0)
!= t.getLightControlList().get(1));
t.clearLightControls();
Assert.assertTrue("0 controls attached", t.getLightControlList().size() == 0);

}

}
@@ -59,6 +59,103 @@ public void testEquals() {

LightControl l2 = new LightControl(o);
Assert.assertTrue(l1.equals(l2));

l1.setControlType(999);
Assert.assertFalse(l1.equals(l2));
l2.setControlType(999);
Assert.assertTrue(l1.equals(l2));
JUnitAppender.assertWarnMessage("Unexpected _controlType = 999");

l1.setControlType(Light.SENSOR_CONTROL);
Assert.assertFalse(l1.equals(l2));
l2.setControlType(Light.SENSOR_CONTROL);
Assert.assertTrue(l1.equals(l2));

l1.setControlSensorName("S2");
Assert.assertFalse(l1.equals(l2));
l2.setControlSensorName("S2");
Assert.assertTrue(l1.equals(l2));

l1.setControlSensorSense(Sensor.ACTIVE);
Assert.assertTrue(l1.equals(l2)); // default is ACTIVE

l1.setControlSensorSense(Sensor.INACTIVE);
Assert.assertFalse(l1.equals(l2));
l2.setControlSensorSense(Sensor.INACTIVE);
Assert.assertTrue(l1.equals(l2));

l1.setControlType(Light.FAST_CLOCK_CONTROL );
Assert.assertFalse(l1.equals(l2));
l2.setControlType(Light.FAST_CLOCK_CONTROL );
Assert.assertTrue(l1.equals(l2));

l1.setFastClockControlSchedule(0,0,0,0); // onHr, OnMin, OffHr, OffMin default
Assert.assertTrue(l1.equals(l2));

l1.setFastClockControlSchedule(1,0,0,0); // onHr, OnMin, OffHr, OffMin
Assert.assertFalse(l1.equals(l2));
l1.setFastClockControlSchedule(0,1,0,0); // onHr, OnMin, OffHr, OffMin
Assert.assertFalse(l1.equals(l2));
l1.setFastClockControlSchedule(0,0,1,0); // onHr, OnMin, OffHr, OffMin
Assert.assertFalse(l1.equals(l2));
l1.setFastClockControlSchedule(0,0,0,1); // onHr, OnMin, OffHr, OffMin
Assert.assertFalse(l1.equals(l2));

l1.setControlType(Light.TURNOUT_STATUS_CONTROL );
Assert.assertFalse(l1.equals(l2));
l2.setControlType(Light.TURNOUT_STATUS_CONTROL );
Assert.assertTrue(l1.equals(l2));

l1.setControlTurnout("T1");
Assert.assertFalse(l1.equals(l2));
l2.setControlTurnout("T1");
Assert.assertTrue(l1.equals(l2));

l1.setControlTurnoutState(Turnout.CLOSED); // default CLOSED
Assert.assertTrue(l1.equals(l2));

l1.setControlTurnoutState(Turnout.THROWN);
Assert.assertFalse(l1.equals(l2));
l2.setControlTurnoutState(Turnout.THROWN);
Assert.assertTrue(l1.equals(l2));

l1.setControlType(Light.TIMED_ON_CONTROL );
Assert.assertFalse(l1.equals(l2));
l2.setControlType(Light.TIMED_ON_CONTROL );
Assert.assertTrue(l1.equals(l2));

l1.setControlTimedOnSensorName("S1");
Assert.assertFalse(l1.equals(l2));
l2.setControlTimedOnSensorName("S1");
Assert.assertTrue(l1.equals(l2));

l1.setTimedOnDuration(77);
Assert.assertFalse(l1.equals(l2));
l2.setTimedOnDuration(77);
Assert.assertTrue(l1.equals(l2));

l1.setControlType(Light.TWO_SENSOR_CONTROL );
Assert.assertFalse(l1.equals(l2));
l2.setControlType(Light.TWO_SENSOR_CONTROL );
Assert.assertTrue(l1.equals(l2));


l1.setControlSensorName("S1");
Assert.assertFalse(l1.equals(l2));
l2.setControlSensorName("S1");
Assert.assertTrue(l1.equals(l2));

l1.setControlSensor2Name("S2");
Assert.assertFalse(l1.equals(l2));
l2.setControlSensor2Name("S2");
Assert.assertTrue(l1.equals(l2));

l1.setControlSensorSense(Sensor.ACTIVE);
Assert.assertFalse(l1.equals(l2));
l2.setControlSensorSense(Sensor.ACTIVE);
Assert.assertTrue(l1.equals(l2));


}

@Test
@@ -175,7 +272,7 @@ public void testNoTurnout() {
}

@Test
public void testSingleTurnoutFollower() throws jmri.JmriException {
public void testTurnoutFollower() throws jmri.JmriException {

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
Turnout t = InstanceManager.getDefault(jmri.TurnoutManager.class).provideTurnout("T1");
@@ -495,15 +592,13 @@ public void testTimedSensorFollowing() throws jmri.JmriException{
lc.setControlType(Light.TIMED_ON_CONTROL);
lc.setControlTimedOnSensorName("S2");


l.setState(Light.ON); // should go OFF when light enabled and Timed Sensor Control activated

// adding the PCL to check the Light changes
// ie "normal" amount of PCEvents for a state change.
// NOT testing the actual PCListeners
l.addPropertyChangeListener(new ControlListen());


l.addLightControl(lc);
l.activateLight();

@@ -534,7 +629,6 @@ public void testTimedSensorFollowing() throws jmri.JmriException{
JUnitUtil.waitFor(()->{return Light.OFF == l.getState();},"Light goes back OFF after timer");
Assert.assertEquals("10 Light PropertyChangeEvents", 10, _listenerkicks );


l.setEnabled(false);
s.setState(Sensor.ON);
s.setState(Sensor.OFF);

0 comments on commit b964866

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