Skip to content

Commit

Permalink
fixed unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
superernie77 committed Feb 21, 2017
1 parent c730524 commit 30b35b2
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,37 @@ public void testStopBroadcast(){

@Test
public void testStartGame(){
when(gameEngine.getWorld(anyInt())).thenReturn(mock(SpaceWorld.class));
Session session = mock(Session.class);
when(session.getRemote()).thenReturn(mock(RemoteEndpoint.class));

serverEngine.startGame(0,0, mock(Session.class));
serverEngine.startGame(0,0, session);

// world with player has been created and started to run
assertTrue(serverEngine.getPlayerWorldMap().size() == 1);
assertTrue(serverEngine.getWorldFutureMap().size() == 1);
assertTrue(serverEngine.getPlayerSessionMap().size() == 1);

// broadcasted once
verify(session, times(1)).getRemote();
}

@Test
public void startGameTwice(){
serverEngine.startGame(0,0, mock(Session.class));
serverEngine.startGame(0,0, mock(Session.class));
when(gameEngine.getWorld(anyInt())).thenReturn(mock(SpaceWorld.class));
Session session = mock(Session.class);
when(session.getRemote()).thenReturn(mock(RemoteEndpoint.class));


serverEngine.startGame(0,0, session);
serverEngine.startGame(0,0, session);

// game only started once
assertTrue(serverEngine.getPlayerWorldMap().size() == 1);
assertTrue(serverEngine.getWorldFutureMap().size() == 1);
assertTrue(serverEngine.getPlayerSessionMap().size() == 1);

verify(session, times(1)).getRemote();
}

@Test
Expand Down

0 comments on commit 30b35b2

Please sign in to comment.