Commit 34498092 authored by Winfried's avatar Winfried

fixed null bug

parent 29470c3d
......@@ -128,7 +128,14 @@ public class IncomingMessagesInterpreter {
result.playerOneActive = object.getJSONObject("content").getBoolean("playerOneActive");
result.indexOfChangedCoreElement = object.getJSONObject("content").getInt("indexOfChangedCoreElement");
result.newIpIndex = object.getJSONObject("content").getInt("newIpIndex");
result.newOpCode = object.getJSONObject("content").getString("newOpCode");
Object o = object.getJSONObject("content").get("newOpCode");
if (o == null || o.equals(null)) {
result.newOpCode = null;
} else {
result.newOpCode = object.getJSONObject("content").getString("newOpCode");
}
result.oldIpIndex = object.getJSONObject("content").getInt("oldIpIndex");
return result;
......
......@@ -151,4 +151,29 @@ public class SerializationTest {
assertThat(content.state, is(newContent.state));
}
@Test
public void testGameStatusNullMessage() {
IncomingMessagesInterpreter interpreter = new IncomingMessagesInterpreter();
OutgoingMessagesSerializer serializer = new OutgoingMessagesSerializer();
CwGameStatusContent content = new CwGameStatusContent();
content.playerOneActive = true;
content.oldIpIndex = -1;
content.newIpIndex = 1;
content.indexOfChangedCoreElement = -1;
content.newOpCode = null;
String parsedMessage = serializer.serializeGameStatusMessage(content);
assertThat(interpreter.getMessageType(parsedMessage), is(CwMessageType.GameStatus));
CwGameStatusContent newContent = interpreter.parseGameStatusMessage(parsedMessage);
assertThat(content.indexOfChangedCoreElement, is(newContent.indexOfChangedCoreElement));
assertThat(content.newIpIndex, is(newContent.newIpIndex));
assertThat(content.oldIpIndex, is(newContent.oldIpIndex));
assertThat(content.newOpCode, is(newContent.newOpCode));
assertThat(content.playerOneActive, is(newContent.playerOneActive));
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment