generated from Arquisoft/wiq_0
-
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.
Merge pull request #242 from Arquisoft/chore/gamesPlayed
Chore/games played
- Loading branch information
Showing
8 changed files
with
51 additions
and
1 deletion.
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
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import lab.en2b.quizapi.commons.user.User; | ||
import lab.en2b.quizapi.commons.user.dtos.UserResponseDto; | ||
import lab.en2b.quizapi.commons.user.UserService; | ||
import lab.en2b.quizapi.game.GameRepository; | ||
import lab.en2b.quizapi.statistics.dtos.StatisticsResponseDto; | ||
import lab.en2b.quizapi.statistics.mappers.StatisticsResponseDtoMapper; | ||
import org.junit.jupiter.api.Assertions; | ||
|
@@ -42,6 +43,9 @@ public class StatisticsServiceTest { | |
@Mock | ||
private StatisticsResponseDtoMapper statisticsResponseDtoMapper; | ||
|
||
@Mock | ||
private GameRepository gameRepository; | ||
|
||
private User defaultUser; | ||
|
||
private Statistics defaultStatistics1; | ||
|
@@ -56,7 +60,7 @@ public class StatisticsServiceTest { | |
|
||
@BeforeEach | ||
public void setUp(){ | ||
this.statisticsService = new StatisticsService(statisticsRepository, userService, statisticsResponseDtoMapper); | ||
this.statisticsService = new StatisticsService(statisticsRepository, userService, statisticsResponseDtoMapper, gameRepository); | ||
this.defaultUser = User.builder() | ||
.id(1L) | ||
.email("[email protected]") | ||
|
@@ -79,6 +83,7 @@ public void setUp(){ | |
.correct(5L) | ||
.wrong(5L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
|
||
this.defaultStatisticsResponseDto1 = StatisticsResponseDto.builder() | ||
|
@@ -88,6 +93,7 @@ public void setUp(){ | |
.total(10L) | ||
.correctRate(50L) | ||
.user(defaultUserResponseDto) | ||
.finishedGames(1L) | ||
.build(); | ||
|
||
this.defaultStatistics2 = Statistics.builder() | ||
|
@@ -96,6 +102,7 @@ public void setUp(){ | |
.correct(7L) | ||
.wrong(3L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
|
||
this.defaultStatisticsResponseDto2 = StatisticsResponseDto.builder() | ||
|
@@ -105,6 +112,7 @@ public void setUp(){ | |
.total(10L) | ||
.correctRate(70L) | ||
.user(defaultUserResponseDto) | ||
.finishedGames(1L) | ||
.build(); | ||
} | ||
|
||
|
@@ -135,6 +143,7 @@ public void getTopTenStatisticsTestWhenThereAreNotTenAndAreEqual(){ | |
.correct(5L) | ||
.wrong(5L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
StatisticsResponseDto defaultStatisticsResponseDto3 = StatisticsResponseDto.builder() | ||
.id(2L) | ||
|
@@ -143,6 +152,7 @@ public void getTopTenStatisticsTestWhenThereAreNotTenAndAreEqual(){ | |
.total(10L) | ||
.correctRate(50L) | ||
.user(defaultUserResponseDto) | ||
.finishedGames(1L) | ||
.build(); | ||
when(statisticsRepository.findAll()).thenReturn(List.of(defaultStatistics1, defaultStatistics3)); | ||
when(statisticsResponseDtoMapper.apply(defaultStatistics1)).thenReturn(defaultStatisticsResponseDto1); | ||
|
@@ -159,41 +169,47 @@ public void getTopTenStatisticsWhenThereAreTen(){ | |
.correct(1L) | ||
.wrong(9L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
Statistics defaultStatistics4 = Statistics.builder() | ||
.id(4L) | ||
.user(defaultUser) | ||
.correct(2L) | ||
.wrong(8L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
Statistics defaultStatistics5 = Statistics.builder() | ||
.id(5L) | ||
.user(defaultUser) | ||
.correct(3L) | ||
.wrong(7L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
Statistics defaultStatistics6 = Statistics.builder() | ||
.id(6L) | ||
.user(defaultUser) | ||
.correct(4L) | ||
.wrong(6L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
Statistics defaultStatistics7 = Statistics.builder() | ||
.id(7L) | ||
.user(defaultUser) | ||
.correct(6L) | ||
.wrong(4L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
Statistics defaultStatistics8 = Statistics.builder() | ||
.id(8L) | ||
.user(defaultUser) | ||
.correct(8L) | ||
.wrong(2L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
List<Statistics> statistics = List.of(defaultStatistics8, defaultStatistics2, defaultStatistics7, | ||
defaultStatistics1, defaultStatistics6, defaultStatistics5, defaultStatistics4, defaultStatistics3); | ||
|
@@ -206,6 +222,7 @@ public void getTopTenStatisticsWhenThereAreTen(){ | |
.wrong(9L) | ||
.total(10L) | ||
.correctRate(10L) | ||
.finishedGames(1L) | ||
.user(defaultUserResponseDto) | ||
.build()); | ||
when(statisticsResponseDtoMapper.apply(defaultStatistics4)).thenReturn(StatisticsResponseDto.builder() | ||
|
@@ -214,6 +231,7 @@ public void getTopTenStatisticsWhenThereAreTen(){ | |
.wrong(8L) | ||
.total(10L) | ||
.correctRate(20L) | ||
.finishedGames(1L) | ||
.user(defaultUserResponseDto) | ||
.build()); | ||
when(statisticsResponseDtoMapper.apply(defaultStatistics5)).thenReturn(StatisticsResponseDto.builder() | ||
|
@@ -222,6 +240,7 @@ public void getTopTenStatisticsWhenThereAreTen(){ | |
.wrong(7L) | ||
.total(10L) | ||
.correctRate(30L) | ||
.finishedGames(1L) | ||
.user(defaultUserResponseDto) | ||
.build()); | ||
when(statisticsResponseDtoMapper.apply(defaultStatistics6)).thenReturn(StatisticsResponseDto.builder() | ||
|
@@ -230,6 +249,7 @@ public void getTopTenStatisticsWhenThereAreTen(){ | |
.wrong(6L) | ||
.total(10L) | ||
.correctRate(40L) | ||
.finishedGames(1L) | ||
.user(defaultUserResponseDto) | ||
.build()); | ||
when(statisticsResponseDtoMapper.apply(defaultStatistics7)).thenReturn(StatisticsResponseDto.builder() | ||
|
@@ -238,6 +258,7 @@ public void getTopTenStatisticsWhenThereAreTen(){ | |
.wrong(4L) | ||
.total(10L) | ||
.correctRate(60L) | ||
.finishedGames(1L) | ||
.user(defaultUserResponseDto) | ||
.build()); | ||
when(statisticsResponseDtoMapper.apply(defaultStatistics8)).thenReturn(StatisticsResponseDto.builder() | ||
|
@@ -246,6 +267,7 @@ public void getTopTenStatisticsWhenThereAreTen(){ | |
.wrong(2L) | ||
.total(10L) | ||
.correctRate(80L) | ||
.finishedGames(1L) | ||
.user(defaultUserResponseDto) | ||
.build()); | ||
List<StatisticsResponseDto> result = statistics.stream().map(statisticsResponseDtoMapper::apply).toList(); | ||
|
@@ -260,48 +282,55 @@ public void getTopTenWhenThereAreMoreThanTen(){ | |
.correct(1L) | ||
.wrong(9L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
Statistics defaultStatistics4 = Statistics.builder() | ||
.id(4L) | ||
.user(defaultUser) | ||
.correct(2L) | ||
.wrong(8L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
Statistics defaultStatistics5 = Statistics.builder() | ||
.id(5L) | ||
.user(defaultUser) | ||
.correct(3L) | ||
.wrong(7L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
Statistics defaultStatistics6 = Statistics.builder() | ||
.id(6L) | ||
.user(defaultUser) | ||
.correct(4L) | ||
.wrong(6L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
Statistics defaultStatistics7 = Statistics.builder() | ||
.id(7L) | ||
.user(defaultUser) | ||
.correct(6L) | ||
.wrong(4L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
Statistics defaultStatistics8 = Statistics.builder() | ||
.id(8L) | ||
.user(defaultUser) | ||
.correct(8L) | ||
.wrong(2L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
Statistics defaultStatistics9 = Statistics.builder() | ||
.id(9L) | ||
.user(defaultUser) | ||
.correct(9L) | ||
.wrong(1L) | ||
.total(10L) | ||
.finishedGames(1L) | ||
.build(); | ||
List<Statistics> statistics = List.of(defaultStatistics9, defaultStatistics8, defaultStatistics2, | ||
defaultStatistics7, defaultStatistics1, defaultStatistics6, defaultStatistics5, defaultStatistics4, | ||
|
@@ -315,6 +344,7 @@ public void getTopTenWhenThereAreMoreThanTen(){ | |
.wrong(9L) | ||
.total(10L) | ||
.correctRate(10L) | ||
.finishedGames(1L) | ||
.user(defaultUserResponseDto) | ||
.build()); | ||
when(statisticsResponseDtoMapper.apply(defaultStatistics4)).thenReturn(StatisticsResponseDto.builder() | ||
|
@@ -323,6 +353,7 @@ public void getTopTenWhenThereAreMoreThanTen(){ | |
.wrong(8L) | ||
.total(10L) | ||
.correctRate(20L) | ||
.finishedGames(1L) | ||
.user(defaultUserResponseDto) | ||
.build()); | ||
when(statisticsResponseDtoMapper.apply(defaultStatistics5)).thenReturn(StatisticsResponseDto.builder() | ||
|
@@ -331,6 +362,7 @@ public void getTopTenWhenThereAreMoreThanTen(){ | |
.wrong(7L) | ||
.total(10L) | ||
.correctRate(30L) | ||
.finishedGames(1L) | ||
.user(defaultUserResponseDto) | ||
.build()); | ||
when(statisticsResponseDtoMapper.apply(defaultStatistics6)).thenReturn(StatisticsResponseDto.builder() | ||
|
@@ -339,6 +371,7 @@ public void getTopTenWhenThereAreMoreThanTen(){ | |
.wrong(6L) | ||
.total(10L) | ||
.correctRate(40L) | ||
.finishedGames(1L) | ||
.user(defaultUserResponseDto) | ||
.build()); | ||
when(statisticsResponseDtoMapper.apply(defaultStatistics7)).thenReturn(StatisticsResponseDto.builder() | ||
|
@@ -347,6 +380,7 @@ public void getTopTenWhenThereAreMoreThanTen(){ | |
.wrong(4L) | ||
.total(10L) | ||
.correctRate(60L) | ||
.finishedGames(1L) | ||
.user(defaultUserResponseDto) | ||
.build()); | ||
when(statisticsResponseDtoMapper.apply(defaultStatistics8)).thenReturn(StatisticsResponseDto.builder() | ||
|
@@ -355,6 +389,7 @@ public void getTopTenWhenThereAreMoreThanTen(){ | |
.wrong(2L) | ||
.total(10L) | ||
.correctRate(80L) | ||
.finishedGames(1L) | ||
.user(defaultUserResponseDto) | ||
.build()); | ||
when(statisticsResponseDtoMapper.apply(defaultStatistics9)).thenReturn(StatisticsResponseDto.builder() | ||
|
@@ -363,6 +398,7 @@ public void getTopTenWhenThereAreMoreThanTen(){ | |
.wrong(1L) | ||
.total(10L) | ||
.correctRate(90L) | ||
.finishedGames(1L) | ||
.user(defaultUserResponseDto) | ||
.build()); | ||
List<StatisticsResponseDto> result = statistics.stream().limit(10). | ||
|