I am trying to mock rest template exchange method.
String responseBody = "responseBody";
String url = "http://example.com";
HttpMethod method = HttpMethod.GET;
HttpEntity<String> requestEntity = null;
Class<String> responseType = String.class;
Object[] uriVariables = {};
Map<String, String> headers = Collections.singletonMap("key", "value");
when(restTemplate.exchange(url, HttpMethod.GET, requestEntity, responseType,uriVariables))
.thenReturn(new ResponseEntity<>(responseBody, HttpStatus.OK));
but getting this error,
Description Resource Path Location Type
The method exchange(String, HttpMethod, HttpEntity<?>, Class<T>, Object...) in the type RestTemplate
is not applicable for the arguments (String, HttpMethod, HttpEntity<String>, Class<String>, Object[]) line 45 Java Problem
i am not able to understand which argument is causing this error. can anyone please help
CodePudding user response:
As discussed in comments, the most likely cause is wrong import.
The error message makes it difficult to find by not printing fully qualified class names.