Here is my stubbing code. The exchange method is called with the proper parameters (shown below the stubbing code) but for some reason, the when().then() statement is looking for null parameters. Why is the PotentialStubbingProblem exception being thrown here?
@BeforeEach
public <T> void configureMocks() {
when(apiAccess.getKey()).thenReturn("abcdefghijklmnopqrstuvwxyz");
when(apiAccess.getUrlPrefix()).thenReturn("{region}.api.riotgames.com");
val response = new ResponseEntity<Collection<T>>(HttpStatus.OK);
when(restTemplate.exchange(ArgumentMatchers.anyString(),
ArgumentMatchers.any(HttpMethod.class),
(HttpEntity<?>) isNull(),
eq(new ParameterizedTypeReference<Collection<T>>() {})))
.thenReturn(response);
}
PotentialStubbingProblem output is shown belown:
org.mockito.exceptions.misusing.PotentialStubbingProblem:
Strict stubbing argument mismatch. Please check:
- this invocation of 'exchange' method:
restTemplate.exchange(
https://JP1.api.riotgames.com/lol/champion-mastery/v3/champion-masteries/by-summoner/1234567890?api_key=abcdefghijklmnopqrstuvwxyz,
GET,
null,
ParameterizedTypeReference<java.util.Collection<T>>
);
-> at org.eyeoftheherald.riotapiinterface.service.RiotApiService.getEntityList(RiotApiService.java:176)
- has following stubbing(s) with different arguments:
1. restTemplate.exchange("", null, null, null);
ApiAccess is shown below:
@Configuration
public class RiotApiInterfaceConfiguration {
@Getter
@Setter
@Configuration
@PropertySource("classpath:configuration.properties")
@ConfigurationProperties(prefix = "api-access")
public static class ApiAccess {
private String key;
private String urlPrefix;
}
@Autowired
public RiotApiInterfaceConfiguration() {
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}