|
|
@ -1,6 +1,7 @@ |
|
|
|
package de.edu.hsfulda.ccip.tdd.withdependencies; |
|
|
|
|
|
|
|
import static org.junit.Assert.assertThat; |
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
@ -15,16 +16,20 @@ import org.mockito.Mockito; |
|
|
|
|
|
|
|
class GameOfLifeCellTest { |
|
|
|
|
|
|
|
private GameOfLifeStateChangeListener stateChangeListener = |
|
|
|
Mockito.mock(GameOfLifeStateChangeListener.class); |
|
|
|
|
|
|
|
private GameOfLifeStatus status = Mockito.mock(GameOfLifeStatus.class, "initial state"); |
|
|
|
|
|
|
|
private GameOfLifeCell gameOfLifeCell; |
|
|
|
|
|
|
|
private List<GameOfLifeCell> neighbors; |
|
|
|
private GameOfLifeCell neigborCell = Mockito.mock(GameOfLifeCell.class); |
|
|
|
private GameOfLifeCell neigborCell = Mockito.mock(GameOfLifeCell.class,"neighbor"); |
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
void setUp() throws Exception { |
|
|
|
gameOfLifeCell = new GameOfLifeCell(status); |
|
|
|
Mockito.doReturn(status).when(status).calculateNextBy(Mockito.anyList()); |
|
|
|
gameOfLifeCell = new GameOfLifeCell(status,stateChangeListener); |
|
|
|
neighbors = Arrays.asList(neigborCell, neigborCell, neigborCell, neigborCell, neigborCell, neigborCell, |
|
|
|
neigborCell, neigborCell); |
|
|
|
|
|
|
@ -73,4 +78,28 @@ class GameOfLifeCellTest { |
|
|
|
assertThat("status changed", currentState, CoreMatchers.equalTo(newState)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void callsChangeListenerWhenStateChanges() throws Exception { |
|
|
|
GameOfLifeStatus newState = Mockito.mock(GameOfLifeStatus.class, "new state"); |
|
|
|
Mockito |
|
|
|
.doReturn(newState) |
|
|
|
.when(status) |
|
|
|
.calculateNextBy(Mockito.anyList()); |
|
|
|
|
|
|
|
gameOfLifeCell.caclulateNextState(); |
|
|
|
|
|
|
|
Mockito.verify(stateChangeListener).stateChangedIn(gameOfLifeCell); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void doesNotCallsChangeListenerWhenStateNotChanges() throws Exception { |
|
|
|
Mockito.doReturn(status) |
|
|
|
.when(status).calculateNextBy(Mockito.anyList()); |
|
|
|
|
|
|
|
|
|
|
|
gameOfLifeCell.caclulateNextState(); |
|
|
|
|
|
|
|
Mockito.verify(stateChangeListener,Mockito.never()).stateChangedIn(gameOfLifeCell); |
|
|
|
|
|
|
|
} |
|
|
|
} |