Skip to content

Commit

Permalink
tests of normailized name
Browse files Browse the repository at this point in the history
  • Loading branch information
bobjacobsen committed May 9, 2018
1 parent d6bd2d1 commit a3b3577
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 31 deletions.
9 changes: 4 additions & 5 deletions java/test/jmri/jmrix/can/cbus/CbusSensorManagerTest.java
Expand Up @@ -7,6 +7,7 @@
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

/**
Expand Down Expand Up @@ -50,12 +51,10 @@ public void testProvideName() {
Assert.assertTrue("system name correct ", t == l.getBySystemName(getSystemName(getNumToTest1())));
}

@Test
@Override
public void testUpperLower() {
Sensor t = l.provideSensor("MSX0A;+N15E" + getNumToTest2());
String name = t.getSystemName();
Assert.assertNull(l.getSensor(name.toLowerCase()));
@Ignore
@Test
public void testUpperLower() { // ignoring this test due to the system name format, needs to be properly coded
}

@Override
Expand Down
Expand Up @@ -12,6 +12,7 @@
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

/**
Expand Down Expand Up @@ -56,11 +57,9 @@ public void testDefaultSystemName() {
}

@Override
@Ignore
@Test
public void testUpperLower() {
Sensor t = l.provideSensor(getSystemName(getNumToTest2()));
String name = t.getSystemName();
Assert.assertNull(l.getSensor(name.toLowerCase()));
public void testUpperLower() { // ignoring this test due to the system name format, needs to be properly coded
}

@Test
Expand Down
17 changes: 17 additions & 0 deletions java/test/jmri/jmrix/internal/InternalSensorManagerTest.java
Expand Up @@ -23,6 +23,23 @@ 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() {

Expand Down
2 changes: 1 addition & 1 deletion java/test/jmri/jmrix/maple/SerialAddressTest.java
Expand Up @@ -163,7 +163,7 @@ public void testIsInputBitFree() {

@Test
public void testGetUserNameFromSystemName() {
jmri.SensorManager sMgr = memo.getSensorManager();
jmri.SensorManager sMgr = jmri.InstanceManager.sensorManagerInstance();
// create 4 new sensors
sMgr.newSensor("KS16", "userS16");
sMgr.newSensor("KS014", "userS14");
Expand Down
12 changes: 5 additions & 7 deletions java/test/jmri/jmrix/openlcb/OlcbSensorManagerTest.java
Expand Up @@ -7,6 +7,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

/**
Expand Down Expand Up @@ -49,14 +50,11 @@ public void testDefaultSystemName() {
}

@Override
@Ignore
@Test
public void testUpperLower() {
// olcb addresses are hex values requirng 16 digits.
Sensor t = l.provideSensor(getSystemName(getNumToTest2()));
String name = t.getSystemName();
Assert.assertNull(l.getSensor(name.toLowerCase()));
public void testUpperLower() { // ignoring this test due to the system name format, needs to be properly coded
}

@Override
@Test
public void testMoveUserName() {
Expand All @@ -76,7 +74,7 @@ public void testDotted() {
// olcb addresses are hex values requirng 16 digits.
Sensor t = l.provideSensor("MS01.02.03.04.05.06.07.0" + getNumToTest2());
String name = t.getSystemName();
Assert.assertNull(l.getSensor(name.toLowerCase()));
Assert.assertEquals(t, l.getSensor(name));
}

// The minimal setup for log4J
Expand Down
9 changes: 3 additions & 6 deletions java/test/jmri/jmrix/powerline/SerialSensorManagerTest.java
Expand Up @@ -5,6 +5,7 @@
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

/**
Expand Down Expand Up @@ -81,13 +82,9 @@ public void testDefaultSystemName() {
}

@Override
@Ignore
@Test
public void testUpperLower() {
// powerline systems require a module letter(?) which
// isn't provided by makeSystemName();
Sensor t = l.provideSensor(getSystemName(getNumToTest1()));
String name = t.getSystemName();
Assert.assertNull(l.getSensor(name.toLowerCase()));
public void testUpperLower() { // ignoring this test due to the system name format, needs to be properly coded
}

@Test
Expand Down
3 changes: 0 additions & 3 deletions java/test/jmri/jmrix/rps/RpsSensorManagerTest.java
Expand Up @@ -51,9 +51,6 @@ public void testDefaultSystemName() {
public void testUpperLower() {
// RPS sensors use coordinates as their address, and they require a
// 2 characterprefix (for now).
Sensor t = l.provideSensor("RS(0,0,0);(1,0,0);(1,1,0);(0,1,0)");
String name = t.getSystemName();
Assert.assertNull(l.getSensor(name.toLowerCase()));
}

@Test
Expand Down
8 changes: 6 additions & 2 deletions java/test/jmri/managers/AbstractSensorMgrTestBase.java
Expand Up @@ -153,10 +153,14 @@ public void testMoveUserName() {
}

@Test
public void testUpperLower() {
public void testUpperLower() { // this is part of testing of (default) normalization
Sensor t = l.provideSensor("" + getNumToTest2());
String name = t.getSystemName();
Assert.assertNull(l.getSensor(name.toLowerCase()));

int prefixLength = l.getSystemPrefix().length()+1; // 1 for type letter
String lowerName = name.substring(0,prefixLength)+name.substring(prefixLength, name.length()).toLowerCase();

Assert.assertEquals(t, l.getSensor(lowerName));
}

@Test
Expand Down
17 changes: 17 additions & 0 deletions java/test/jmri/managers/InternalSensorManagerTest.java
Expand Up @@ -41,6 +41,23 @@ public void testAsAbstractFactory() {

}

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 testSetGetDefaultState() {

Expand Down
27 changes: 24 additions & 3 deletions java/test/jmri/managers/ProxySensorManagerTest.java
Expand Up @@ -33,6 +33,23 @@ public void testPutGetJ() {
Assert.assertTrue("system name correct ", tj == l.getBySystemName("JS1"));
}

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());
}

public void testPutGetI() {
// create
Sensor ti = l.newSensor("IS1", "mine");
Expand Down Expand Up @@ -98,10 +115,14 @@ public void testMisses() {
Assert.assertTrue(null == l.getBySystemName("bar"));
}

public void testUpperLower() {
Sensor t = l.provideSensor("2");
public void testUpperLower() { // this is part of testing of (default) normalization
Sensor t = l.provideSensor("JS1ABC"); // internal will always accept that name
String name = t.getSystemName();
Assert.assertNull(l.getSensor(name.toLowerCase()));

int prefixLength = l.getSystemPrefix().length()+1; // 1 for type letter
String lowerName = name.substring(0,prefixLength)+name.substring(prefixLength, name.length()).toLowerCase();

Assert.assertEquals(t, l.getSensor(lowerName));
}

public void testRename() {
Expand Down

0 comments on commit a3b3577

Please sign in to comment.