PublicHolidayQueryService.java

1
package edu.ucsb.cs156.spring.backenddemo.services;
2
3
import java.util.List;
4
import java.util.Map;
5
6
import org.springframework.web.client.RestTemplate;
7
8
import lombok.extern.slf4j.Slf4j;
9
10
import org.springframework.boot.web.client.RestTemplateBuilder;
11
12
import org.springframework.stereotype.Service;
13
import org.springframework.web.client.HttpClientErrorException;
14
15
import org.springframework.boot.web.client.RestTemplateBuilder;
16
import org.springframework.http.HttpEntity;
17
import org.springframework.http.HttpHeaders;
18
import org.springframework.http.HttpMethod;
19
import org.springframework.http.MediaType;
20
import org.springframework.http.ResponseEntity;
21
import org.springframework.stereotype.Service;
22
import org.springframework.web.client.HttpClientErrorException;
23
24
@Slf4j
25
@Service
26
public class PublicHolidayQueryService {
27
28
29
    private final RestTemplate restTemplate;
30
31
    public PublicHolidayQueryService(RestTemplateBuilder restTemplateBuilder) {
32
        restTemplate = restTemplateBuilder.build();
33
    }
34
35
    public static final String ENDPOINT = "https://date.nager.at/api/v2/publicholidays/{year}/{countryCode}";
36
37
    public String getJSON(String year, String countryCode) throws HttpClientErrorException {
38
        log.info("year={}, countryCode={}", year, countryCode);
39
        HttpHeaders headers = new HttpHeaders();
40 1 1. getJSON : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED
        headers.setAccept(List.of(MediaType.APPLICATION_JSON));
41 1 1. getJSON : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED
        headers.setContentType(MediaType.APPLICATION_JSON);
42
43
        HttpEntity<String> entity = new HttpEntity<>(headers);
44
45
        Map<String, String> uriVariables = Map.of("year", year, "countryCode", countryCode);
46
        ResponseEntity<String> re = restTemplate.exchange(ENDPOINT, HttpMethod.GET, entity, String.class, uriVariables);
47 1 1. getJSON : replaced return value with "" for edu/ucsb/cs156/spring/backenddemo/services/PublicHolidayQueryService::getJSON → KILLED
        return re.getBody();
48
    }
49
50
   
51
52
}

Mutations

40

1.1
Location : getJSON
Killed by : edu.ucsb.cs156.spring.backenddemo.services.PublicHolidayQueryServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.spring.backenddemo.services.PublicHolidayQueryServiceTests]/[method:test_getJSON()]
removed call to org/springframework/http/HttpHeaders::setAccept → KILLED

41

1.1
Location : getJSON
Killed by : edu.ucsb.cs156.spring.backenddemo.services.PublicHolidayQueryServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.spring.backenddemo.services.PublicHolidayQueryServiceTests]/[method:test_getJSON()]
removed call to org/springframework/http/HttpHeaders::setContentType → KILLED

47

1.1
Location : getJSON
Killed by : edu.ucsb.cs156.spring.backenddemo.services.PublicHolidayQueryServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.spring.backenddemo.services.PublicHolidayQueryServiceTests]/[method:test_getJSON()]
replaced return value with "" for edu/ucsb/cs156/spring/backenddemo/services/PublicHolidayQueryService::getJSON → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3