/
InternalSensorManagerTest.java
99 lines (79 loc) · 3.08 KB
/
InternalSensorManagerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package jmri.jmrix.internal;
import jmri.Sensor;
import jmri.SensorManager;
import jmri.util.JUnitUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Tests for the jmri.jmrix.internal.InternalSensorManager class.
*
* @author Bob Jacobsen Copyright 2016
*/
public class InternalSensorManagerTest extends jmri.managers.AbstractSensorMgrTestBase {
@Override
public String getSystemName(int i) {
return "IS" + i;
}
public void testSensorNameCase() {
Assert.assertEquals(0, l.getObjectCount());
// create
Sensor t = l.provideSensor("IS:XYZ");
t = l.provideSensor("IS:xyz"); // upper canse and lower case are the same object
// check
Assert.assertTrue("real object returned ", t != null);
Assert.assertEquals("IS:XYZ", t.getSystemName()); // we force upper
Assert.assertTrue("system name correct ", t == l.getBySystemName("IS:XYZ"));
Assert.assertEquals(1, l.getObjectCount());
Assert.assertEquals(1, l.getSystemNameAddedOrderList().size());
t = l.provideSensor("IS:XYZ");
Assert.assertEquals(1, l.getObjectCount());
Assert.assertEquals(1, l.getSystemNameAddedOrderList().size());
}
@Test
public void testAsAbstractFactory() {
// ask for a Sensor, and check type
SensorManager lm = jmri.InstanceManager.sensorManagerInstance();
Sensor tl = lm.newSensor("IS21", "my name");
if (log.isDebugEnabled()) {
log.debug("received sensor value " + tl);
}
Assert.assertTrue(null != tl);
// make sure loaded into tables
if (log.isDebugEnabled()) {
log.debug("by system name: " + lm.getBySystemName("IS21"));
}
if (log.isDebugEnabled()) {
log.debug("by user name: " + lm.getByUserName("my name"));
}
Assert.assertTrue(null != lm.getBySystemName("IS21"));
Assert.assertTrue(null != lm.getByUserName("my name"));
}
@Test
public void testSetGetDefaultState() {
// confirm default
Assert.assertEquals("starting mode", Sensor.UNKNOWN, InternalSensorManager.getDefaultStateForNewSensors() );
// set and retrieve
InternalSensorManager.setDefaultStateForNewSensors(Sensor.INACTIVE);
Assert.assertEquals("updated mode", Sensor.INACTIVE, InternalSensorManager.getDefaultStateForNewSensors() );
}
// from here down is testing infrastructure
// The minimal setup for log4J
@Override
@Before
public void setUp() {
apps.tests.Log4JFixture.setUp();
// create and register the manager object
jmri.util.JUnitUtil.resetInstanceManager();
jmri.util.JUnitUtil.initInternalSensorManager();
l = jmri.InstanceManager.sensorManagerInstance();
}
@After
public void tearDown() {
JUnitUtil.tearDown();
}
private final static Logger log = LoggerFactory.getLogger(InternalSensorManagerTest.class);
}