ReportService.java

1
package edu.ucsb.cs156.happiercows.services;
2
3
import org.springframework.beans.factory.annotation.Autowired;
4
import org.springframework.stereotype.Service;
5
6
import edu.ucsb.cs156.happiercows.entities.Commons;
7
import edu.ucsb.cs156.happiercows.entities.Report;
8
import edu.ucsb.cs156.happiercows.entities.ReportLine;
9
import edu.ucsb.cs156.happiercows.entities.UserCommons;
10
import edu.ucsb.cs156.happiercows.repositories.CommonsRepository;
11
import edu.ucsb.cs156.happiercows.repositories.ReportLineRepository;
12
import edu.ucsb.cs156.happiercows.repositories.ReportRepository;
13
import edu.ucsb.cs156.happiercows.repositories.UserCommonsRepository;
14
15
@Service("ReportService")
16
public class ReportService {
17
18
    @Autowired
19
    ReportRepository reportRepository;
20
21
    @Autowired
22
    ReportLineRepository reportLineRepository;
23
24
    @Autowired
25
    CommonsRepository commonsRepository;
26
27
    @Autowired
28
    UserCommonsRepository userCommonsRepository;
29
30
    public Report createReport(Long commonsId) {
31
        Report report = createAndSaveReportHeader(commonsId);
32
        
33
        Iterable<UserCommons> allUserCommons = userCommonsRepository.findByCommonsId(commonsId);
34
35
36
        for (UserCommons userCommons : allUserCommons) {
37
               createAndSaveReportLine(report, userCommons);
38
        }
39
40 1 1. createReport : replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::createReport → KILLED
        return report;
41
    }
42
43
    public Report createAndSaveReportHeader(Long commonsId) {
44
        Commons commons = commonsRepository.findById(commonsId)
45 1 1. lambda$createAndSaveReportHeader$0 : replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::lambda$createAndSaveReportHeader$0 → KILLED
                .orElseThrow(() -> new RuntimeException(String.format("Commons with id %d not found", commonsId)));
46
47
        Report report = Report.builder()
48
                .commonsId(commonsId)
49
50
                .name(commons.getName())
51
                .cowPrice(commons.getCowPrice())
52
                .milkPrice(commons.getMilkPrice())
53
                .startingBalance(commons.getStartingBalance())
54
                .startingDate(commons.getStartingDate())
55
                .showLeaderboard(commons.isShowLeaderboard())
56
                .carryingCapacity(commons.getCarryingCapacity())
57
                .degradationRate(commons.getDegradationRate())
58
                .belowCapacityHealthUpdateStrategy(commons.getBelowCapacityHealthUpdateStrategy())
59
                .aboveCapacityHealthUpdateStrategy(commons.getAboveCapacityHealthUpdateStrategy())
60
                .numUsers(commonsRepository.getNumUsers(commonsId).orElse(0))
61
                .numCows(commonsRepository.getNumCows(commonsId).orElse(0))
62
63
                .build();
64
65
        reportRepository.save(report);
66 1 1. createAndSaveReportHeader : replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::createAndSaveReportHeader → KILLED
        return report;
67
    }
68
69
    public ReportLine createAndSaveReportLine(Report report, UserCommons userCommons) {
70
        ReportLine reportLine = ReportLine.builder()
71
                .reportId(report.getId())
72
                .userId(userCommons.getUser().getId())
73
                .username(userCommons.getUsername())
74
                .totalWealth(userCommons.getTotalWealth())
75
                .numOfCows(userCommons.getNumOfCows())
76
                .avgCowHealth(userCommons.getCowHealth())
77
                .cowsBought(userCommons.getCowsBought())
78
                .cowsSold(userCommons.getCowsSold())
79
                .cowDeaths(userCommons.getCowDeaths())
80
                .build();
81
82
        reportLineRepository.save(reportLine);
83 1 1. createAndSaveReportLine : replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::createAndSaveReportLine → KILLED
        return reportLine;
84
    }
85
86
}

Mutations

40

1.1
Location : createReport
Killed by : edu.ucsb.cs156.happiercows.services.ReportServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.ReportServiceTests]/[method:test_createAndSaveReport()]
replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::createReport → KILLED

45

1.1
Location : lambda$createAndSaveReportHeader$0
Killed by : edu.ucsb.cs156.happiercows.services.ReportServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.ReportServiceTests]/[method:test_createAndSaveReportHeader_throwsException()]
replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::lambda$createAndSaveReportHeader$0 → KILLED

66

1.1
Location : createAndSaveReportHeader
Killed by : edu.ucsb.cs156.happiercows.services.ReportServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.ReportServiceTests]/[method:test_createAndSaveReportHeader()]
replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::createAndSaveReportHeader → KILLED

83

1.1
Location : createAndSaveReportLine
Killed by : edu.ucsb.cs156.happiercows.services.ReportServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.ReportServiceTests]/[method:test_createAndSaveReportLine()]
replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::createAndSaveReportLine → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3