@Test public void testJoinRoomHasPass() { UserProfile profile = spy(new UserProfile("aa", "bb")); when(service.getUserBySession(anyString())).thenReturn(profile); when(rooms.containsKey(anyString())).thenReturn(true); when(profile.getCurrentroom()).thenReturn(null); Room room = new RoomFFA("aaa", "cc"); when(rooms.get(anyString())).thenReturn(room); Room endRoom = gameServer.joinRoom("aaa", "aaa", "aa"); assertNull(endRoom); room = new RoomFFA("aaa"); when(rooms.get(anyString())).thenReturn(room); endRoom = gameServer.joinRoom("aa", "aa", "aa"); assertNotNull(endRoom); assertEquals(endRoom.getPlayersCount(), 1); }