GameSideCommandAdapter.java

1
package org.hplr.game.infrastructure.dbadapter.adapters;
2
3
import lombok.RequiredArgsConstructor;
4
import lombok.extern.slf4j.Slf4j;
5
6
import org.hplr.game.core.enums.Status;
7
import org.hplr.game.core.model.GameSnapshot;
8
import org.hplr.game.core.usecases.port.out.command.SaveGameSecondSideCommandInterface;
9
import org.hplr.game.core.usecases.port.out.command.SaveScoreCommandInterface;
10
import org.hplr.game.infrastructure.dbadapter.entities.GameArmyTypeEntity;
11
import org.hplr.game.infrastructure.dbadapter.entities.GameEntity;
12
import org.hplr.game.infrastructure.dbadapter.entities.GameTurnScoreEntity;
13
import org.hplr.game.infrastructure.dbadapter.mappers.GameSideDatabaseMapper;
14
import org.hplr.game.infrastructure.dbadapter.repositories.GameArmyTypeRepository;
15
import org.hplr.game.infrastructure.dbadapter.repositories.GameRepository;
16
17
import org.hplr.elo.core.model.vo.Score;
18
19
import org.hplr.user.infrastructure.dbadapter.entities.PlayerEntity;
20
import org.hplr.user.infrastructure.dbadapter.repositories.PlayerQueryRepository;
21
22
import org.hplr.library.exception.HPLRIllegalStateException;
23
import org.springframework.stereotype.Service;
24
25
import java.util.List;
26
import java.util.NoSuchElementException;
27
28
import static org.hplr.game.infrastructure.dbadapter.adapters.GameCommandAdapter.mapGamePlayerDataEntityList;
29
30
@Service
31
@Slf4j
32
@RequiredArgsConstructor
33
public class GameSideCommandAdapter implements SaveGameSecondSideCommandInterface, SaveScoreCommandInterface {
34
35
    final GameRepository gameRepository;
36
    final PlayerQueryRepository playerQueryRepository;
37
    final GameArmyTypeRepository gameArmyTypeRepository;
38
39
    @Override
40
    public void saveGameSecondSide(GameSnapshot gameSnapshot) {
41
42
        List<PlayerEntity> allPlayerEntityList = playerQueryRepository.findAll();
43 1 1. saveGameSecondSide : negated conditional → KILLED
        if (allPlayerEntityList.isEmpty()) {
44
            throw new HPLRIllegalStateException("Not enough players!");
45
        }
46
        List<GameArmyTypeEntity> armyTypeEntityList = gameArmyTypeRepository.findAll();
47 1 1. saveGameSecondSide : negated conditional → KILLED
        if (armyTypeEntityList.isEmpty()) {
48
            throw new HPLRIllegalStateException("No army types!");
49
        }
50 1 1. lambda$saveGameSecondSide$0 : replaced return value with null for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveGameSecondSide$0 → KILLED
        GameEntity gameEntity = gameRepository.findByGameId(gameSnapshot.gameId().gameId()).orElseThrow(() -> new NoSuchElementException("Game not found!"));
51 1 1. saveGameSecondSide : removed call to org/hplr/game/infrastructure/dbadapter/entities/GameEntity::setSecondGameSide → KILLED
        gameEntity.setSecondGameSide(GameSideDatabaseMapper.fromSnapshot(
52
                gameSnapshot.secondGameSide()));
53 1 1. saveGameSecondSide : removed call to org/hplr/game/infrastructure/dbadapter/entities/GameSideEntity::setGamePlayerDataEntityList → KILLED
        gameEntity.getSecondGameSide().setGamePlayerDataEntityList( mapGamePlayerDataEntityList(gameSnapshot.secondGameSide(), allPlayerEntityList, armyTypeEntityList));
54 1 1. saveGameSecondSide : removed call to org/hplr/game/infrastructure/dbadapter/entities/GameEntity::setStatus → KILLED
        gameEntity.setStatus(Status.AWAITING);
55
        gameRepository.save(gameEntity);
56
    }
57
58
    @Override
59
    public void saveScore(GameSnapshot gameSnapshot, Score score, Boolean firstSide) {
60 1 1. lambda$saveScore$1 : replaced return value with null for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveScore$1 → KILLED
        GameEntity gameEntity = gameRepository.findByGameId(gameSnapshot.gameId().gameId()).orElseThrow(() -> new NoSuchElementException("Game not found!"));
61 1 1. saveScore : negated conditional → KILLED
        if(Boolean.TRUE.equals(firstSide)){
62
            GameTurnScoreEntity gameTurnScoreEntity =
63
                    gameEntity.getFirstGameSide().getTurnScoreEntityList()
64
                            .stream()
65 2 1. lambda$saveScore$2 : replaced boolean return with false for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveScore$2 → KILLED
2. lambda$saveScore$2 : replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveScore$2 → KILLED
                            .filter(scoreEntity-> score.turnNumber().equals(scoreEntity.getTurnNumber()))
66
                            .findFirst()
67 1 1. lambda$saveScore$3 : replaced return value with null for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveScore$3 → KILLED
                            .orElseThrow(() -> new NoSuchElementException("Turn not found"));
68 1 1. saveScore : removed call to org/hplr/game/infrastructure/dbadapter/entities/GameTurnScoreEntity::setTurnScore → KILLED
            gameTurnScoreEntity.setTurnScore(score.turnScore());
69 1 1. saveScore : removed call to org/hplr/game/infrastructure/dbadapter/entities/GameTurnScoreEntity::setTabled → KILLED
            gameTurnScoreEntity.setTabled(score.tabled());
70
   }
71
        else{
72
            GameTurnScoreEntity gameTurnScoreEntity =
73
                  gameEntity.getSecondGameSide().getTurnScoreEntityList()
74
                            .stream()
75 2 1. lambda$saveScore$4 : replaced boolean return with false for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveScore$4 → KILLED
2. lambda$saveScore$4 : replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveScore$4 → KILLED
                            .filter(scoreEntity-> score.turnNumber().equals(scoreEntity.getTurnNumber()))
76
                            .findFirst()
77 1 1. lambda$saveScore$5 : replaced return value with null for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveScore$5 → KILLED
                            .orElseThrow(() -> new NoSuchElementException("Turn not found"));
78 1 1. saveScore : removed call to org/hplr/game/infrastructure/dbadapter/entities/GameTurnScoreEntity::setTurnScore → KILLED
            gameTurnScoreEntity.setTurnScore(score.turnScore());
79 1 1. saveScore : removed call to org/hplr/game/infrastructure/dbadapter/entities/GameTurnScoreEntity::setTabled → KILLED
            gameTurnScoreEntity.setTabled(score.tabled());
80
        }
81
        gameRepository.save(gameEntity);
82
    }
83
}

