Skip to main content

All Questions

0 votes
1 answer
833 views

Getting org.mockito.exceptions.misusing.PotentialStubbingProblem: Strict stubbing argument mismatch while using restTemplate

I call external API by using RestTemplate's exchange() in my application. And currently, I am writing junit and mockito test case for restTemplate call but I am getting stubbing argument mismatch ...
Rahul's user avatar
  • 131
1 vote
2 answers
2k views

Spring Boot Microservices - RestTemplate Null Pointer Exception in JUnit Test

I have a problem running Junit Service in my spring-boot microservice. I defined bearer token getting from /authenticate/login. It is valid. I can send a request to any service through Postman. I ...
S.N's user avatar
  • 1
0 votes
1 answer
1k views

Mocking RestTemplate exchange returns null

I have looked at multiple posts here - one for example and tried multiple variations but still can't seem to be able to get a non-null value after mocking RestTemplate#exchange(String url, HttpMethod ...
linuxNoob's user avatar
  • 690
2 votes
1 answer
5k views

RestTemplate Junit: Cannot invoke "org.springframework.http.ResponseEntity.getBody()" because "response" is null

I have a spring boot application that makes an API hit of other internal projects using the rest template which works fine and I am writing unit test cases for it but test case if failing due to ...
anonymous's user avatar
  • 223
0 votes
1 answer
424 views

Create mock server to test on result of RestTemplate

I am not sure if it is possible to write a Test case that can mock the "http://localhost:8888/setup" site, so the above code can hit it and I want to check if the "http://localhost:...
xxestter's user avatar
  • 487
0 votes
1 answer
408 views

mocking resttemplate exchange method returning null

I am trying to write the Junit test case for exchange method but it its returning null, can anybody tell me what is mistake I am doing here My Actual Code is HttpEntity httpEntity = ...
java_tech's user avatar
0 votes
1 answer
331 views

Using @InjectMock giving URI not absolute error

I have written following Junit for the method which is using rest template to call another service but the mocking is throwing URI not absolute error. Method: @Value("${app.prop.esso-url}") ...
Pooja Katkade's user avatar
0 votes
1 answer
721 views

unit testing of controller class which has rest template

I have tried test on controller class, It is not mock the rest template which is in controller class. @RestController public class LoginController { @RequestMapping(value = "api/v1/login&...
Chandan Reddy's user avatar
0 votes
1 answer
1k views

How to properly mock my RestTemplate unit test?

My current unit test using RestTemplate to reach a GET endpoint has a lot of hard-coded values. I would like to know if there's a better approach mocking the values and how to do it. Currently it ...
jimmy's user avatar
  • 515
0 votes
1 answer
559 views

How to write Junit for if else condition under thrown exceptions from rest template

I am new in Junit. I read basics of Mockito. I am not able to figure out how to write Junit for test code coverage. I am using rest template calls to receive response object for requests sent. I am ...
Ag863's user avatar
  • 47
0 votes
1 answer
3k views

java.lang.IllegalArgumentException: HttpMethod is required when mocking restTemplate.exhange in JUnit (post call)

Mockito.when(restTemplate.exchange( anyString(), Mockito.eq(HttpMethod.POST), Mockito.any(), Mockito.eq(String.class) ))....
Aishu.dars's user avatar
0 votes
1 answer
966 views

401 unauthorized spring boot test

I wrote a test and I expect to get 401, but I get an exception. when I run a test on debugging mode, I saw 401 status is handled in HttpUrlConnection.class (please find it below) and I get an ...
Ehsan's user avatar
  • 43
0 votes
1 answer
344 views

JUnit test Mocking test case for Springboot App

Working on a Springboot app, which has a method to make a call to external rest API and get some response. This response is a number between 1 and 100. I am using a simple if else loop to check if ...
John Seen's user avatar
  • 721
8 votes
1 answer
16k views

How to wire up Micrometer with @WebMvcTest

Im trying to test a Spring Boot 2.3 @Controller that does metrics via Actuator/Prometheus with @WebMvcTest. Unfortunately this fails with a NPE, probably because the Micrometer/Prometheus classes are ...
Martin Schröder's user avatar
0 votes
1 answer
785 views

is there a way to test all 5XX or 4XX codes with Mockito?

Hi everyone I'm working in a microservice which has dependency in another ones. I'm handling the rest consumption with Restemplate and everything its okay with that but I also need get a 100% on ...
Juanbg.dev's user avatar

15 30 50 per page