Commit a7b7341e authored by Benedikt Geißler's avatar Benedikt Geißler 🐸

Write assert statements in a more elegant way

And indent JSONStringer methods in serializeStartMessage() nicely.
parent 5276eca0
......@@ -84,14 +84,14 @@ public class OutgoingMessagesSerializer {
public String serializeStartMessage(CwStartContent content) {
String result = new JSONStringer()
.object()
.key("content")
.object()
.key("content")
.object()
.key("fullState").value(String.join(
NetworkConstants.REDCODESEPARATOR, content.fullState))
.key("players").value(content.players)
.endObject()
.key("version").value(packetVersion)
.key("packageType").value("start")
.key("players").value(content.players)
.endObject()
.key("version").value(packetVersion)
.key("packageType").value("start")
.endObject().toString();
return result;
}
......
......@@ -32,7 +32,7 @@ public class ClientLoginTest {
receivedLogin = interpreter.getMessageType(data) == CwMessageType.Login;
}
boolean receivedLogin;
private boolean receivedLogin;
}
@Test
......
package gone.lib.network.test;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import gone.lib.common.ClientRole;
import gone.lib.common.RcStandard;
import gone.lib.network.json.CwGameStatusContent;
......@@ -9,7 +12,7 @@ import gone.lib.network.json.CwReadyContent;
import gone.lib.network.json.CwStartContent;
import gone.lib.network.serialization.IncomingMessagesInterpreter;
import gone.lib.network.serialization.OutgoingMessagesSerializer;
import org.junit.Assert;
import org.junit.Test;
import java.util.LinkedList;
......@@ -35,11 +38,11 @@ public class SerializationTest {
CwGameStatusContent newContent = interpreter.parseGameStatusMessage(parsedMessage);
Assert.assertEquals(content.indexOfChangedCoreElement, newContent.indexOfChangedCoreElement);
Assert.assertEquals(content.newIpIndex, newContent.newIpIndex);
Assert.assertEquals(content.oldIpIndex, newContent.oldIpIndex);
Assert.assertEquals(content.newOpCode, newContent.newOpCode);
Assert.assertEquals(content.playerOneActive, newContent.playerOneActive);
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));
}
@Test
......@@ -56,8 +59,8 @@ public class SerializationTest {
CwLoginContent newContent = interpreter.parseLoginMessage(parsedMessage);
Assert.assertEquals(content.name, newContent.name);
Assert.assertEquals(content.role, newContent.role);
assertThat(content.name, is(newContent.name));
assertThat(content.role, is(newContent.role));
}
@Test
......@@ -76,9 +79,9 @@ public class SerializationTest {
CwLoginOkContent newContent = interpreter.parseLoginOkMessage(parsedMessage);
Assert.assertEquals(content.lineLength, newContent.lineLength);
Assert.assertEquals(content.coreSize, newContent.coreSize);
Assert.assertEquals(content.clientMustWait, newContent.clientMustWait);
assertThat(content.lineLength, is(newContent.lineLength));
assertThat(content.coreSize, is(newContent.coreSize));
assertThat(content.clientMustWait, is(newContent.clientMustWait));
}
@Test
......@@ -97,11 +100,10 @@ public class SerializationTest {
CwReadyContent newContent = interpreter.parseReadyMessage(parsedMessage);
Assert.assertEquals(newContent.warriorRedcode.size(), content.warriorRedcode.size());
newContent.warriorRedcode.get(0).equals(content.warriorRedcode.get(0));
newContent.warriorRedcode.get(1).equals(content.warriorRedcode.get(1));
newContent.warriorRedcode.get(2).equals(content.warriorRedcode.get(2));
assertThat(newContent.warriorRedcode.size(), is(content.warriorRedcode.size()));
assertThat(newContent.warriorRedcode.get(0), is(content.warriorRedcode.get(0)));
assertThat(newContent.warriorRedcode.get(1), is(content.warriorRedcode.get(1)));
assertThat(newContent.warriorRedcode.get(2), is(content.warriorRedcode.get(2)));
}
@Test
......@@ -123,8 +125,8 @@ public class SerializationTest {
CwStartContent newContent = interpreter.parseStartMessage(parsedMessage);
Assert.assertEquals(content.players, newContent.players);
assertThat(content.players, is(newContent.players));
assertThat(content.fullState, is(newContent.fullState));
Assert.assertEquals(newContent.fullState.size(), content.fullState.size());
newContent.fullState.get(0).equals(content.fullState.get(0));
......
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