151 lines
4.1 KiB
Java
151 lines
4.1 KiB
Java
package jmri.jmrit.ussctc;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
import java.util.*;
|
|
|
|
import jmri.*;
|
|
import jmri.util.JUnitUtil;
|
|
|
|
import org.junit.jupiter.api.*;
|
|
|
|
/**
|
|
* Tests for TimeLock class in the jmri.jmrit.ussctc package
|
|
*
|
|
* @author Bob Jacobsen Copyright 2007
|
|
*/
|
|
public class TimeLockTest {
|
|
|
|
@Test
|
|
public void testEmpty() {
|
|
ArrayList<SignalHeadSection> list = new ArrayList<>();
|
|
|
|
TimeLock lock = new TimeLock(list);
|
|
|
|
assertTrue(lock.isLockClear(Lock.turnoutLockLogger));
|
|
}
|
|
|
|
@Test
|
|
public void testOneInListPass() throws JmriException {
|
|
ArrayList<SignalHeadSection> list = new ArrayList<>();
|
|
|
|
SignalHeadSection s = new SignalHeadSection() {
|
|
@Override
|
|
public boolean isRunningTime() { return false;}
|
|
};
|
|
list.add(s);
|
|
|
|
TimeLock lock = new TimeLock(list);
|
|
|
|
assertTrue(lock.isLockClear(Lock.turnoutLockLogger));
|
|
}
|
|
|
|
@Test
|
|
public void testOneFailActive() throws JmriException {
|
|
ArrayList<SignalHeadSection> list = new ArrayList<>();
|
|
|
|
SignalHeadSection s = new SignalHeadSection() {
|
|
@Override
|
|
public boolean isRunningTime() { return true;}
|
|
};
|
|
list.add(s);
|
|
|
|
TimeLock lock = new TimeLock(list);
|
|
|
|
assertFalse(lock.isLockClear(Lock.turnoutLockLogger));
|
|
}
|
|
|
|
@Test
|
|
public void testOneFailStringArrayCtor() throws JmriException {
|
|
SignalHeadSection s = new SignalHeadSection() {
|
|
@Override
|
|
public boolean isRunningTime() { return true;}
|
|
};
|
|
|
|
TimeLock lock = new TimeLock(new SignalHeadSection[]{s});
|
|
|
|
assertFalse(lock.isLockClear(Lock.turnoutLockLogger));
|
|
}
|
|
|
|
@Test
|
|
public void testOneFailSingleCtor() throws JmriException {
|
|
SignalHeadSection s = new SignalHeadSection() {
|
|
@Override
|
|
public boolean isRunningTime() { return true;}
|
|
};
|
|
|
|
TimeLock lock = new TimeLock(s);
|
|
|
|
assertFalse(lock.isLockClear(Lock.turnoutLockLogger));
|
|
}
|
|
|
|
@Test
|
|
public void testSecondFailActive() throws JmriException {
|
|
ArrayList<SignalHeadSection> list = new ArrayList<>();
|
|
|
|
SignalHeadSection s = new SignalHeadSection() {
|
|
@Override
|
|
public boolean isRunningTime() { return false;}
|
|
};
|
|
list.add(s);
|
|
|
|
s = new SignalHeadSection() {
|
|
@Override
|
|
public boolean isRunningTime() { return true;}
|
|
};
|
|
list.add(s);
|
|
|
|
TimeLock lock = new TimeLock(list);
|
|
|
|
assertFalse(lock.isLockClear(Lock.turnoutLockLogger));
|
|
}
|
|
|
|
@Test
|
|
public void testBeanSettingMatch() throws JmriException {
|
|
SignalHeadSection s = new SignalHeadSection() {
|
|
@Override
|
|
public boolean isRunningTime() { return true;}
|
|
};
|
|
|
|
Turnout t = InstanceManager.getDefault(TurnoutManager.class).provideTurnout("IT1");
|
|
t.setCommandedState(Turnout.CLOSED);
|
|
|
|
BeanSetting b = new BeanSetting(t, Turnout.CLOSED);
|
|
TimeLock lock = new TimeLock(new SignalHeadSection[]{s}, new BeanSetting[]{b});
|
|
|
|
assertFalse(lock.isLockClear(Lock.turnoutLockLogger));
|
|
}
|
|
|
|
@Test
|
|
public void testBeanSettingoMatch() throws JmriException {
|
|
SignalHeadSection s = new SignalHeadSection() {
|
|
@Override
|
|
public boolean isRunningTime() { return true;}
|
|
};
|
|
|
|
Turnout t = InstanceManager.getDefault(TurnoutManager.class).provideTurnout("IT1");
|
|
t.setCommandedState(Turnout.CLOSED);
|
|
|
|
BeanSetting b = new BeanSetting(t, Turnout.THROWN);
|
|
TimeLock lock = new TimeLock(new SignalHeadSection[]{s}, new BeanSetting[]{b});
|
|
|
|
assertTrue( lock.isLockClear(Lock.turnoutLockLogger));
|
|
}
|
|
|
|
|
|
@BeforeEach
|
|
public void setUp() {
|
|
JUnitUtil.setUp();
|
|
JUnitUtil.resetProfileManager();
|
|
JUnitUtil.initConfigureManager();
|
|
// new Lock(); // to create statics
|
|
}
|
|
|
|
@AfterEach
|
|
public void tearDown() {
|
|
JUnitUtil.tearDown();
|
|
}
|
|
|
|
}
|