MilkTheCowsJobInd.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.UserCommons;
6
import edu.ucsb.cs156.happiercows.repositories.CommonsRepository;
7
import edu.ucsb.cs156.happiercows.repositories.ProfitRepository;
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
import java.util.Optional;
15
16
@AllArgsConstructor
17
public class MilkTheCowsJobInd implements JobContextConsumer {
18
19
    @Getter
20
    private CommonsRepository commonsRepository;
21
    @Getter
22
    private UserCommonsRepository userCommonsRepository;
23
    @Getter
24
    private UserRepository userRepository;
25
    @Getter
26
    private ProfitRepository profitRepository;
27
    @Getter
28
    private long commonsID;
29
30
    public String formatDollars(double amount) {
31 1 1. formatDollars : replaced return value with "" for edu/ucsb/cs156/happiercows/jobs/MilkTheCowsJobInd::formatDollars → KILLED
        return  String.format("$%.2f", amount);
32
    }
33
34
    @Override
35
    public void accept(JobContext ctx) throws Exception {
36 1 1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED
        ctx.log("Starting to milk the cows");
37
        Optional<Commons> commonMilkedOpt = commonsRepository.findById(commonsID);
38
39 1 1. accept : negated conditional → KILLED
        if(commonMilkedOpt.isPresent()){
40
            Commons commonMilked = commonMilkedOpt.get();
41
            String name = commonMilked.getName();
42
            double milkPrice = commonMilked.getMilkPrice();
43 1 1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED
            ctx.log("Milking cows for Commons: " + name + ", Milk Price: " + formatDollars(milkPrice));
44
45
            Iterable<UserCommons> allUserCommons = userCommonsRepository.findByCommonsId(commonMilked.getId());
46
47
            for (UserCommons userCommons : allUserCommons) {
48 1 1. accept : removed call to edu/ucsb/cs156/happiercows/jobs/MilkTheCowsJob::milkCows → KILLED
                MilkTheCowsJob.milkCows(ctx, commonMilked, userCommons, profitRepository, userCommonsRepository);
49
            }
50
            
51
52 1 1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED
            ctx.log("Cows have been milked!");
53
        } else {
54 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));
55
        }
56
    }
57
58
}

Mutations

31

1.1
Location : formatDollars
Killed by : edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobIndTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobIndTests]/[method:test_log_output_with_commons_and_user_commons()]
replaced return value with "" for edu/ucsb/cs156/happiercows/jobs/MilkTheCowsJobInd::formatDollars → KILLED

36

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

39

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

43

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

48

1.1
Location : accept
Killed by : edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobIndTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobIndTests]/[method:test_log_output_with_commons_and_user_commons()]
removed call to edu/ucsb/cs156/happiercows/jobs/MilkTheCowsJob::milkCows → KILLED

52

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

54

1.1
Location : accept
Killed by : edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobIndTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobIndTests]/[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