GameQueryAdapter.java

1
package org.hplr.game.infrastructure.dbadapter.adapters;
2
3
import lombok.extern.slf4j.Slf4j;
4
import org.hplr.game.core.enums.Status;
5
import org.hplr.game.core.usecases.port.dto.GameSelectDto;
6
import org.hplr.game.core.usecases.port.out.query.SelectAllGamesQueryInterface;
7
import org.hplr.game.core.usecases.port.out.query.SelectCreatedGamesByPlayerIdNotMatchingQueryInterface;
8
import org.hplr.game.core.usecases.port.out.query.SelectGameByGameIdQueryInterface;
9
import org.hplr.game.core.usecases.port.out.query.SelectGamesByStatusAndPlayerIdQueryInterface;
10
import org.hplr.game.infrastructure.dbadapter.entities.GameEntity;
11
import org.hplr.game.infrastructure.dbadapter.mappers.GameDatabaseMapper;
12
import org.hplr.game.infrastructure.dbadapter.repositories.GameRepository;
13
import org.springframework.stereotype.Service;
14
15
import java.util.*;
16
17
@Service
18
@Slf4j
19
public class GameQueryAdapter implements
20
        SelectGameByGameIdQueryInterface,
21
        SelectAllGamesQueryInterface,
22
        SelectGamesByStatusAndPlayerIdQueryInterface,
23
        SelectCreatedGamesByPlayerIdNotMatchingQueryInterface {
24
    final GameRepository gameRepository;
25
26
    public GameQueryAdapter(GameRepository gameRepository) {
27
        this.gameRepository = gameRepository;
28
    }
29
30
    @Override
31
    public Optional<GameSelectDto> selectGameByGameId(UUID gameId) {
32
        GameEntity gameEntity = gameRepository.findByGameId(gameId).orElseThrow(NoSuchElementException::new);
33 1 1. selectGameByGameId : replaced return value with Optional.empty for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::selectGameByGameId → KILLED
        return Optional.of(GameDatabaseMapper.toDto(gameEntity));
34
    }
35
36
    @Override
37
    public List<GameSelectDto> selectAllGames() {
38
        List<GameEntity> gameEntityList = gameRepository.findAll();
39
        List<GameSelectDto> gameSelectDtoList = new ArrayList<>();
40 1 1. selectAllGames : removed call to java/util/List::forEach → KILLED
        gameEntityList.forEach(
41
                game -> {
42
                    try{
43
                        gameSelectDtoList.add(GameDatabaseMapper.toDto(game));
44
45
                    } catch (Exception e){
46
                       log.error("Game with id {} is not valid", game.getGameId());
47
                    }
48
                });
49 1 1. selectAllGames : replaced return value with Collections.emptyList for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::selectAllGames → KILLED
        return  gameSelectDtoList;
50
51
    }
52
53
    @Override
54
    public List<GameSelectDto> selectGamesByStatusAndPlayerId(Status status, UUID playerId) {
55
        ArrayList<GameEntity> gameEntityFilteredList;
56
        List<GameEntity> gameEntityList = gameRepository.findAllByStatus(status);
57 2 1. lambda$selectGamesByStatusAndPlayerId$2 : replaced boolean return with false for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$2 → KILLED
2. lambda$selectGamesByStatusAndPlayerId$2 : replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$2 → KILLED
        List<GameEntity> gameEntityListFirstSide = gameEntityList.stream().filter(gameEntity -> gameEntity
58
                .getFirstGameSide()
59
                .getGamePlayerDataEntityList()
60
                .stream()
61 2 1. lambda$selectGamesByStatusAndPlayerId$1 : replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$1 → KILLED
2. lambda$selectGamesByStatusAndPlayerId$1 : replaced boolean return with false for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$1 → KILLED
                .anyMatch(playerData -> Objects.equals(playerId, playerData.getPlayerEntity().getUserId())))
62
                .toList();
63 2 1. lambda$selectGamesByStatusAndPlayerId$4 : replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$4 → KILLED
2. lambda$selectGamesByStatusAndPlayerId$4 : negated conditional → KILLED
        List<GameEntity> gameEntityListSecondSide = gameEntityList.stream().filter(gameEntity -> Objects.nonNull(gameEntity.getSecondGameSide()) && gameEntity
64
                        .getSecondGameSide()
65
                        .getGamePlayerDataEntityList()
66
                        .stream()
67 3 1. lambda$selectGamesByStatusAndPlayerId$3 : replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$3 → KILLED
2. lambda$selectGamesByStatusAndPlayerId$4 : negated conditional → KILLED
3. lambda$selectGamesByStatusAndPlayerId$3 : replaced boolean return with false for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$3 → KILLED
                        .anyMatch(playerData -> Objects.equals(playerId, playerData.getPlayerEntity().getUserId())))
68
                .toList();
69
        gameEntityFilteredList = new ArrayList<>(gameEntityListFirstSide);
70
        gameEntityFilteredList.addAll(gameEntityListSecondSide);
71
        List<GameSelectDto> gameSelectDtoList = new ArrayList<>();
72 1 1. selectGamesByStatusAndPlayerId : removed call to java/util/ArrayList::forEach → KILLED
        gameEntityFilteredList.forEach(
73
                game -> {
74
                    try{
75
                        gameSelectDtoList.add(GameDatabaseMapper.toDto(game));
76
77
                    } catch (Exception e){
78
                        log.error("Game with id {} is not valid", game.getGameId());
79
                    }
80
                });
81 1 1. selectGamesByStatusAndPlayerId : replaced return value with Collections.emptyList for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::selectGamesByStatusAndPlayerId → KILLED
        return  gameSelectDtoList;
82
    }
83
84
    @Override
85
    public List<GameSelectDto> selectCreatedGamesByPlayerIdNotMatching(UUID playerId) {
86
        List<GameEntity> gameEntityList = gameRepository.findAllByStatus(Status.CREATED);
87
        List<GameEntity> gameEntityFiltered = gameEntityList
88
                .stream()
89 2 1. lambda$selectCreatedGamesByPlayerIdNotMatching$7 : replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectCreatedGamesByPlayerIdNotMatching$7 → KILLED
2. lambda$selectCreatedGamesByPlayerIdNotMatching$7 : replaced boolean return with false for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectCreatedGamesByPlayerIdNotMatching$7 → KILLED
                .filter(gameEntity -> gameEntity.getFirstGameSide().getGamePlayerDataEntityList()
90
                        .stream()
91 2 1. lambda$selectCreatedGamesByPlayerIdNotMatching$6 : replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectCreatedGamesByPlayerIdNotMatching$6 → KILLED
2. lambda$selectCreatedGamesByPlayerIdNotMatching$6 : replaced boolean return with false for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectCreatedGamesByPlayerIdNotMatching$6 → KILLED
                        .noneMatch(gamePlayerDataEntity -> Objects.equals(playerId,gamePlayerDataEntity.getPlayerEntity().getUserId()))).toList()
92
                ;
93 1 1. selectCreatedGamesByPlayerIdNotMatching : replaced return value with Collections.emptyList for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::selectCreatedGamesByPlayerIdNotMatching → KILLED
        return gameEntityFiltered.stream().map(GameDatabaseMapper::toDto).toList();
94
95
    }
96
}

