SetCowHealthJob.java

1
package edu.ucsb.cs156.happiercows.jobs;
2
3
4
import edu.ucsb.cs156.happiercows.entities.Game;
5
import edu.ucsb.cs156.happiercows.entities.User;
6
import edu.ucsb.cs156.happiercows.entities.Farmer;
7
import edu.ucsb.cs156.happiercows.repositories.GameRepository;
8
import edu.ucsb.cs156.happiercows.repositories.FarmerRepository;
9
import edu.ucsb.cs156.happiercows.repositories.UserRepository;
10
import edu.ucsb.cs156.jobs.services.JobContext;
11
import edu.ucsb.cs156.jobs.services.JobContextConsumer;
12
import lombok.AllArgsConstructor;
13
import lombok.Getter;
14
15
import java.util.Optional;
16
17
@AllArgsConstructor
18
public class SetCowHealthJob implements JobContextConsumer {
19
20
    private long gameID;
21
    private double newCowHealth;
22
23
    @Getter
24
    private GameRepository gameRepository;
25
    @Getter
26
    private FarmerRepository farmerRepository;
27
    @Getter
28
    private UserRepository userRepository;
29
30
    @Override
31
    public void accept(JobContext ctx) throws Exception {
32 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
        ctx.log("Setting cow health...");
33
34
        Optional<Game> game = gameRepository.findById(gameID);
35
36
37 1 1. accept : negated conditional → KILLED
        if (game.isPresent()) {
38 1 1. accept : negated conditional → KILLED
            if (!GameGate.shouldProcess(game.get(), gameRepository, ctx)) {
39
                return;
40
            }
41 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
            ctx.log("Game " + game.get().getName());
42
43
            Iterable<Farmer> allFarmer = farmerRepository.findByGameId(game.get().getId());
44
45
            for (Farmer farmer : allFarmer) {
46
                User user = farmer.getUser();
47 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
                ctx.log("User: " + user.getFullName() + ", numCows: " + farmer.getNumOfCows() + ", cowHealth: " + farmer.getCowHealth());
48 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
                ctx.log(" old cow health: " + farmer.getCowHealth() + ", new cow health: " + newCowHealth);
49 1 1. accept : removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setCowHealth → KILLED
                farmer.setCowHealth(newCowHealth);
50
                farmerRepository.save(farmer);
51
            }
52
53 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
            ctx.log("Cow health has been set!");
54
        } else {
55 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
            ctx.log(String.format("No game found for id %d", gameID));
56
        }
57
58
    }
59
}

Mutations

32

1.1
Location : accept
Killed by : edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests]/[method:error_msg_when_no_game_found()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

37

1.1
Location : accept
Killed by : edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests]/[method:error_msg_when_no_game_found()]
negated conditional → KILLED

38

1.1
Location : accept
Killed by : edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests]/[method:test_skips_game_when_game_not_in_progress()]
negated conditional → KILLED

41

1.1
Location : accept
Killed by : edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests]/[method:test_updating_to_new_values_for_multiple()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

47

1.1
Location : accept
Killed by : edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests]/[method:test_updating_to_new_values_for_multiple()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

48

1.1
Location : accept
Killed by : edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests]/[method:test_updating_to_new_values_for_multiple()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

49

1.1
Location : accept
Killed by : edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests]/[method:test_updating_to_new_values_for_multiple()]
removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setCowHealth → KILLED

53

1.1
Location : accept
Killed by : edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests]/[method:test_updating_to_new_values_for_multiple()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

55

1.1
Location : accept
Killed by : edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobTests]/[method:error_msg_when_no_game_found()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1