test: completed test for Client

This commit is contained in:
Yannik Bretschneider 2021-06-08 02:47:36 +02:00
parent be08c6f1c4
commit 8d536ddcb0

View File

@ -0,0 +1,53 @@
package uulm.teamname.marvelous.server.netconnector;
import org.java_websocket.WebSocket;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import uulm.teamname.marvelous.gamelibrary.json.JSON;
import uulm.teamname.marvelous.gamelibrary.messages.ErrorMessage;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.*;
class ClientTest {
Client client;
WebSocket socket;
SUID suid;
@BeforeEach
void setUp() {
socket = mock(WebSocket.class);
suid = new SUID("ClientName", "DeviceID");
client = new Client(socket);
}
@Test
void clientGetsCreatedEmpty() {
assertThat(client.getState()).isEqualTo(ClientState.Blank);
assertThat(client.getId()).isNull();
assertThat(client.getSocket()).isEqualTo(socket);
}
@Test
void sendError() {
client.sendError("SomeMessage");
verify(socket).send("{\"messageType\":\"ERROR\",\"message\":\"SomeMessage\",\"type\":0}");
}
@Test
void sendMessage() {
var stringRepresentingErrorMessage = "{\"messageType\":\"ERROR\",\"message\":\"SomeMessage\",\"type\":0}";
var errorMessage = new ErrorMessage();
errorMessage.message = "SomeMessage";
errorMessage.type = 0;
client.sendMessage(errorMessage);
verify(socket).send(stringRepresentingErrorMessage);
}
}