-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 게임이 끝나지않았을때 예외 추가 * feat: 게임 결과 반환 기능 구현
- Loading branch information
Showing
10 changed files
with
206 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 49 additions & 3 deletions
52
src/main/java/mafia/mafiatogether/domain/status/EndStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/mafia/mafiatogether/service/dto/RoomResultPlayerDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package mafia.mafiatogether.service.dto; | ||
|
||
import mafia.mafiatogether.domain.Player; | ||
|
||
public record RoomResultPlayerDto( | ||
String name, | ||
Boolean isAlive, | ||
String job | ||
) { | ||
public static RoomResultPlayerDto of( | ||
final Player player | ||
) { | ||
return new RoomResultPlayerDto( | ||
player.getName(), | ||
player.isAlive(), | ||
player.getJobType().name() | ||
); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/mafia/mafiatogether/service/dto/RoomResultResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package mafia.mafiatogether.service.dto; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.List; | ||
import mafia.mafiatogether.domain.status.EndStatus; | ||
|
||
public record RoomResultResponse( | ||
String winnerJob, | ||
Timestamp endTime, | ||
List<RoomResultPlayerDto> winner, | ||
List<RoomResultPlayerDto> loser | ||
) { | ||
public static RoomResultResponse of( | ||
final EndStatus endStatus | ||
) { | ||
final List<RoomResultPlayerDto> winner = endStatus.getWinner() | ||
.stream() | ||
.map(RoomResultPlayerDto::of) | ||
.toList(); | ||
|
||
final List<RoomResultPlayerDto> loser = endStatus.getLoser() | ||
.stream() | ||
.map(RoomResultPlayerDto::of) | ||
.toList(); | ||
|
||
return new RoomResultResponse( | ||
endStatus.getWinnerJob().name(), | ||
endStatus.getEndTime(), | ||
winner, | ||
loser | ||
); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/java/mafia/mafiatogether/domain/status/EndStatusTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package mafia.mafiatogether.domain.status; | ||
|
||
import java.time.Clock; | ||
import java.util.List; | ||
import mafia.mafiatogether.domain.Player; | ||
import mafia.mafiatogether.domain.job.JobType; | ||
import mafia.mafiatogether.domain.job.Mafia; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class EndStatusTest { | ||
|
||
@Test | ||
void 시민_승리_결과_반환() { | ||
Mafia mafia = new Mafia(); | ||
Player A = Player.create("A"); | ||
A.modifyJob(mafia); | ||
A.kill(); | ||
Player B = Player.create("B"); | ||
B.modifyJob(mafia); | ||
B.kill(); | ||
Player C = Player.create("C"); | ||
Player D = Player.create("D"); | ||
Player E = Player.create("E"); | ||
|
||
List<Player> players = List.of(A, B, C, D, E); | ||
|
||
EndStatus endStatus = EndStatus.create(players, Clock.systemUTC().millis()); | ||
|
||
Assertions.assertThat(endStatus.getWinnerJob()).isEqualTo(JobType.CITIZEN); | ||
Assertions.assertThat(endStatus.getWinner()).containsAll(List.of(C, D, E)); | ||
Assertions.assertThat(endStatus.getLoser()).containsAll(List.of(A, B)); | ||
} | ||
|
||
@Test | ||
void 마피아_승리_결과_반환() { | ||
Mafia mafia = new Mafia(); | ||
Player A = Player.create("A"); | ||
A.modifyJob(mafia); | ||
Player B = Player.create("B"); | ||
B.modifyJob(mafia); | ||
Player C = Player.create("C"); | ||
C.kill(); | ||
Player D = Player.create("D"); | ||
Player E = Player.create("E"); | ||
|
||
List<Player> players = List.of(A, B, C, D, E); | ||
|
||
EndStatus endStatus = EndStatus.create(players, Clock.systemUTC().millis()); | ||
|
||
Assertions.assertThat(endStatus.getWinnerJob()).isEqualTo(JobType.MAFIA); | ||
Assertions.assertThat(endStatus.getLoser()).containsAll(List.of(C, D, E)); | ||
Assertions.assertThat(endStatus.getWinner()).containsAll(List.of(A, B)); | ||
} | ||
} |