Skip to content

Commit

Permalink
fix: fixed nullpointer
Browse files Browse the repository at this point in the history
  • Loading branch information
Toto-hitori committed Apr 9, 2024
1 parent 28160d1 commit b902cfb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public GameResponseDto apply(Game game) {
.correctlyAnsweredQuestions(game.getCorrectlyAnsweredQuestions())
.actualRound(game.getActualRound())
.roundDuration(game.getRoundDuration())
.roundStartTime(Instant.ofEpochMilli(game.getRoundStartTime()).toString())
.roundStartTime(game.getRoundStartTime() != null? Instant.ofEpochMilli(game.getRoundStartTime()).toString(): null)
.isGameOver(game.isGameOver())
.build();
}
Expand Down
7 changes: 4 additions & 3 deletions api/src/test/java/lab/en2b/quizapi/game/GameServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void setUp() {
.questions(new ArrayList<>())
.rounds(9L)
.actualRound(0L)
.roundStartTime(0L)
.correctlyAnsweredQuestions(0L)
.language("en")
.roundDuration(30)
Expand All @@ -170,7 +171,7 @@ public void startRound(){
GameResponseDto result = defaultGameResponseDto;
result.setActualRound(1L);
result.setId(1L);
result.setRoundStartTime(defaultGame.getRoundStartTime());
result.setRoundStartTime(Instant.ofEpochMilli(defaultGame.getRoundStartTime()).toString());
assertEquals(result, gameDto);
}

Expand Down Expand Up @@ -220,7 +221,7 @@ public void getCurrentQuestionRoundFinished() {
when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion);
when(userService.getUserByAuthentication(authentication)).thenReturn(defaultUser);
gameService.startRound(1L,authentication);
defaultGame.setRoundStartTime(Instant.now().minusSeconds(100).toString());
defaultGame.setRoundStartTime(Instant.now().minusSeconds(100).toEpochMilli());
assertThrows(IllegalStateException.class, () -> gameService.getCurrentQuestion(1L,authentication));
}

Expand Down Expand Up @@ -285,7 +286,7 @@ public void answerQuestionWhenRoundHasFinished(){
when(questionService.findRandomQuestion(any())).thenReturn(defaultQuestion);
gameService.newGame(authentication);
gameService.startRound(1L, authentication);
defaultGame.setRoundStartTime(Instant.now().minusSeconds(100).toString());
defaultGame.setRoundStartTime(Instant.now().minusSeconds(100).toEpochMilli());
assertThrows(IllegalStateException.class, () -> gameService.answerQuestion(1L, new GameAnswerDto(1L), authentication));
}

Expand Down

0 comments on commit b902cfb

Please sign in to comment.