Skip to content

Commit

Permalink
handle null name, add empty name to tests,
Browse files Browse the repository at this point in the history
  • Loading branch information
silverailscolo committed Dec 23, 2019
1 parent d654bc4 commit 84f41ba
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
39 changes: 19 additions & 20 deletions java/src/jmri/jmrit/blockboss/BlockBossLogic.java
Expand Up @@ -125,7 +125,7 @@ public class BlockBossLogic extends Siglet implements java.beans.VetoableChangeL
static public final int TRAILINGDIVERGING = 3;
static public final int FACING = 4;

int mode = 0;
private int mode = 0;

/**
* Create an object to drive a specific signal head.
Expand All @@ -134,6 +134,7 @@ public class BlockBossLogic extends Siglet implements java.beans.VetoableChangeL
*/
public BlockBossLogic(@Nonnull String name) {
super(name + Bundle.getMessage("_BlockBossLogic"));
java.util.Objects.requireNonNull(name, "BlockBossLogic name cannot be null");
this.name = name;
log.trace("Create BBL {}", name);

Expand Down Expand Up @@ -229,7 +230,7 @@ public void setSensor5(String name) {
}

/**
* Return the system name of the sensors 1-5 being monitored.
* Get the system name of the sensors 1-5 being monitored.
*
* @return system name; null if no sensor configured
*/
Expand Down Expand Up @@ -281,7 +282,7 @@ public void setTurnout(String name) {
}

/**
* Return the system name of the turnout being monitored.
* Get the system name of the turnout being monitored.
*
* @return system name; null if no turnout configured
*/
Expand Down Expand Up @@ -326,7 +327,7 @@ public void setWatchedSignal1(String name, boolean useFlash) {
}

/**
* Return the system name of the signal head being monitored for first route.
* Get the system name of the signal head being monitored for first route.
*
* @return system name; null if no primary signal head is configured
*/
Expand All @@ -352,7 +353,7 @@ public void setWatchedSignal1Alt(String name) {
}

/**
* Return the system name of the alternate signal head being monitored for first
* Get the system name of the alternate signal head being monitored for first
* route.
*
* @return system name; null if no signal head is configured
Expand All @@ -379,7 +380,7 @@ public void setWatchedSignal2(String name) {
}

/**
* Return the system name of the signal head being monitored for the 2nd route.
* Get the system name of the signal head being monitored for the 2nd route.
*
* @return system name; null if no signal head is configured
*/
Expand All @@ -405,7 +406,7 @@ public void setWatchedSignal2Alt(String name) {
}

/**
* Return the system name of the secondary signal head being monitored for the
* Get the system name of the secondary signal head being monitored for the
* 2nd route.
*
* @return system name; null if no secondary signal head is configured
Expand All @@ -431,7 +432,7 @@ public void setWatchedSensor1(String name) {
}

/**
* Return the original name of the sensor1 being monitored.
* Get the original name of the sensor1 being monitored.
*
* @return original name; null if no sensor is configured
*/
Expand All @@ -456,7 +457,7 @@ public void setWatchedSensor1Alt(String name) {
}

/**
* Return the system name of the sensor1Alt being monitored.
* Get the system name of the sensor1Alt being monitored.
*
* @return system name; null if no sensor is configured
*/
Expand All @@ -481,7 +482,7 @@ public void setWatchedSensor2(String name) {
}

/**
* Return the system name of the sensor2 being monitored.
* Get the system name of the sensor2 being monitored.
*
* @return system name; null if no sensor is configured
*/
Expand All @@ -506,7 +507,7 @@ public void setWatchedSensor2Alt(String name) {
}

/**
* Return the system name of the sensor2Alt being monitored.
* Get the system name of the sensor2Alt being monitored.
*
* @return system name; null if no sensor is configured
*/
Expand Down Expand Up @@ -561,7 +562,7 @@ public boolean getDistantSignal() {
return distantSignal;
}

boolean mHold = false;
private boolean mHold = false;

/**
* Provide the current value of the "hold" parameter.
Expand Down Expand Up @@ -589,7 +590,7 @@ public void setHold(boolean m) {
setOutput(); // to invoke the new state
}

String name;
private String name;

@Nonnull NamedBeanHandle<SignalHead> driveSignal;

Expand Down Expand Up @@ -626,11 +627,10 @@ public void setApproachSensor1(String name) {
if (approachSensor1.getBean() == null) {
log.warn(Bundle.getMessage("BeanXNotFound", Bundle.getMessage("Approach_Sensor1_"), name));
}

}

/**
* Return the system name of the sensor being monitored.
* Get the system name of the sensor being monitored.
*
* @return system name; null if no sensor configured
*/
Expand Down Expand Up @@ -1145,7 +1145,6 @@ void doApproach() {
driveSignal.getBean().setLit(true);
}
}
return;
}

