package uulm.teamname.marvelous.server.netconnector; import org.java_websocket.WebSocket; import org.java_websocket.handshake.ClientHandshake; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType; import uulm.teamname.marvelous.gamelibrary.messages.client.*; import uulm.teamname.marvelous.server.lobbymanager.Participant; import java.lang.reflect.InvocationTargetException; import static org.mockito.Mockito.*; import static org.assertj.core.api.Assertions.*; class UserManagerTest { UserManager manager; Client client1, client2; WebSocket socket1, socket2; SUID suid1, suid2; @BeforeEach void beforeEach() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { socket1 = mock(WebSocket.class); client1 = spy(new Client(socket1)); suid1 = new SUID("name1", "devID1"); when(client1.getId()).thenReturn(suid1); when(client1.getSocket()).thenReturn(socket1); socket2 = mock(WebSocket.class); client2 = spy(new Client(socket2)); suid2 = new SUID("name2", "devID2"); when(client2.getId()).thenReturn(suid2); when(client2.getSocket()).thenReturn(socket2); var c = UserManager.class.getDeclaredConstructor(); c.setAccessible(true); manager = spy(c.newInstance()); } @Test void userIsConnectedTest() { assertThat(manager.getUserCount()).isZero(); assertThat(manager.containsConnection(socket1)).isFalse(); manager.connectUser(socket1); assertThat(manager.getUserCount()).isEqualTo(1); assertThat(manager.containsConnection(socket1)).isTrue(); verify(socket1, never()).send(any(String.class)); } @Test void helloServerMessagesGetAssignedProperly() { manager.messageReceived( socket1, "{\"messageType\":\"HELLO_SERVER\",\"name\":\"SomeAwesomeName\",\"deviceID\":\"YAY\"}"); // TODO: test this } }