Skip to main content

All Questions

0 votes
2 answers
40 views

Mockito service dependency null pointer exception

So, let me show my problem. I have Service class: @Service @Transactional public class UserServiceImpl implements UserService { private final UserRepository userRepository; private final ...
IvanDx's user avatar
  • 17
0 votes
0 answers
54 views

Why this mocked StringBuilder always return the string "stringBuilder" ? Posibly confiusion with Junit mocks

Hello and sorry for my english. Im new in Junit and im trying to learning mocks and how it works, well, I have this test class with the next mocks: @DataJpaTest @AutoConfigureTestDatabase(...
Alejandro Seco Pineda's user avatar
0 votes
2 answers
271 views

Mocking using @Mock annotation is not working for my junit test case

I have been Unit testing a class where when I use @Autowired the testing class one of the test methods passes and the other test methods fails, when I use @Inject mocks instead of @Autowired the ...
Faiz's user avatar
  • 3
2 votes
0 answers
354 views

Creating mock API using MockWebServer and calling by WebTestClient using spring boot 3 giving 404 error

I am working on a project to upgrade it to springboot 3.Now i am facing 404 NOT_FOUND error in junit test while mocking API using MockWebServer and WebTestClient.I am using 4.10.0 version of okhttp ...
sekhar's user avatar
  • 147
0 votes
1 answer
517 views

Page Not Found -- No mapping for /GET

I am trying to write test for my controller for my SPRING-BOOT CRUD operation project using junit5 and mocking. While running the test it is showing below error. Not able to understand what is the ...
harsh agarwal's user avatar
0 votes
1 answer
970 views

How to test model class using junit to cover field validations?

I am writing unit test cases using junit and mockito for my spring boot application. Now, I also want to write test cases for request model class to achieve minimum 90% code coverage as per business ...
Rahul's user avatar
  • 131
1 vote
1 answer
388 views

Why I geeting java.lang.NullPointerException when a MockBean is executed?

I have the following service class (Spring Boot): @Service public class MyService { @Autowired private DependedService dependedService; @Transactional public ...
user2304483's user avatar
  • 1,554
0 votes
0 answers
525 views

Mockito Mocks don't reset after a Test or with `clearInvocations(...)` (JUnit, Spring Boot)

I'm trying to Test a Method where I call a method from three different other Classes (adapterX, adapterY, adapterZ). I want to verify that only one of these Methods is getting executed with the verify(...
stuchlyf's user avatar
  • 197
1 vote
1 answer
4k views

NullPointerException MockMvc with ExtendWith (test Junit Springboot)

I have a problem doing tests Mocking with Junit. It turns out that if I put the @SpringBootTest annotation it works perfectly, on the other hand if I remove it and leave it only with @ExtendWith(...
SeNTiHaDeS's user avatar
1 vote
2 answers
67 views

Spring Boot RestController Testclass doesn't instantiate Mocked Variables

I'm trying to create a Unit Test for a RestController in Spring Boot. The Controller looks something like this: @RestController() @RequestMapping("/endpoint") public class MyRestController { ...
tung's user avatar
  • 749
1 vote
1 answer
1k views

How to mock spring security cookies session in spring boot unit Test?

I have added Http cookie Authentication using authentication manager to my Spring Boot REST API I have a controller that exposes a rest service allowing authentication to /api/auth/signin resource via ...
Hamza Khadhri's user avatar
0 votes
0 answers
541 views

Why I am getting 403 forbidden error with mockmvc?

I am trying to mock itemService.deleteItem() method but getting a 403 status code, (I am using spring security, and for that, I have used @WithMockUser annotation) Controller: ` @DeleteMapping("/...
Tushar Kawade's user avatar
1 vote
1 answer
1k views

spring Junit with Mock return value null

I'm new in JUnit with Mock. This is actual working but I notice receiving null value in TEST using Map<String, Object> The reason for this what if their is condition must not null. Someday I'm ...
SpicySandwich's user avatar
1 vote
4 answers
345 views

how to inject two mockito object in single Implentaion class

Right now only one mocking working fine. another one returning null pointer exception. Both @Autowired and @Mock giving nullpointer for BCryptPasswordEncoder passwordEncoder; My Test class @...
Prabagaran Sellamuthu'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

15 30 50 per page