Mutations

33

1.1
Location : selectGameByGameId
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:get_existent_game_and_succeed()]
replaced return value with Optional.empty for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::selectGameByGameId → KILLED

40

1.1
Location : selectAllGames
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:select_all_games_and_succeed()]
removed call to java/util/List::forEach → KILLED

49

1.1
Location : selectAllGames
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:select_all_games_and_succeed()]
replaced return value with Collections.emptyList for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::selectAllGames → KILLED

57

1.1
Location : lambda$selectGamesByStatusAndPlayerId$2
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:select_games_by_status_and_succeed()]
replaced boolean return with false for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$2 → KILLED

2.2
Location : lambda$selectGamesByStatusAndPlayerId$2
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:select_games_by_status_and_succeed()]
replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$2 → KILLED

61

1.1
Location : lambda$selectGamesByStatusAndPlayerId$1
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:select_games_by_status_and_succeed()]
replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$1 → KILLED

2.2
Location : lambda$selectGamesByStatusAndPlayerId$1
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:select_games_by_status_and_succeed()]
replaced boolean return with false for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$1 → KILLED

63

1.1
Location : lambda$selectGamesByStatusAndPlayerId$4
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:select_games_by_status_and_succeed()]
replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$4 → KILLED

2.2
Location : lambda$selectGamesByStatusAndPlayerId$4
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:select_games_by_status_and_succeed()]
negated conditional → KILLED

67

1.1
Location : lambda$selectGamesByStatusAndPlayerId$3
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:select_games_by_status_and_succeed()]
replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$3 → KILLED

2.2
Location : lambda$selectGamesByStatusAndPlayerId$4
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:select_games_by_status_and_succeed()]
negated conditional → KILLED

3.3
Location : lambda$selectGamesByStatusAndPlayerId$3
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:select_games_by_status_and_succeed()]
replaced boolean return with false for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectGamesByStatusAndPlayerId$3 → KILLED

72

1.1
Location : selectGamesByStatusAndPlayerId
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:select_games_by_status_and_succeed()]
removed call to java/util/ArrayList::forEach → KILLED

81

1.1
Location : selectGamesByStatusAndPlayerId
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:select_games_by_status_and_succeed()]
replaced return value with Collections.emptyList for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::selectGamesByStatusAndPlayerId → KILLED

89

1.1
Location : lambda$selectCreatedGamesByPlayerIdNotMatching$7
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:find_created_games_not_belonging_to_player_and_succeed()]
replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectCreatedGamesByPlayerIdNotMatching$7 → KILLED

2.2
Location : lambda$selectCreatedGamesByPlayerIdNotMatching$7
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:find_created_games_not_belonging_to_player_and_succeed()]
replaced boolean return with false for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectCreatedGamesByPlayerIdNotMatching$7 → KILLED

91

1.1
Location : lambda$selectCreatedGamesByPlayerIdNotMatching$6
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:find_created_games_not_belonging_to_player_and_succeed()]
replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectCreatedGamesByPlayerIdNotMatching$6 → KILLED

2.2
Location : lambda$selectCreatedGamesByPlayerIdNotMatching$6
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:find_created_games_not_belonging_to_player_and_succeed()]
replaced boolean return with false for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::lambda$selectCreatedGamesByPlayerIdNotMatching$6 → KILLED

93

1.1
Location : selectCreatedGamesByPlayerIdNotMatching
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameQueryAdapterTests]/[method:find_created_games_not_belonging_to_player_and_succeed()]
replaced return value with Collections.emptyList for org/hplr/game/infrastructure/dbadapter/adapters/GameQueryAdapter::selectCreatedGamesByPlayerIdNotMatching → KILLED

Active mutators

Tests examined


Report generated by PIT 1.16.1