diff --git a/src/test/java/fr/iut_fbleau/info/but3/automation/rock_paper_scissors/play/PlayControllerTest.java b/src/test/java/fr/iut_fbleau/info/but3/automation/rock_paper_scissors/play/PlayControllerTest.java index 1e0cd10..4fad370 100644 --- a/src/test/java/fr/iut_fbleau/info/but3/automation/rock_paper_scissors/play/PlayControllerTest.java +++ b/src/test/java/fr/iut_fbleau/info/but3/automation/rock_paper_scissors/play/PlayControllerTest.java @@ -4,6 +4,7 @@ import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.ddd.DomainService; import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.ddd.Stub; import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.configuration.PlayConfiguration; import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain.Move; +import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain.Result; import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain.RockPaperScissorsPlayer; import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.spi.CpuPick; import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.spi.FakeCpuPicker; @@ -24,8 +25,6 @@ import org.springframework.test.web.servlet.MockMvc; import java.util.stream.Stream; -import static fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain.RockPaperScissorsPlayer.LOOSE; -import static fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain.RockPaperScissorsPlayer.WIN; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -45,14 +44,14 @@ public class PlayControllerTest { public static Stream scenario() { return Stream.of( - Arguments.of(Move.ROCK, Move.SCISSORS, WIN), - Arguments.of(Move.ROCK, Move.PAPER, LOOSE) + Arguments.of(Move.ROCK, Move.SCISSORS, Result.WIN), + Arguments.of(Move.ROCK, Move.PAPER, Result.LOOSE) ); } @ParameterizedTest @MethodSource("scenario") - void shouldReturnWinResult_whenPlayerPlaysRock(Move playerMove, Move cpuMove, String expectedResult) throws Exception { + void shouldReturnWinResult_whenPlayerPlaysRock(Move playerMove, Move cpuMove, Result expectedResult) throws Exception { FakeCpuConfiguration.cpuPick.setNextMove(cpuMove); mockMvc.perform( post(PLAY_ENDPOINT) @@ -64,7 +63,7 @@ public class PlayControllerTest { """, playerMove)) .contentType(MediaType.APPLICATION_JSON_VALUE) ).andExpect(status().isOk()) - .andExpect(jsonPath("$.result").value(expectedResult)) + .andExpect(jsonPath("$.result").value(expectedResult.toString())) .andExpect(jsonPath("$.cpu").value(cpuMove.name())); } diff --git a/src/test/java/fr/iut_fbleau/info/but3/automation/rock_paper_scissors/play/domain/MoveTest.java b/src/test/java/fr/iut_fbleau/info/but3/automation/rock_paper_scissors/play/domain/MoveTest.java index 2fd5b03..5e1eb97 100644 --- a/src/test/java/fr/iut_fbleau/info/but3/automation/rock_paper_scissors/play/domain/MoveTest.java +++ b/src/test/java/fr/iut_fbleau/info/but3/automation/rock_paper_scissors/play/domain/MoveTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.MethodSource; import java.util.stream.Stream; @@ -20,15 +21,25 @@ class MoveTest { @ParameterizedTest(name = "{0} should beat {1}") @MethodSource("winnable") void should_win(Move move1, Move move2) { - assertTrue(move1.beats(move2)); + assertEquals(Result.WIN ,move1.beats(move2)); } @ParameterizedTest(name = "{1} should not beat {0}") @MethodSource("winnable") void should_loose(Move move1, Move move2) { - assertFalse(move2.beats(move1)); + assertEquals(Result.LOOSE ,move2.beats(move1)); } + + + + @ParameterizedTest(name = "{0} should be equal {0}") + @EnumSource(Move.class) + void should_equal(Move move) { + assertEquals(Result.EQUAL,move.beats(move)); + } + + static Stream winnable(){ return Stream.of( Arguments.of(Move.ROCK,Move.SCISSORS),