Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

58 řádky
2.3 KiB

  1. import static org.junit.Assert.assertFalse;
  2. import static org.junit.Assert.assertTrue;
  3. import org.junit.Test;
  4. import com.fasterxml.jackson.databind.node.ObjectNode;
  5. import commands.BasicCommands;
  6. import commands.CheckMessageIsNotNullOnTell;
  7. import events.Initalize;
  8. import play.libs.Json;
  9. import structures.GameState;
  10. import structures.basic.Tile;
  11. import utils.BasicObjectBuilders;
  12. /**
  13. * This is an example of a JUnit test. In this case, we want to be able to test the logic
  14. * of our system without needing to actually start the web server. We do this by overriding
  15. * the altTell method in BasicCommands, which means whenever a command would normally be sent
  16. * to the front-end it is instead discarded. We can manually simulate messages coming from the
  17. * front-end by calling the processEvent method on the appropriate event processor.
  18. * @author Richard
  19. *
  20. */
  21. public class InitalizationTest {
  22. /**
  23. * This test simply checks that a boolean vairable is set in GameState when we call the
  24. * initalize method for illustration.
  25. */
  26. @Test
  27. public void checkInitalized() {
  28. // First override the alt tell variable so we can issue commands without a running front-end
  29. CheckMessageIsNotNullOnTell altTell = new CheckMessageIsNotNullOnTell(); // create an alternative tell
  30. BasicCommands.altTell = altTell; // specify that the alternative tell should be used
  31. // As we are not starting the front-end, we have no GameActor, so lets manually create
  32. // the components we want to test
  33. GameState gameState = new GameState(); // create state storage
  34. Initalize initalizeProcessor = new Initalize(); // create an initalize event processor
  35. assertFalse(gameState.gameInitalised); // check we have not initalized
  36. // lets simulate recieveing an initalize message
  37. ObjectNode eventMessage = Json.newObject(); // create a dummy message
  38. initalizeProcessor.processEvent(null, gameState, eventMessage); // send it to the initalize event processor
  39. assertTrue(gameState.gameInitalised); // check that this updated the game state
  40. // lets also check that running commands don't actually do anything, since we have no front-end
  41. Tile tile = BasicObjectBuilders.loadTile(3, 2); // create a tile
  42. BasicCommands.drawTile(null, tile, 0); // draw tile, but will use altTell, so nothing should happen
  43. }
  44. }