CommonsPlusBuilderService.java

1
package edu.ucsb.cs156.happiercows.services;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Optional;
6
import java.util.stream.Collectors;
7
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.stereotype.Service;
10
11
import edu.ucsb.cs156.happiercows.entities.Commons;
12
import edu.ucsb.cs156.happiercows.entities.CommonsPlus;
13
import edu.ucsb.cs156.happiercows.repositories.CommonsRepository;
14
15
@Service("CommonsPlusBuilderService")
16
public class CommonsPlusBuilderService {
17
    
18
    @Autowired
19
    CommonsRepository commonsRepository;
20
21
    public CommonsPlus toCommonsPlus(Commons c) {
22
        Optional<Integer> numCows = commonsRepository.getNumCows(c.getId());
23
        Optional<Integer> numUsers = commonsRepository.getNumUsers(c.getId());
24
25 1 1. toCommonsPlus : replaced return value with null for edu/ucsb/cs156/happiercows/services/CommonsPlusBuilderService::toCommonsPlus → KILLED
        return CommonsPlus.builder()
26
                .commons(c)
27
                .totalCows(numCows.orElse(0))
28
                .totalUsers(numUsers.orElse(0))
29
                .build();
30
    }
31
32
33
    public Iterable<CommonsPlus> convertToCommonsPlus(Iterable<Commons> iteOfCommons) {
34
        List<Commons> commonsList = new ArrayList<Commons>();
35 1 1. convertToCommonsPlus : removed call to java/lang/Iterable::forEach → KILLED
        iteOfCommons.forEach(commonsList::add);
36
37 1 1. lambda$convertToCommonsPlus$0 : replaced return value with null for edu/ucsb/cs156/happiercows/services/CommonsPlusBuilderService::lambda$convertToCommonsPlus$0 → KILLED
        List<CommonsPlus> commonsPlusList = commonsList.stream().map((c) -> toCommonsPlus(c)).collect(Collectors.toList());
38
39
        ArrayList<CommonsPlus> commonsPlusArrayList = new ArrayList<CommonsPlus>(commonsPlusList);
40
41 1 1. convertToCommonsPlus : replaced return value with null for edu/ucsb/cs156/happiercows/services/CommonsPlusBuilderService::convertToCommonsPlus → KILLED
        return commonsPlusArrayList;
42
    }
43
}

Mutations

25

1.1
Location : toCommonsPlus
Killed by : edu.ucsb.cs156.happiercows.services.CommonsPlusBuilderServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.CommonsPlusBuilderServiceTests]/[method:test_convertToCommonsPlus()]
replaced return value with null for edu/ucsb/cs156/happiercows/services/CommonsPlusBuilderService::toCommonsPlus → KILLED

35

1.1
Location : convertToCommonsPlus
Killed by : edu.ucsb.cs156.happiercows.services.CommonsPlusBuilderServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.CommonsPlusBuilderServiceTests]/[method:test_convertToCommonsPlus()]
removed call to java/lang/Iterable::forEach → KILLED

37

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

41

1.1
Location : convertToCommonsPlus
Killed by : edu.ucsb.cs156.happiercows.services.CommonsPlusBuilderServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.services.CommonsPlusBuilderServiceTests]/[method:test_convertToCommonsPlus()]
replaced return value with null for edu/ucsb/cs156/happiercows/services/CommonsPlusBuilderService::convertToCommonsPlus → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3