Skip to content

Commit

Permalink
Add test for user name already in use
Browse files Browse the repository at this point in the history
  • Loading branch information
jacwah committed Aug 10, 2015
1 parent c92a2ac commit a44a9cf
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private String getTestMod() {
private Server server;
private TestClient client1;
private int userId;
private final String client1UserName = "Tester1";
private AvailableModsMessage mods;

@Before
Expand All @@ -61,7 +62,7 @@ public void setup() throws IOException, InterruptedException {
assertTrue("Server did not start correctly. Perhaps it is already running?", server.getClients().size() > 0);

client1 = new TestClient();
client1.send(new LoginMessage("Tester"));
client1.send(new LoginMessage(client1UserName));

WelcomeMessage welcome = client1.await(WelcomeMessage.class);
assertEquals(200, welcome.getStatus());
Expand Down Expand Up @@ -104,7 +105,7 @@ public void testUserOnlineOffline() throws InterruptedException, UnknownHostExce
List<UserStatusMessage> users = client2.awaitMany(6, UserStatusMessage.class);
System.out.println("Online users: " + users);
// There is no determined order in which the UserStatusMessages are received, so it is harder to make any assertions.
assertTrue(users.stream().filter(mess -> mess.getName().equals("Tester")).findAny().isPresent());
assertTrue(users.stream().filter(mess -> mess.getName().equals(client1UserName)).findAny().isPresent());
assertTrue(users.stream().filter(mess -> mess.getName().equals("Test2")).findAny().isPresent());
assertTrue(users.stream().filter(mess -> mess.getName().equals("AI Fighter")).findAny().isPresent());
assertTrue(users.stream().filter(mess -> mess.getName().equals("AI Loser")).findAny().isPresent());
Expand All @@ -119,6 +120,14 @@ public void testUserOnlineOffline() throws InterruptedException, UnknownHostExce
assertEquals(client2id, statusMessage.getUserId());
assertEquals("Test2", statusMessage.getName());
}

@Test(timeout = 5000)
public void testSameUserName() throws IOException, InterruptedException {
TestClient client2 = new TestClient();
client2.send(new LoginMessage(client1UserName));
WelcomeMessage welcomeMessage = client2.await(WelcomeMessage.class);
assertEquals(false, welcomeMessage.isOK());
}

@Test(timeout = 10000)
public void testStartGame() throws InterruptedException, IOException {
Expand Down

0 comments on commit a44a9cf

Please sign in to comment.