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.

53 lines
1.2 KiB

  1. package de.edu.hsfulda.ciip.tdd;
  2. import static org.hamcrest.CoreMatchers.equalTo;
  3. import static org.hamcrest.CoreMatchers.not;
  4. import static org.junit.Assert.*;
  5. import java.util.Arrays;
  6. import java.util.List;
  7. import org.junit.Rule;
  8. import org.junit.Test;
  9. import org.mockito.Mock;
  10. import org.mockito.junit.MockitoJUnit;
  11. import org.mockito.junit.MockitoRule;
  12. public class StatusAliveTest {
  13. @Rule
  14. public MockitoRule mockitoRule = MockitoJUnit.rule();
  15. @Mock
  16. State dead;
  17. @Test
  18. public void changeToDeadIfOneAliveNeighbor() {
  19. // arrange
  20. State stateAlive = new StateAlive();
  21. List<State> neigborStates = Arrays.asList(stateAlive,dead,dead,dead,dead,dead,dead,dead);
  22. // act
  23. State result = stateAlive.nextBy(neigborStates);
  24. // assert
  25. assertNotNull("",result);
  26. assertThat("changed to dead", result.getClass(), not(equalTo(stateAlive.getClass())));
  27. }
  28. @Test
  29. public void KeepSateAliveWithTwoLivingNeighbors() {
  30. // arrange
  31. State stateAlive = new StateAlive();
  32. List<State> neigborStates = Arrays.asList(stateAlive,stateAlive,dead,dead,dead,dead,dead,dead);
  33. // act
  34. State result = stateAlive.nextBy(neigborStates);
  35. // assert
  36. assertNotNull("",result);
  37. assertThat("Still alive", result.getClass(), (equalTo(stateAlive.getClass())));
  38. }
  39. }