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.jobs.services.JobContext;
11
import edu.ucsb.cs156.jobs.services.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/jobs/services/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 1 1. accept : negated conditional → KILLED
            if (!CommonsGate.shouldProcess(commonMilked, commonsRepository, ctx)) {
42
                return;
43
            }
44
            String name = commonMilked.getName();
45
            double milkPrice = commonMilked.getMilkPrice();
46 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
            ctx.log("Milking cows for Commons: " + name + ", Milk Price: " + formatDollars(milkPrice));
47
48
            Iterable<UserCommons> allUserCommons = userCommonsRepository.findByCommonsId(commonMilked.getId());
49
50
            for (UserCommons userCommons : allUserCommons) {
51 1 1. accept : removed call to edu/ucsb/cs156/happiercows/jobs/MilkTheCowsJob::milkCows → KILLED
                MilkTheCowsJob.milkCows(ctx, commonMilked, userCommons, profitRepository, userCommonsRepository);
52
            }
53
            
54
55 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
            ctx.log("Cows have been milked!");
56
        } else {
57 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));
58
        }
59
    }
60
61
}

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/jobs/services/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

41

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

46

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

51

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

55

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

57

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

Active mutators

Tests examined


Report generated by PIT 1.17.0