You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package de.edu.hsfulda.ccip.tdd.withdependencies;
import static org.junit.Assert.assertThat;
import java.util.Arrays; import java.util.Collections; import java.util.List;
import org.hamcrest.CoreMatchers; import org.junit.Ignore; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito;
class GameOfLifeCellTest {
private GameOfLifeStatus status = Mockito.mock(GameOfLifeStatus.class, "initial state");
private GameOfLifeCell gameOfLifeCell;
private List<GameOfLifeCell> neighbors; private GameOfLifeCell neigborCell = Mockito.mock(GameOfLifeCell.class);
@BeforeEach void setUp() throws Exception { gameOfLifeCell = new GameOfLifeCell(status); neighbors = Arrays.asList(neigborCell, neigborCell, neigborCell, neigborCell, neigborCell, neigborCell, neigborCell, neigborCell);
for (GameOfLifeCell neighbor : neighbors) { gameOfLifeCell.addNeighbor(neighbor); } }
@Test void passesNeighborStatusToOwn() {
gameOfLifeCell.caclulateNextState();
ArgumentCaptor<List<GameOfLifeStatus>> listOfNeghborStates = ArgumentCaptor.forClass(List.class); Mockito.verify(status).calculateNextBy(listOfNeghborStates.capture()); assertThat("all neighbor states", listOfNeghborStates.getValue().size(), CoreMatchers.equalTo(neighbors.size())); }
@Test void doesNotChangeStateWhenCalculating() { GameOfLifeStatus newState = Mockito.mock(GameOfLifeStatus.class); Mockito.doReturn(newState).when(status).calculateNextBy(Mockito.anyList());
gameOfLifeCell.caclulateNextState(); GameOfLifeStatus currentState = gameOfLifeCell.getState();
Mockito.verify(status).calculateNextBy(Mockito.anyList());
assertThat("status not changed", currentState, CoreMatchers.equalTo(status));
}
@Test void changesStateWhenRequested() { GameOfLifeStatus newState = Mockito.mock(GameOfLifeStatus.class, "new state"); Mockito.doReturn(newState).when(status).calculateNextBy(Mockito.anyList());
gameOfLifeCell.caclulateNextState(); gameOfLifeCell.updateState();
GameOfLifeStatus currentState = gameOfLifeCell.getState();
Mockito.verify(status).calculateNextBy(Mockito.anyList());
assertThat("status changed", currentState, CoreMatchers.equalTo(newState)); } }
|