Questions tagged [springmockito]

Springockito is a small extension to spring that simplifies the creation of mockito mocks in the intergation tests' related context xml files.

Springockito is a small extension to spring that simplifies the creation of mockito mocks in the intergation tests' related context xml files.

100 questions
1
vote
1 answer

How can i test the doFilter method?

I try to test this method: public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { final HttpServletRequest httpRequest = (HttpServletRequest)…
Tizi Toure
  • 41
  • 3
1
vote
1 answer

Spring mvc test + mockito. @ModelAttribute NullPointer

I am trying to Unit test a simple Spring-MVC-Controller but even the simplest Unit Test fails because a @ModelAttribute throws a NullpointerException. My Question is: How to mock/set the ModelAttribute? I've tried mocking the findAll() method from…
user1651804
  • 45
  • 2
  • 8
1
vote
2 answers

Mockito Mock a method call called twice

I am trying to use mockito to mock a method. However the class I am injecting mocks with calls the method twice while sending in two different objects of the same type, but depending the values in the object determine the output of the method. So,…
thrilingheroics
  • 13
  • 1
  • 1
  • 3
1
vote
1 answer

Mocking rest client class using mockito throw null pointer exception

Hi i have class RestClientUtil which perform all the connection related operation with server and get the response using rest Services. When i tried to mock my restClientUtil its mocked successfully but when i tried calling method of this…
henrycharles
  • 899
  • 6
  • 23
  • 55
1
vote
1 answer

java.lang.NullPointerException when i run my unit test - mockito

i have a spring mvc application and using mockito for my unit test.I keep getting null pointer exception when i run my unit test. :( Please find below the method that my unit test will be based on: @Controller public class LogInController { …
1
vote
1 answer

how to mock a return value from another class within a method java (mockito)

I am new to mockito and i want to make a unit test for user validation. Please find below the method i want to perform the unit test: @RequestMapping(method = RequestMethod.POST, value = "/login") public ModelAndView…
user1999453
  • 769
  • 1
  • 18
  • 46
0
votes
0 answers

Stackoverflowerror on Tests when migrating to SpringBoot 2.4.4

Symptom After migrating to SpringBoot 2.4.4, we are facing a StackOverflowError when running our Junit tests: 2021-04-28 08:49:50.608 DEBUG 27312 --- [pool-2-thread-1] o.s.j.d.DataSourceTransactionManager : Initiating transaction…
r4phG
  • 440
  • 8
  • 16
0
votes
0 answers

Spring boot - Mockito being ignored in @Async function

I am writing tests for some async methods where I want to mock that an exception is thrown. These methods were synchronous and the tests we working fine until now that I made them async and for some reasy the mocked exception isn't being thrown. My…
Wrong
  • 796
  • 9
  • 26
0
votes
0 answers

How to mock res template multiple times for different urls in a signe test case

String urlFetchCustomers="http://localhost:8080/fetch/customers"; String urlFetchPlaces="http://localhost:8080/fetch/places"; JsonNode customerJSON = mapper.readTree("{"result":["User1","User2","User3"],"message":"Fetched customers…
0
votes
0 answers

MockMvc WebMvcTests Spring Hateoas Returning Multiple NestedLinks

I have a DTO that extends RepresentationalModel from Spring Hateoas. I also have a class that implements an interface from Spring Hateoas called SimpleRepresentationalModel, all it does is easily add links to your DTO's. Now I also made my own…
0
votes
1 answer

How to use any() in jupiter Spring Boot?

I am trying to test a controller method for retrieving a book. For some reason the uploadBook() that I want to mock with when() method below doesn't return an object. @Test void uploadNewBookTest() { MockMultipartFile firstFile = new…
Octtavius
  • 511
  • 7
  • 25
0
votes
0 answers

Mockito calling the wrong stub

I am getting some pretty bizarre behavior right now with mockito. I have essentially (super short hand), the following code enum brokerages { brokerage1 } System system=new System(...); Order order = new Order(...); Mockito brokerage=…
0
votes
1 answer

SpringBoot testing with spring-retry

I had the following function (the function is not really important): fun myRandomFunc(something: String?): List { return listOf(5) } And you can imagine it was doing some API calls, returning list of some objects, etc. I could…
vukojevicf
  • 168
  • 7
0
votes
1 answer

Spring boot - Can't mock MongoTemplate

I have a method in a service that I want to test and which uses MongoTemplate as follows: @Service public class MongoUpdateUtilityImpl implements MongoUpdateUtility { private final MongoTemplate mongoTemplate; @Autowired …
Wrong
  • 796
  • 9
  • 26
0
votes
1 answer

Which is the right location for Mockito when(...).thenReturn(...) in JUnit5? The Test itself or @BeforeClass/@BeforeEach blocks?

Can anybody explain me if there is a difference between: @SpringBootTest public class MyServiceMockTest { @Mock private MyRepository myRepository; @InjectMocks private MyService myService = new MyServiceImpl(); @BeforeEach …
Reader
  • 21
  • 4