// Due to an older configuration & storage paradigm, this class
Expand Down Expand Up @@ -1184,7 +1183,7 @@ public void retain() {
}

/**
* Return the BlockBossLogic item governing a specific signal head by its name,
* Get the BlockBossLogic item governing a specific signal head by its name,
* having removed it from use.
*
* @param signal name of the signal head object
Expand All @@ -1202,7 +1201,7 @@ public static BlockBossLogic getStoppedObject(String signal) {
}

/**
* Return the BlockBossLogic item governing a specific signal head, having
* Get the BlockBossLogic item governing a specific signal head, having
* removed it from use.
*
* @param sh signal head object
Expand Down Expand Up @@ -1231,7 +1230,7 @@ public static BlockBossLogic getStoppedObject(@Nonnull SignalHead sh) {
}

/**
* Return the BlockBossLogic item governing a specific signal head located from its name.
* Get the BlockBossLogic item governing a specific signal head located from its name.
* <p>
* Unlike {@link BlockBossLogic#getStoppedObject(String signal)} this does
* not remove the object from being used.
Expand All @@ -1250,7 +1249,7 @@ public static BlockBossLogic getExisting(@Nonnull String signal) {
}

/**
* Return the BlockBossLogic item governing a specific signal head object.
* Get the BlockBossLogic item governing a specific signal head object.
* <p>
* Unlike {@link BlockBossLogic#getStoppedObject(String signal)} this does
* not remove the object from being used.
Expand Down
8 changes: 4 additions & 4 deletions java/src/jmri/jmrit/logix/PortalManager.java
Expand Up @@ -7,14 +7,12 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;

import javax.annotation.Nonnull;
import javax.annotation.OverridingMethodsMustInvokeSuper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;

/**
* Basic implementation of a PortalManager.
* <p>
Expand Down Expand Up @@ -73,9 +71,11 @@ public Collection<Portal> getPortalSet() {
/*
* Create a new Portal with a given user name.
*
* @return null if a Portal with the same userName already exists
* @return null if a Portal with the same userName already exists,
* or if an empty userName was requested
*/
public Portal createNewPortal(@Nonnull String userName) {
java.util.Objects.requireNonNull(userName, "Name cannot be null");
// Check that Portal does not already exist
Portal portal;
if (userName.trim().length() > 0) {
Expand Down
11 changes: 10 additions & 1 deletion java/test/jmri/jmrit/blockboss/BlockBossLogicTest.java
Expand Up @@ -179,8 +179,17 @@ public void testSimpleBlockNoNextLimited() throws jmri.JmriException {
// check for basic not-fail if no signal name was set
@Test
public void testSimpleBlockNoSignal() throws jmri.JmriException {

try {
new BlockBossLogic(null);
} catch (java.lang.NullPointerException e) {
// this is expected
}
}

// check for basic not-fail if empty signal name was set
@Test
public void testSimpleBlockEmptyName() throws jmri.JmriException {
try {
new BlockBossLogic("");
} catch (java.lang.IllegalArgumentException e) {
// this is expected
Expand Down
6 changes: 4 additions & 2 deletions java/test/jmri/jmrit/logix/PortalTest.java
Expand Up @@ -23,8 +23,10 @@ public class PortalTest {

@Test
public void testCtor() {
Portal p = _portalMgr.createNewPortal(""); // @Nonnull annotated userName
Assert.assertNull("No User Name", p); // Portals must have a user name
Portal p = _portalMgr.createNewPortal(null);
Assert.assertNull("Null User Name", p); // Portals must have a user name
p = _portalMgr.createNewPortal("");
Assert.assertNull("Empty User Name", p);
p = _portalMgr.createNewPortal("portal_1");
Assert.assertNotNull("Has User Name", p);
}
Expand Down

0 comments on commit 84f41ba

Please sign in to comment.