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.entities.Herd;
8
import edu.ucsb.cs156.happiercows.repositories.GameRepository;
9
import edu.ucsb.cs156.happiercows.repositories.FarmerRepository;
10
import edu.ucsb.cs156.happiercows.repositories.HerdRepository;
11
import edu.ucsb.cs156.happiercows.repositories.UserRepository;
12
import edu.ucsb.cs156.jobs.services.JobContext;
13
import edu.ucsb.cs156.jobs.services.JobContextConsumer;
14
import lombok.AllArgsConstructor;
15
import lombok.Getter;
16
17
import java.util.Optional;
18
19
@AllArgsConstructor
20
public class SetCowHealthJob implements JobContextConsumer {
21
22
    private long gameID;
23
    private double newCowHealth;
24
25
    @Getter
26
    private GameRepository gameRepository;
27
    @Getter
28
    private FarmerRepository farmerRepository;
29
    @Getter
30
    private UserRepository userRepository;
31
    @Getter
32
    private HerdRepository herdRepository;
33
34
    @Override
35
    public void accept(JobContext ctx) throws Exception {
36 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
        ctx.log("Setting cow health...");
37
38
        Optional<Game> game = gameRepository.findById(gameID);
39
40
41 1 1. accept : negated conditional → KILLED
        if (game.isPresent()) {
42 1 1. accept : negated conditional → KILLED
            if (!GameGate.shouldProcess(game.get(), gameRepository, ctx)) {
43
                return;
44
            }
45 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
            ctx.log("Game " + game.get().getName());
46
47
            Iterable<Farmer> allFarmer = farmerRepository.findByGameId(game.get().getId());
48
49
            for (Farmer farmer : allFarmer) {
50
                User user = farmer.getUser();
51 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());
52 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);
53 1 1. accept : removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setCowHealth → KILLED
                farmer.setCowHealth(newCowHealth);
54
                farmerRepository.save(farmer);
55
                for (Herd herd : herdRepository.findByGameIdAndUserId(game.get().getId(), farmer.getUserId())) {
56 1 1. accept : removed call to edu/ucsb/cs156/happiercows/entities/Herd::setHealth → KILLED
                    herd.setHealth(newCowHealth);
57
                    herdRepository.save(herd);
58
                }
59
            }
60
61 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
            ctx.log("Cow health has been set!");
62
        } else {
63 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));
64
        }
65
66
    }
67
}

Mutations

36

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

41

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

42

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

45

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

51

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

52

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

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/happiercows/entities/Farmer::setCowHealth → KILLED

56

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

61

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

63

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