Skip to content

Commit

Permalink
Improve LightControlTest
Browse files Browse the repository at this point in the history
  • Loading branch information
icklesteve committed Jun 14, 2019
1 parent f70f27d commit 72a4a6e
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions java/test/jmri/implementation/LightControlTest.java
Expand Up @@ -175,28 +175,28 @@ public void testSetGetNames(){

@Test
public void testInvalidControlType() {
Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
LightControl lc = new LightControl(l);
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
lc = new LightControl(l);
lc.activateLightControl();
JUnitAppender.assertErrorMessage("Unexpected control type when activating Light: ILL1");
}

@Test
public void testActivateNoLight() {
LightControl lc = new LightControl();
lc = new LightControl();
lc.activateLightControl();
JUnitAppender.assertErrorMessage("No Parent Light when activating LightControl");
}

@Test
public void testSingleSensorFollower() throws jmri.JmriException {

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
Sensor s = InstanceManager.getDefault(jmri.SensorManager.class).provideSensor("S2");

int startListeners = s.getPropertyChangeListeners().length;

LightControl lc = new LightControl(l);
lc = new LightControl(l);
lc.setControlType(Light.SENSOR_CONTROL);
lc.setControlSensorName("S2");
lc.setControlSensorSense(Sensor.ACTIVE);
Expand Down Expand Up @@ -245,8 +245,8 @@ public void testSingleSensorFollower() throws jmri.JmriException {
@Test
public void testNoSensor() {

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
LightControl lc = new LightControl(l);
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
lc = new LightControl(l);
lc.setControlType(Light.SENSOR_CONTROL);

l.addLightControl(lc);
Expand All @@ -258,8 +258,8 @@ public void testNoSensor() {
@Test
public void testNoTurnout() {

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
LightControl lc = new LightControl(l);
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
lc = new LightControl(l);
lc.setControlType(Light.TURNOUT_STATUS_CONTROL);

l.addLightControl(lc);
Expand All @@ -275,12 +275,12 @@ public void testNoTurnout() {
@Test
public void testTurnoutFollower() throws jmri.JmriException {

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
Turnout t = InstanceManager.getDefault(jmri.TurnoutManager.class).provideTurnout("T1");

int startListeners = t.getPropertyChangeListeners().length;

LightControl lc = new LightControl(l);
lc = new LightControl(l);
lc.setControlType(Light.TURNOUT_STATUS_CONTROL);
lc.setControlTurnout("T1");
lc.setControlTurnoutState(Turnout.THROWN);
Expand Down Expand Up @@ -340,14 +340,14 @@ public void testFastClockFollowingOneControl() throws TimebaseRateException {
cal.set(2018, 1, 12, 2, 00, 00); // 02:00:00
timebase.setTime(cal.getTime());

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");

Assert.assertEquals("OFF state by default", Light.OFF, l.getState()); // lights are OFF by default
Assert.assertEquals("enabled by default", true, l.getEnabled()); // lights are enabled by default

int startListeners = timebase.getMinuteChangeListeners().length;

LightControl lc = new LightControl();
lc = new LightControl();
lc.setParentLight(l);
lc.setControlType(Light.FAST_CLOCK_CONTROL);
lc.setFastClockControlSchedule(3,0,4,0); // onHr, OnMin, OffHr, OffMin
Expand Down Expand Up @@ -393,10 +393,10 @@ public void testFastClockFollowingOneControlStartOn() throws TimebaseRateExcepti
cal.set(2018, 1, 12, 21, 00, 00); // 21:00:00
timebase.setTime(cal.getTime());

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
Assert.assertEquals("OFF state by default", Light.OFF, l.getState()); // lights are OFF by default

LightControl lc = new LightControl(l);
lc = new LightControl(l);
lc.setControlType(Light.FAST_CLOCK_CONTROL);
lc.setFastClockControlSchedule(18,0,7,0); // onHr, OnMin, OffHr, OffMin

Expand Down Expand Up @@ -439,10 +439,10 @@ public void testFastClockFollowingTwoControls() throws TimebaseRateException {
cal.set(2018, 1, 12, 21, 00, 00); // 21:00:00
timebase.setTime(cal.getTime());

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
Assert.assertEquals("OFF state by default", Light.OFF, l.getState()); // lights are OFF by default

LightControl lc = new LightControl(l);
lc = new LightControl(l);
lc.setControlType(Light.FAST_CLOCK_CONTROL);
lc.setFastClockControlSchedule(3,0,4,0); // onHr, OnMin, OffHr, OffMin

Expand Down Expand Up @@ -516,10 +516,10 @@ public void testFastClockFollowingTwoControlsOverlap() throws TimebaseRateExcept
cal.set(2018, 1, 12, 02, 59, 00); // 02:59:00
timebase.setTime(cal.getTime());

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
Assert.assertEquals("OFF state by default", Light.OFF, l.getState()); // lights are OFF by default

LightControl lc = new LightControl(l);
lc = new LightControl(l);
lc.setControlType(Light.FAST_CLOCK_CONTROL);
lc.setFastClockControlSchedule(3,0,4,0); // onHr, OnMin, OffHr, OffMin

Expand Down Expand Up @@ -584,12 +584,12 @@ public void testFastClockFollowingTwoControlsOverlap() throws TimebaseRateExcept
@Test
public void testTimedSensorFollowing() throws jmri.JmriException{

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
Sensor s = InstanceManager.getDefault(jmri.SensorManager.class).provideSensor("S2");

int startListeners = s.getPropertyChangeListeners().length;

LightControl lc = new LightControl(l);
lc = new LightControl(l);
lc.setControlType(Light.TIMED_ON_CONTROL);
lc.setControlTimedOnSensorName("S2");

Expand Down Expand Up @@ -666,8 +666,8 @@ public void testTimedSensorFollowing() throws jmri.JmriException{
@Test
public void testNoTimedSensor() {

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
LightControl lc = new LightControl(l);
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
lc = new LightControl(l);
lc.setControlType(Light.TIMED_ON_CONTROL);

l.addLightControl(lc);
Expand All @@ -679,9 +679,9 @@ public void testNoTimedSensor() {
@Test
public void testTwoSensorFollowingNoSensorSet() {

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");

LightControl lc = new LightControl(l);
lc = new LightControl(l);
lc.setControlType(Light.TWO_SENSOR_CONTROL);

lc.setControlSensorName("");
Expand Down Expand Up @@ -711,11 +711,11 @@ public void testTwoSensorFollowingNoSensorSet() {
@Test
public void testTwoSensorFollowing() throws jmri.JmriException {

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
Sensor sOne = InstanceManager.getDefault(jmri.SensorManager.class).provideSensor("S1");
Sensor sTwo = InstanceManager.getDefault(jmri.SensorManager.class).provideSensor("S2");

LightControl lc = new LightControl(l);
lc = new LightControl(l);
lc.setControlType(Light.TWO_SENSOR_CONTROL);
lc.setControlSensorName("S1");
lc.setControlSensor2Name("S2");
Expand Down Expand Up @@ -781,11 +781,11 @@ public void testTwoSensorFollowing() throws jmri.JmriException {
@Test
public void testTwoSensorFollowingInactive() throws jmri.JmriException {

Light l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
l = InstanceManager.getDefault(jmri.LightManager.class).provideLight("L1");
Sensor sOne = InstanceManager.getDefault(jmri.SensorManager.class).provideSensor("S1");
Sensor sTwo = InstanceManager.getDefault(jmri.SensorManager.class).provideSensor("S2");

LightControl lc = new LightControl(l);
lc = new LightControl(l);
lc.setControlType(Light.TWO_SENSOR_CONTROL);
lc.setControlSensorName("S1");
lc.setControlSensor2Name("S2");
Expand Down Expand Up @@ -844,6 +844,9 @@ public void propertyChange(java.beans.PropertyChangeEvent e) {
}
}

private Light l;
private LightControl lc;

// The minimal setup for log4J
@Before
public void setUp() {
Expand Down

0 comments on commit 72a4a6e

Please sign in to comment.