forked from tpapendieck/ciip-examples
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.
77 lines
2.0 KiB
77 lines
2.0 KiB
package de.edu.hsfulda.ciip.tdd;
|
|
|
|
import static org.mockito.Mockito.any;
|
|
import static org.hamcrest.CoreMatchers.equalTo;
|
|
import static org.junit.Assert.*;
|
|
import static org.mockito.Mockito.doReturn;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
|
|
import org.hamcrest.CoreMatchers;
|
|
import org.junit.Rule;
|
|
import org.junit.Test;
|
|
import org.mockito.ArgumentCaptor;
|
|
import org.mockito.Mock;
|
|
import org.mockito.junit.MockitoJUnit;
|
|
import org.mockito.junit.MockitoRule;
|
|
|
|
public class GameCellTest {
|
|
|
|
@Rule
|
|
public MockitoRule mockitoRule = MockitoJUnit.rule();
|
|
|
|
@Mock
|
|
State initialState;
|
|
|
|
@Mock
|
|
State changedState;
|
|
|
|
@Test
|
|
public void reportsInitiallyProvidesState() {
|
|
GameCell cell = new GameCell(initialState);
|
|
|
|
State result = cell.getState();
|
|
|
|
assertThat("initial state returned", result, equalTo(initialState));
|
|
}
|
|
|
|
@Test
|
|
public void changesStateWhenRequested() {
|
|
GameCell cell = new GameCell(initialState);
|
|
when(initialState.nextBy(any(List.class))).thenReturn(changedState);
|
|
|
|
cell.calculateNextGen();
|
|
verify(initialState).nextBy(any(List.class));
|
|
|
|
cell.activateNextGeneration();
|
|
State result = cell.getState();
|
|
assertThat("initial state returned", result, equalTo(changedState));
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Test
|
|
|
|
public void passesNeigbourStatesForStateChangeCalculation() {
|
|
GameCell cell = new GameCell(initialState);
|
|
List<State> neighborStates = Arrays.asList(mock(State.class), mock(State.class), mock(State.class),
|
|
mock(State.class));
|
|
for (State state : neighborStates) {
|
|
cell.addNeigbour(new GameCell(state));
|
|
}
|
|
|
|
cell.calculateNextGen();
|
|
ArgumentCaptor<List> passedStates = ArgumentCaptor.forClass(List.class);
|
|
verify(initialState).nextBy(passedStates.capture());
|
|
|
|
List<State> statesPassed = passedStates.getValue();
|
|
for (State state : neighborStates) {
|
|
assertThat(statesPassed, CoreMatchers.hasItem(state));
|
|
}
|
|
}
|
|
|
|
}
|