@Test
 public void amoebeShouldBeSetToASquare() {
   Amoebe amoebe = AmoebeFactory.get(this.compassProvider, Game.Color.RED);
   int[] position = {0, 0};
   Square square = SquareFactory.get(position);
   amoebe.setSquare(square);
   assertTrue(amoebe.getSquare().getPosition()[0] == 0);
   assertTrue(amoebe.getSquare().getPosition()[1] == 0);
 }
 @Test
 public void amoebeShouldExcrement() {
   Amoebe amoebe = AmoebeFactory.get(this.compassProvider, Game.Color.RED);
   int[] position = {0, 0};
   Square square = SquareFactory.get(position);
   amoebe.setSquare(square);
   square.enterSquare(amoebe);
   assertTrue(square.getFoodcubes().size() == 6);
   amoebe.excrement();
   assertTrue(square.getFoodcubes().size() == 8);
 }
 @Test
 public void amoebeShouldDie() {
   Amoebe amoebe = AmoebeFactory.get(this.compassProvider, Game.Color.RED);
   int[] position = {0, 0};
   Square square = SquareFactory.get(position);
   amoebe.setSquare(square);
   square.enterSquare(amoebe);
   assertTrue(square.getAmoebesList().size() == 1);
   amoebe.die();
   assertTrue(square.getAmoebesList().size() == 0);
 }
Beispiel #4
0
 /** creates all the squares required */
 private void createSquares() {
   for (int i = 0; i < board.length; i++) {
     for (int j = 0; j < board[i].length; j++) {
       int[] position = {i, j};
       board[i][j] = SquareFactory.get(position);
       /*
        * While I admit, that this static factory method does get the
        * `new` out of view, it does not add much flexibility to the
        * application (but it does add complexity, a dangerous combination).
        * I think, you actually mean to inject the factory as an instance,
        * so that you can rebind the factory if needed.
        */
     }
   }
 }