Skip to content
Permalink
Browse files

test: Fix tests that assumed normalization would occur.

  • Loading branch information...
rhwood committed Jun 29, 2019
1 parent 4fb7684 commit 1dcf5b26f5517905232dd0047cc0dbf7935c2be4
@@ -76,8 +76,7 @@ public Light getLight(@Nonnull String name) {
*/
@Override
@CheckForNull
public Light getBySystemName(@Nonnull String name
) {
public Light getBySystemName(@Nonnull String name) {
return _tsys.get(name);
}

@@ -21,15 +21,15 @@
public void testCreate1() {
// original create with systemname and username
Block b1 = InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock("SystemName1", "UserName1");
Assert.assertEquals("system name", "SYSTEMNAME1", b1.getSystemName());
Assert.assertEquals("system name", "SystemName1", b1.getSystemName());
Assert.assertEquals("user name", "UserName1", b1.getUserName());
}

@Test
public void testCreate2() {
// original create with systemname and empty username
Block b1 = InstanceManager.getDefault(jmri.BlockManager.class).createNewBlock("SystemName2", "");
Assert.assertEquals("system name", "SYSTEMNAME2", b1.getSystemName());
Assert.assertEquals("system name", "SystemName2", b1.getSystemName());
Assert.assertEquals("user name", "", b1.getUserName());
}

@@ -106,7 +106,7 @@ public void testProvide1() {

// auto create with prefixed systemname and no username
Block bprovide3 = InstanceManager.getDefault(jmri.BlockManager.class).provideBlock("SystemName6");
Assert.assertEquals("provide system name by user name", "IBSYSTEMNAME6", bprovide3.getSystemName());
Assert.assertEquals("provide system name by user name", "IBSystemName6", bprovide3.getSystemName());
Assert.assertEquals("provide user name by user name", null, bprovide3.getUserName());

// auto create with accepted systemname and no username
@@ -27,7 +27,7 @@ public void testState() {
// Check that audio.setState() triggers stateChanged()
Assert.assertTrue("state has changed", stateHasChanged.get());
Assert.assertTrue("toString() matches",
"jmri.implementation.AbstractAudioTest$MyAbstractAudio (MYSYSTEMNAME)".equals(audio.toString()));
"jmri.implementation.AbstractAudioTest$MyAbstractAudio (MySystemName)".equals(audio.toString()));

Assert.assertTrue("getBeanType() matches", "Audio".equals(audio.getBeanType()));
}
@@ -27,10 +27,10 @@ public void testCtor1() {
Assert.assertEquals("to high before", Turnout.UNKNOWN, it12.getCommandedState());

SE8cSignalHead s = new SE8cSignalHead(
new NamedBeanHandle<Turnout>("11", it11),
new NamedBeanHandle<Turnout>("12", it12));
new NamedBeanHandle<>("11", it11),
new NamedBeanHandle<>("12", it12));

Assert.assertEquals("system name", "IH:SE8C:\"11\";\"12\"", s.getSystemName());
Assert.assertEquals("system name", "IH:SE8c:\"11\";\"12\"", s.getSystemName());

Assert.assertEquals("to low", Turnout.UNKNOWN, it11.getCommandedState());
Assert.assertEquals("to high", Turnout.CLOSED, it12.getCommandedState()); // dark
@@ -41,12 +41,12 @@ public void testCtor2() {
Turnout it11 = InstanceManager.turnoutManagerInstance().provideTurnout("11");
Turnout it12 = InstanceManager.turnoutManagerInstance().provideTurnout("12");
SE8cSignalHead s = new SE8cSignalHead(
new NamedBeanHandle<Turnout>("11", it11),
new NamedBeanHandle<Turnout>("12", it12),
new NamedBeanHandle<>("11", it11),
new NamedBeanHandle<>("12", it12),
"user name"
);

Assert.assertEquals("system name", "IH:SE8C:\"11\";\"12\"", s.getSystemName());
Assert.assertEquals("system name", "IH:SE8c:\"11\";\"12\"", s.getSystemName());
Assert.assertEquals("user name", "user name", s.getUserName());

Assert.assertEquals("to low", Turnout.UNKNOWN, it11.getCommandedState());
@@ -75,8 +75,8 @@ public void testRedState() {
Turnout it11 = InstanceManager.turnoutManagerInstance().provideTurnout("11");
Turnout it12 = InstanceManager.turnoutManagerInstance().provideTurnout("12");
SE8cSignalHead s = new SE8cSignalHead(
new NamedBeanHandle<Turnout>("11", it11),
new NamedBeanHandle<Turnout>("12", it12),
new NamedBeanHandle<>("11", it11),
new NamedBeanHandle<>("12", it12),
"user name"
);

@@ -92,8 +92,8 @@ public void testYellowState() {
Turnout it11 = InstanceManager.turnoutManagerInstance().provideTurnout("11");
Turnout it12 = InstanceManager.turnoutManagerInstance().provideTurnout("12");
SE8cSignalHead s = new SE8cSignalHead(
new NamedBeanHandle<Turnout>("11", it11),
new NamedBeanHandle<Turnout>("12", it12),
new NamedBeanHandle<>("11", it11),
new NamedBeanHandle<>("12", it12),
"user name"
);

@@ -109,8 +109,8 @@ public void testGreenState() {
Turnout it11 = InstanceManager.turnoutManagerInstance().provideTurnout("11");
Turnout it12 = InstanceManager.turnoutManagerInstance().provideTurnout("12");
SE8cSignalHead s = new SE8cSignalHead(
new NamedBeanHandle<Turnout>("11", it11),
new NamedBeanHandle<Turnout>("12", it12),
new NamedBeanHandle<>("11", it11),
new NamedBeanHandle<>("12", it12),
"user name"
);

@@ -126,8 +126,8 @@ public void testDarkState() {
Turnout it11 = InstanceManager.turnoutManagerInstance().provideTurnout("11");
Turnout it12 = InstanceManager.turnoutManagerInstance().provideTurnout("12");
SE8cSignalHead s = new SE8cSignalHead(
new NamedBeanHandle<Turnout>("11", it11),
new NamedBeanHandle<Turnout>("12", it12),
new NamedBeanHandle<>("11", it11),
new NamedBeanHandle<>("12", it12),
"user name"
);

@@ -145,8 +145,8 @@ public SignalHead getHeadToTest() {
Turnout it11 = InstanceManager.turnoutManagerInstance().provideTurnout("11");
Turnout it12 = InstanceManager.turnoutManagerInstance().provideTurnout("12");
return new SE8cSignalHead(
new NamedBeanHandle<Turnout>("11", it11),
new NamedBeanHandle<Turnout>("12", it12),
new NamedBeanHandle<>("11", it11),
new NamedBeanHandle<>("12", it12),
"user name"
);
}
@@ -51,7 +51,7 @@ public void testProvideIdStringName() {
Light t = l.provide("ALNode 1:2");
// check
Assert.assertTrue("real object returned ", t != null);
Assert.assertEquals("correct object returned ", t ,l.getBySystemName("ALNODE 1:2"));
Assert.assertEquals("correct object returned ", t ,l.getBySystemName("ALNode 1:2"));
}

@Test
@@ -55,7 +55,7 @@ public void testProvideIdStringName() {
Sensor t = l.provide("ASNode 1:2");
// check
Assert.assertTrue("real object returned ", t != null);
Assert.assertEquals("correct object returned ", t ,l.getBySystemName("ASNODE 1:2"));
Assert.assertEquals("correct object returned ", t ,l.getBySystemName("ASNode 1:2"));
}

@Test
@@ -24,7 +24,7 @@ public String getSystemName(int i) {
}

public String getSystemName(int on, int off) {
return "MLX010203040506070" + on +";X010203040506070" + off;
return "MLx010203040506070" + on +";x010203040506070" + off;
}

@Test
@@ -39,8 +39,8 @@ public void testProvideName() {
// olcb addresses are hex values requirng 16 digits.
Light t = l.provide("MLx010203040506070" + getNumToTest1() +";x010203040506070" + getNumToTest2());
// check
Assert.assertTrue("real object returned ", t != null);
Assert.assertTrue("system name correct " + t.getSystemName(), t == l.getBySystemName(getSystemName(getNumToTest1(), getNumToTest2())));
Assert.assertNotNull("real object returned ", t);
Assert.assertEquals("system name correct " + t.getSystemName(), t, l.getBySystemName(getSystemName(getNumToTest1(), getNumToTest2())));
}

@Override
@@ -50,8 +50,8 @@ public void testDefaultSystemName() {
// olcb addresses are hex values requirng 16 digits.
Light t = l.provideLight("MLx010203040506070" + getNumToTest1() +";x010203040506070" + getNumToTest2());
// check
Assert.assertTrue("real object returned ", t != null);
Assert.assertTrue("system name correct " + t.getSystemName(), t == l.getBySystemName(getSystemName(getNumToTest1(), getNumToTest2())));
Assert.assertNotNull("real object returned ", t);
Assert.assertEquals("system name correct " + t.getSystemName(), t, l.getBySystemName(getSystemName(getNumToTest1(), getNumToTest2())));
}

@Override
@@ -68,14 +68,14 @@ public void testUpperLower() {
public void testSingleObject() {
// test that you always get the same representation
Light t1 = l.newLight(getSystemName(getNumToTest1(), getNumToTest2()), "mine");
Assert.assertTrue("t1 real object returned ", t1 != null);
Assert.assertTrue("same by user ", t1 == l.getByUserName("mine"));
Assert.assertTrue("same by system ", t1 == l.getBySystemName(getSystemName(getNumToTest1(), getNumToTest2())));
Assert.assertNotNull("t1 real object returned ", t1);
Assert.assertEquals("same by user ", t1, l.getByUserName("mine"));
Assert.assertEquals("same by system ", t1, l.getBySystemName(getSystemName(getNumToTest1(), getNumToTest2())));

Light t2 = l.newLight(getSystemName(getNumToTest1(), getNumToTest2()), "mine");
Assert.assertTrue("t2 real object returned ", t2 != null);
Assert.assertNotNull("t2 real object returned ", t2);
// check
Assert.assertTrue("same new ", t1 == t2);
Assert.assertEquals("same new ", t1, t2);
}

@Override
@@ -84,9 +84,9 @@ public void testLightPutGet() {
// create
Light t = l.newLight(getSystemName(getNumToTest1(), getNumToTest2()), "mine");
// check
Assert.assertTrue("real object returned ", t != null);
Assert.assertTrue("user name correct ", t == l.getByUserName("mine"));
Assert.assertTrue("system name correct ", t == l.getBySystemName(getSystemName(getNumToTest1(), getNumToTest2())));
Assert.assertNotNull("real object returned ", t);
Assert.assertEquals("user name correct ", t, l.getByUserName("mine"));
Assert.assertEquals("system name correct ", t, l.getBySystemName(getSystemName(getNumToTest1(), getNumToTest2())));
}

@Override
@@ -139,6 +139,7 @@ public void put(Message msg, Connection sender) {
memo = new OlcbSystemConnectionMemo(); // this self-registers as 'M'
memo.setProtocol(jmri.jmrix.can.ConfigurationManager.OPENLCB);
memo.setInterface(new OlcbInterface(nodeID, connection) {
@Override
public Connection getOutputConnection() {
return connection;
}
@@ -21,7 +21,7 @@

@Override
public String getSystemName(int i) {
return "MSX010203040506070" + i;
return "MSx010203040506070" + i;
}

@Test
@@ -34,8 +34,8 @@ public void testProvideName() {
// create
Sensor t = l.provide(getSystemName(getNumToTest1()));
// check
Assert.assertTrue("real object returned ", t != null);
Assert.assertTrue("system name correct ", t == l.getBySystemName(getSystemName(getNumToTest1())));
Assert.assertNotNull("real object returned ", t);
Assert.assertEquals("system name correct ", t, l.getBySystemName(getSystemName(getNumToTest1())));
}

@Override
@@ -45,8 +45,8 @@ public void testDefaultSystemName() {
// olcb addresses are hex values requirng 16 digits.
Sensor t = l.provideSensor(getSystemName(getNumToTest1()));
// check
Assert.assertTrue("real object returned ", t != null);
Assert.assertTrue("system name correct " + t.getSystemName(), t == l.getBySystemName(getSystemName(getNumToTest1())));
Assert.assertNotNull("real object returned ", t);
Assert.assertEquals("system name correct " + t.getSystemName(), t, l.getBySystemName(getSystemName(getNumToTest1())));
}

@Override
@@ -55,9 +55,9 @@ public void testSensorPutGet() {
// create
Sensor t = l.newSensor(getSystemName(getNumToTest1()), "mine");
// check
Assert.assertTrue("real object returned ", t != null);
Assert.assertTrue("user name correct ", t == l.getByUserName("mine"));
Assert.assertTrue("system name correct ", t == l.getBySystemName(getSystemName(getNumToTest1())));
Assert.assertNotNull("real object returned ", t);
Assert.assertEquals("user name correct ", t, l.getByUserName("mine"));
Assert.assertEquals("system name correct ", t, l.getBySystemName(getSystemName(getNumToTest1())));
}

// Quite a few tests overload this to create their own name process
@@ -66,8 +66,8 @@ public void testProvideName() {
// create
Sensor t = l.provide("" + getNumToTest1());
// check
Assert.assertTrue("real object returned ", t != null);
Assert.assertTrue("system name correct ", t == l.getBySystemName(getSystemName(getNumToTest1())));
Assert.assertNotNull("real object returned ", t);
Assert.assertEquals("system name correct ", t, l.getBySystemName(getSystemName(getNumToTest1())));
}

@Test
@@ -102,7 +102,7 @@ public void testDefaultSystemName() {
// create
Sensor t = l.provideSensor("" + getNumToTest1());
// check
Assert.assertTrue("real object returned ", t != null);
Assert.assertNotNull("real object returned ", t);
Assert.assertEquals("system name correct ", t, l.getBySystemName(getSystemName(getNumToTest1())));
}

@@ -124,34 +124,34 @@ public void testSettings() {
public void testSingleObject() {
// test that you always get the same representation
Sensor t1 = l.newSensor(getSystemName(getNumToTest1()), "mine");
Assert.assertTrue("t1 real object returned ", t1 != null);
Assert.assertTrue("same by user ", t1 == l.getByUserName("mine"));
Assert.assertTrue("same by system ", t1 == l.getBySystemName(getSystemName(getNumToTest1())));
Assert.assertNotNull("t1 real object returned ", t1);
Assert.assertEquals("same by user ", t1, l.getByUserName("mine"));
Assert.assertEquals("same by system ", t1, l.getBySystemName(getSystemName(getNumToTest1())));

Sensor t2 = l.newSensor(getSystemName(getNumToTest1()), "mine");
Assert.assertTrue("t2 real object returned ", t2 != null);
Assert.assertNotNull("t2 real object returned ", t2);
// check
Assert.assertTrue("same new ", t1 == t2);
Assert.assertEquals("same new ", t1, t2);
}

@Test
public void testMisses() {
// try to get nonexistant sensors
Assert.assertTrue(null == l.getByUserName("foo"));
Assert.assertTrue(null == l.getBySystemName("bar"));
Assert.assertNull(l.getByUserName("foo"));
Assert.assertNull(l.getBySystemName("bar"));
}

@Test
public void testMoveUserName() {
Sensor t1 = l.provideSensor("" + getNumToTest1());
Sensor t2 = l.provideSensor("" + getNumToTest2());
t1.setUserName("UserName");
Assert.assertTrue(t1 == l.getByUserName("UserName"));
Assert.assertEquals(t1, l.getByUserName("UserName"));

t2.setUserName("UserName");
Assert.assertTrue(t2 == l.getByUserName("UserName"));
Assert.assertEquals(t2, l.getByUserName("UserName"));

Assert.assertTrue(null == t1.getUserName());
Assert.assertNull(t1.getUserName());
}

@Test
@@ -36,7 +36,7 @@ public void testBlankThrows() {
public void testCreatesiM() {
jmri.Memory im = l.provideMemory("iM");
Assert.assertNotNull("iM created",im);
Assert.assertEquals("correct system name","IMIM",im.getSystemName());
Assert.assertEquals("correct system name","IMiM",im.getSystemName());
}

@Before

0 comments on commit 1dcf5b2

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