Skip to content
Permalink
Browse files
Update JsonSignalHeadHttpServiceTest.java
remove unused calls to set variables null
Add nullChecks
icklesteve committed Sep 6, 2022
1 parent 554142d commit 0b53ea83694edd52d5a3c15b375e1fe009293007
Showing 1 changed file with 5 additions and 4 deletions.
}
@Test
public void testDoPost() throws JmriException, JsonException {
//create a signalhead for testing
String sysName = "IH1";
String userName = "SH1";
SignalHead s = new jmri.implementation.VirtualSignalHead(sysName, userName);
jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).register(s);
assertNotNull(s);

JsonNode result = null;
JsonNode message = null;
JsonNode result;
JsonNode message;

//set signalhead to Green and verify change
message = mapper.createObjectNode().put(JSON.NAME, userName).put(JSON.STATE, SignalHead.GREEN);

COLLECTOR-SAHAB / covering test: JsonSignalHeadHttpServiceTest

mapper._jsonFactory._rootCharSymbols._seed=-236497483 only occurs in the original version.

COLLECTOR-SAHAB / covering test: JsonSignalHeadHttpServiceTest

mapper._jsonFactory._rootCharSymbols._seed=-236406135 only occurs in the patched version.

result = service.doPost(JsonSignalHead.SIGNAL_HEAD, userName, message, new JsonRequest(locale, JSON.V5, JSON.GET, 42));
validate(result);
assertEquals(SignalHead.GREEN, s.getState());
assertEquals(SignalHead.GREEN, result.path(JSON.DATA).path(JSON.STATE).asInt());

// try to set to FLASHLUNAR, which should not be allowed for this signalHead,
// so check for error, and verify state does not change
result = null;
message = null;
try {
message = mapper.createObjectNode().put(JSON.NAME, userName).put(JSON.STATE, SignalHead.FLASHLUNAR);
result = service.doPost(JsonSignalHead.SIGNAL_HEAD, userName, message, new JsonRequest(locale, JSON.V5, JSON.GET, 42));
assertNotNull(result);
fail("Expected exception not thrown");
} catch (JsonException ex) {
assertEquals(400, ex.getCode());
}
assertEquals(SignalHead.GREEN, s.getState());
assertEquals(false, s.getHeld());
// set signalmast to Held, then verify
message = mapper.createObjectNode().put(JSON.NAME, userName).put(JSON.STATE, SignalHead.HELD);
result = service.doPost(JsonSignalHead.SIGNAL_HEAD, userName, message, new JsonRequest(locale, JSON.V5, JSON.GET, 42));
assertNotNull(result);
assertEquals(true, s.getHeld());

assertEquals(true, s.getHeld());
// set signalmast to something other than Held, then verify Held is released
message = mapper.createObjectNode().put(JSON.NAME, userName).put(JSON.STATE, SignalHead.RED);
result = service.doPost(JsonSignalHead.SIGNAL_HEAD, userName, message, new JsonRequest(locale, JSON.V5, JSON.GET, 42));
assertNotNull(result);
assertEquals(false, s.getHeld());
}

@Test

0 comments on commit 0b53ea8

Please sign in to comment.