All Questions
58
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 ...
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(...
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 ...
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
...
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 ...
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 ...
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 ...
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(...
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(...
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 {
...
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 ...
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("/...
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 ...
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
@...
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}")
...