CommonStatsService.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.CommonStats;
7
import edu.ucsb.cs156.happiercows.repositories.CommonsRepository;
8
import edu.ucsb.cs156.happiercows.repositories.CommonStatsRepository;
9
import edu.ucsb.cs156.happiercows.repositories.UserCommonsRepository;
10
11
@Service("CommonStatsService")
12
public class CommonStatsService {
13
14
    @Autowired
15
    CommonStatsRepository commonStatsRepository;
16
17
    @Autowired
18
    CommonsRepository commonsRepository;
19
20
    @Autowired
21
    UserCommonsRepository userCommonsRepository;
22
23
    @Autowired
24
    private AverageCowHealthService averageCowHealthService;
25
26
    public CommonStats createCommonStats(Long commonsId) {
27
28
        commonsRepository.findById(commonsId)
29 1 1. lambda$createCommonStats$0 : replaced return value with null for edu/ucsb/cs156/happiercows/services/CommonStatsService::lambda$createCommonStats$0 → KILLED
            .orElseThrow(() -> new IllegalArgumentException(String.format("Commons with id %d not found", commonsId)));
30
        
31
        double avgHealth = averageCowHealthService.getAverageCowHealth(commonsId);
32
        int totalNumCows = averageCowHealthService.getTotalNumCows(commonsId);
33
34
        CommonStats stats = CommonStats.builder()
35
                .commonsId(commonsId)
36
                .numCows(totalNumCows)
37
                .avgHealth(avgHealth)
38
                .build();
39
40 1 1. createCommonStats : replaced return value with null for edu/ucsb/cs156/happiercows/services/CommonStatsService::createCommonStats → KILLED
        return stats;
41
    }
42
43
    public CommonStats createAndSaveCommonStats(Long commonsId) {
44
        
45
        CommonStats stats = createCommonStats(commonsId);
46
        commonStatsRepository.save(stats);
47
48 1 1. createAndSaveCommonStats : replaced return value with null for edu/ucsb/cs156/happiercows/services/CommonStatsService::createAndSaveCommonStats → KILLED
        return stats;
49
    }
50
51
}

Mutations

29

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

40

1.1
Location : createCommonStats
Killed by : edu.ucsb.cs156.happiercows.services.CommonStatsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.CommonStatsServiceTests]/[method:test_saveStatsMultipleUsers()]
replaced return value with null for edu/ucsb/cs156/happiercows/services/CommonStatsService::createCommonStats → KILLED

48

1.1
Location : createAndSaveCommonStats
Killed by : edu.ucsb.cs156.happiercows.services.CommonStatsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.CommonStatsServiceTests]/[method:test_saveStatsMultipleUsers()]
replaced return value with null for edu/ucsb/cs156/happiercows/services/CommonStatsService::createAndSaveCommonStats → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3