Files
JIMRI/java/test/jmri/jmrix/loconet/hexfile/LnSensorManagerTest.java
T
2026-06-17 14:00:51 +02:00

111 lines
3.0 KiB
Java

package jmri.jmrix.loconet.hexfile;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import jmri.Sensor;
import jmri.SensorManager;
import jmri.jmrix.loconet.LocoNetInterfaceScaffold;
import jmri.jmrix.loconet.LocoNetMessage;
import jmri.jmrix.loconet.LocoNetSystemConnectionMemo;
import jmri.util.JUnitUtil;
import org.junit.jupiter.api.*;
/**
* Tests for the jmri.jmrix.loconet.hexfile.LnSensorManagerTurnout class.
*
* @author Bob Jacobsen Copyright 2001
*/
public class LnSensorManagerTest extends jmri.managers.AbstractSensorMgrTestBase {
private LocoNetInterfaceScaffold lnis = null;
@Override
public String getSystemName(int i) {
return "LS" + i;
}
@Test
public void testLnSensorCreate() {
assertNotNull( l, "exists");
}
@Test
public void testByAddress() {
// sample turnout object
Sensor t = l.newSensor("LS22", "test");
// test get
assertSame( t, l.getByUserName("test"));
assertSame( t, l.getBySystemName("LS22"));
}
@Test
@Override
public void testMisses() {
// sample turnout object
Sensor t = l.newSensor("LS22", "test");
assertNotNull( t, "exists");
// try to get nonexistant turnouts
assertNull( l.getByUserName("foo"));
assertNull( l.getBySystemName("bar"));
}
@Test
public void testLocoNetMessages() {
// send messages for 21, 22
// notify the Ln that somebody else changed it...
LocoNetMessage m1 = new LocoNetMessage(4);
m1.setOpCode(0xb2); // OPC_INPUT_REP
m1.setElement(1, 0x15); // all but lowest bit of address
m1.setElement(2, 0x60); // Aux (low addr bit high), sensor high
m1.setElement(3, 0x38);
lnis.sendTestMessage(m1);
// see if sensor exists
assertNotNull(l.getBySystemName("LS44"));
}
@Test
public void testAsAbstractFactory() {
// ask for a Sensor, and check type
SensorManager t = jmri.InstanceManager.sensorManagerInstance();
Sensor o = t.newSensor("LS21", "my name");
assertNotNull(o);
assertNotNull(t.getBySystemName("LS21"));
assertNotNull(t.getByUserName("my name"));
}
// private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LnSensorManagerTest.class);
@Override
@BeforeEach
public void setUp() {
JUnitUtil.setUp();
// prepare an interface
LocoNetSystemConnectionMemo memo = new LocoNetSystemConnectionMemo();
lnis = new LocoNetInterfaceScaffold(memo);
memo.setLnTrafficController(lnis);
assertNotNull( lnis, "exists");
// create and register the manager object
l = new LnSensorManager(memo, false);
jmri.InstanceManager.setSensorManager(l);
}
@AfterEach
public void tearDown() {
l.dispose();
lnis = null;
JUnitUtil.tearDown();
}
}