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.happiercows.services.jobs.JobContext;
11
import edu.ucsb.cs156.happiercows.services.jobs.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/happiercows/services/jobs/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 : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED
            ctx.log("Commons " + commons.get().getName());
39
40
            Iterable<UserCommons> allUserCommons = userCommonsRepository.findByCommonsId(commons.get().getId());
41
42
            for (UserCommons userCommons : allUserCommons) {
43
                User user = userCommons.getUser();
44 1 1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED
                ctx.log("User: " + user.getFullName() + ", numCows: " + userCommons.getNumOfCows() + ", cowHealth: " + userCommons.getCowHealth());
45 1 1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED
                ctx.log(" old cow health: " + userCommons.getCowHealth() + ", new cow health: " + newCowHealth);
46 1 1. accept : removed call to edu/ucsb/cs156/happiercows/entities/UserCommons::setCowHealth → KILLED
                userCommons.setCowHealth(newCowHealth);
47
                userCommonsRepository.save(userCommons);
48
            }
49
50 1 1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED
            ctx.log("Cow health has been set!");
51
        } else {
52 1 1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED
            ctx.log(String.format("No commons found for id %d", commonsID));
53
        }
54
55
    }
56
}

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/happiercows/services/jobs/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_updating_to_new_values_for_multiple()]
removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED

44

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/services/jobs/JobContext::log → 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/happiercows/services/jobs/JobContext::log → KILLED

46

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

50

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/services/jobs/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:error_msg_when_no_commons_found()]
removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3