CommonStatsJob.java

1
package edu.ucsb.cs156.happiercows.jobs;
2
3
import java.time.LocalDateTime;
4
5
import edu.ucsb.cs156.happiercows.entities.Commons;
6
import edu.ucsb.cs156.happiercows.entities.Profit;
7
import edu.ucsb.cs156.happiercows.entities.User;
8
import edu.ucsb.cs156.happiercows.entities.UserCommons;
9
import edu.ucsb.cs156.happiercows.repositories.CommonsRepository;
10
import edu.ucsb.cs156.happiercows.repositories.ProfitRepository;
11
import edu.ucsb.cs156.happiercows.repositories.UserCommonsRepository;
12
import edu.ucsb.cs156.happiercows.repositories.UserRepository;
13
import edu.ucsb.cs156.happiercows.services.jobs.JobContext;
14
import edu.ucsb.cs156.happiercows.services.jobs.JobContextConsumer;
15
import edu.ucsb.cs156.happiercows.services.AverageCowHealthService;
16
17
import edu.ucsb.cs156.happiercows.entities.CommonStats;
18
import edu.ucsb.cs156.happiercows.repositories.CommonStatsRepository;
19
import lombok.AllArgsConstructor;
20
import lombok.Getter;
21
22
@AllArgsConstructor
23
public class CommonStatsJob implements JobContextConsumer {
24
25
    @Getter
26
    AverageCowHealthService averageCowHealthService;
27
28
    @Getter
29
    CommonStatsRepository commonStatsRepository;
30
31
    @Getter
32
    UserCommonsRepository userCommonsRepository;
33
34
    @Getter
35
    CommonsRepository commonsRepository;
36
37
38
    @Override
39
    public void accept (JobContext ctx) throws Exception{
40
41 1 1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED
        ctx.log("Starting to record commons stats");
42
        Iterable<Commons> allCommons = commonsRepository.findAll();
43
44
        for(Commons commons: allCommons){
45
            long commonId = commons.getId();
46 1 1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED
            ctx.log("Starting to record stats for common: " + commons.getName());
47
            double avgHealth = averageCowHealthService.getAverageCowHealth(commonId);
48
            Iterable<UserCommons> userCommonsList = userCommonsRepository.findByCommonsId(commonId);
49
            Integer numCows = 0;
50
51
            for(UserCommons userCommons: userCommonsList){
52 1 1. accept : Replaced integer addition with subtraction → KILLED
                numCows += userCommons.getNumOfCows();
53
            }
54
55
            CommonStats stats = CommonStats.builder()
56
            .commonsId(commonId)
57
            .numCows(numCows)
58
            .avgHealth(avgHealth)
59
            .timestamp(LocalDateTime.now())
60
            .build();
61
62
            commonStatsRepository.save(stats);
63 1 1. accept : removed call to edu/ucsb/cs156/happiercows/services/jobs/JobContext::log → KILLED
            ctx.log("Saved stats for common: " + commons.getName());
64
        }
65
    }
66
}

Mutations

41

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

46

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

52

1.1
Location : accept
Killed by : edu.ucsb.cs156.happiercows.jobs.CommonStatsJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.jobs.CommonStatsJobTests]/[method:test_common_stats()]
Replaced integer addition with subtraction → KILLED

63

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

Active mutators

Tests examined


Report generated by PIT 1.7.3