UCSBSubjectsService.java

1
package edu.ucsb.cs156.courses.services;
2
3
import java.util.List;
4
5
import org.springframework.stereotype.Service;
6
7
import org.springframework.beans.factory.annotation.Value;
8
import org.springframework.boot.web.client.RestTemplateBuilder;
9
import org.springframework.http.HttpEntity;
10
import org.springframework.http.HttpHeaders;
11
import org.springframework.http.HttpMethod;
12
import org.springframework.http.MediaType;
13
import org.springframework.http.ResponseEntity;
14
import org.springframework.web.client.RestTemplate;
15
16
import edu.ucsb.cs156.courses.entities.UCSBSubject;
17
import lombok.extern.slf4j.Slf4j;
18
19
import org.springframework.beans.factory.annotation.Autowired;
20
import com.fasterxml.jackson.databind.ObjectMapper;
21
import com.fasterxml.jackson.core.JsonProcessingException;
22
import com.fasterxml.jackson.core.type.TypeReference;
23
24
@Slf4j
25
@Service("UCSBSubjects")
26
public class UCSBSubjectsService {
27
28
    @Autowired
29
    private ObjectMapper mapper;
30
31
    @Value("${app.ucsb.api.consumer_key}")
32
    private String apiKey;
33
34
    public static final String ENDPOINT = "https://api.ucsb.edu/students/lookups/v1/subjects?includeInactive=false";
35
36
    private final RestTemplate restTemplate;
37
38
    public UCSBSubjectsService(RestTemplateBuilder restTemplateBuilder) {
39
        restTemplate = restTemplateBuilder.build();
40
    }
41
    public List<UCSBSubject> get() throws JsonProcessingException {
42
43
        HttpHeaders headers = new HttpHeaders();
44 1 1. get : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED
        headers.setAccept(List.of(MediaType.APPLICATION_JSON));
45 1 1. get : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED
        headers.setContentType(MediaType.APPLICATION_JSON);
46 1 1. get : removed call to org/springframework/http/HttpHeaders::set → KILLED
        headers.set("ucsb-api-key", this.apiKey);
47
        
48
        HttpEntity<String> entity = new HttpEntity<>(headers);
49
        ResponseEntity<String> re = restTemplate.exchange(ENDPOINT, HttpMethod.GET, entity, String.class);
50
        
51
        String retBody = re.getBody();
52
        List<UCSBSubject> subjects = mapper.readValue(retBody, new TypeReference<List<UCSBSubject>>() {});
53
        
54 1 1. get : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/services/UCSBSubjectsService::get → KILLED
        return subjects;
55
    }
56
57
}

Mutations

44

1.1
Location : get
Killed by : edu.ucsb.cs156.courses.services.UCSBSubjectsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.UCSBSubjectsServiceTests]/[method:get_returns_a_list_of_subjects()]
removed call to org/springframework/http/HttpHeaders::setAccept → KILLED

45

1.1
Location : get
Killed by : edu.ucsb.cs156.courses.services.UCSBSubjectsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.UCSBSubjectsServiceTests]/[method:get_returns_a_list_of_subjects()]
removed call to org/springframework/http/HttpHeaders::setContentType → KILLED

46

1.1
Location : get
Killed by : edu.ucsb.cs156.courses.services.UCSBSubjectsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.UCSBSubjectsServiceTests]/[method:get_returns_a_list_of_subjects()]
removed call to org/springframework/http/HttpHeaders::set → KILLED

54

1.1
Location : get
Killed by : edu.ucsb.cs156.courses.services.UCSBSubjectsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.UCSBSubjectsServiceTests]/[method:get_returns_a_list_of_subjects()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/services/UCSBSubjectsService::get → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3