SetCowHealthJob.java

1
package edu.ucsb.cs156.happiercows.jobs;
2
3
4
import edu.ucsb.cs156.happiercows.entities.Commons;
5
import edu.ucsb.cs156.happiercows.entities.User;
6
import edu.ucsb.cs156.happiercows.entities.UserCommons;
7
import edu.ucsb.cs156.happiercows.repositories.CommonsRepository;
8
import edu.ucsb.cs156.happiercows.repositories.UserCommonsRepository;
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 commonsID;
21
    private double newCowHealth;
22
23
    @Getter
24
    private CommonsRepository commonsRepository;
25
    @Getter
26
    private UserCommonsRepository userCommonsRepository;
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<Commons> commons = commonsRepository.findById(commonsID);
35
36
37 1 1. accept : negated conditional → KILLED
        if (commons.isPresent()) {
38 1 1. accept : negated conditional → KILLED
            if (!CommonsGate.shouldProcess(commons.get(), commonsRepository, ctx)) {
39
                return;
40
            }
41 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
            ctx.log("Commons " + commons.get().getName());
42
43
            Iterable<UserCommons> allUserCommons = userCommonsRepository.findByCommonsId(commons.get().getId());
44
45
            for (UserCommons userCommons : allUserCommons) {
46
                User user = userCommons.getUser();
47 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
                ctx.log("User: " + user.getFullName() + ", numCows: " + userCommons.getNumOfCows() + ", cowHealth: " + userCommons.getCowHealth());
48 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
                ctx.log(" old cow health: " + userCommons.getCowHealth() + ", new cow health: " + newCowHealth);
49 1 1. accept : removed call to edu/ucsb/cs156/happiercows/entities/UserCommons::setCowHealth → KILLED
                userCommons.setCowHealth(newCowHealth);
50
                userCommonsRepository.save(userCommons);
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 commons found for id %d", commonsID));
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_commons_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_commons_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_commons_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/UserCommons::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_commons_found()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0