Mutations

43

1.1
Location : saveGameSecondSide
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:saveGameSecondSide_find_no_armies_and_throw_HPLRIllegalStateException()]
negated conditional → KILLED

47

1.1
Location : saveGameSecondSide
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:saveGameSecondSide_find_no_armies_and_throw_HPLRIllegalStateException()]
negated conditional → KILLED

50

1.1
Location : lambda$saveGameSecondSide$0
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:saveGameSecondSide_find_no_game_and_throw_NoSuchElementException()]
replaced return value with null for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveGameSecondSide$0 → KILLED

51

1.1
Location : saveGameSecondSide
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:saveGameSecondSide_and_succeed()]
removed call to org/hplr/game/infrastructure/dbadapter/entities/GameEntity::setSecondGameSide → KILLED

53

1.1
Location : saveGameSecondSide
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:saveGameSecondSide_and_succeed()]
removed call to org/hplr/game/infrastructure/dbadapter/entities/GameSideEntity::setGamePlayerDataEntityList → KILLED

54

1.1
Location : saveGameSecondSide
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:saveGameSecondSide_and_succeed()]
removed call to org/hplr/game/infrastructure/dbadapter/entities/GameEntity::setStatus → KILLED

60

1.1
Location : lambda$saveScore$1
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:save_score_find_no_game_and_throw_NoSuchElementException()]
replaced return value with null for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveScore$1 → KILLED

61

1.1
Location : saveScore
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:save_score_find_game_get_first_side_and_succeed()]
negated conditional → KILLED

65

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

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

67

1.1
Location : lambda$saveScore$3
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:save_score_find_game_get_wrong_turn_and_throw_NoSuchElementException()]
replaced return value with null for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveScore$3 → KILLED

68

1.1
Location : saveScore
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:save_score_find_game_get_first_side_and_succeed()]
removed call to org/hplr/game/infrastructure/dbadapter/entities/GameTurnScoreEntity::setTurnScore → KILLED

69

1.1
Location : saveScore
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:save_score_find_game_get_first_side_and_succeed()]
removed call to org/hplr/game/infrastructure/dbadapter/entities/GameTurnScoreEntity::setTabled → KILLED

75

1.1
Location : lambda$saveScore$4
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:save_score_find_game_get_second_side_and_succeed()]
replaced boolean return with false for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveScore$4 → KILLED

2.2
Location : lambda$saveScore$4
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:save_score_find_game_get_wrong_turn_and_throw_NoSuchElementException()]
replaced boolean return with true for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveScore$4 → KILLED

77

1.1
Location : lambda$saveScore$5
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:save_score_find_game_get_wrong_turn_and_throw_NoSuchElementException()]
replaced return value with null for org/hplr/game/infrastructure/dbadapter/adapters/GameSideCommandAdapter::lambda$saveScore$5 → KILLED

78

1.1
Location : saveScore
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:save_score_find_game_get_second_side_and_succeed()]
removed call to org/hplr/game/infrastructure/dbadapter/entities/GameTurnScoreEntity::setTurnScore → KILLED

79

1.1
Location : saveScore
Killed by : org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests.[engine:junit-jupiter]/[class:org.hplr.game.infrastructure.dbadapter.adapters.GameSideCommandAdapterTests]/[method:save_score_find_game_get_second_side_and_succeed()]
removed call to org/hplr/game/infrastructure/dbadapter/entities/GameTurnScoreEntity::setTabled → KILLED

Active mutators

Tests examined


Report generated by PIT 1.16.1