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

Mockito doesn't work with custom validator in Spring

I am using Mockito to test one of my get-mappings in the controller class. Here is my get method @PostMapping(value = "insert/carbooking") public ResponseEntity reservation(@Valid BookingRequest bookRequest) { return…
kungho
  • 71
  • 1
  • 7
1
vote
3 answers

@InjectMocks inject @MockBean by Constructor and setter not working properly

I have try so many time by unsing @RunWith(SpringJUnit4ClassRunner.class) I have tried to create a test case foe a class with getter and Constructor injection. When i user @MockBean for setter injection, @Mock for Constructor injection and also…
Araf
  • 428
  • 8
  • 26
1
vote
1 answer

Spring Boot - Mock Interceptors

I'm having an issue while testing Rest request. However test is being intercepted by one of my interceptors. In short I want to mock interceptors behaviour rather than calling actual implementation. For simplicity purposes to visualise the issue…
Alex
  • 453
  • 1
  • 12
  • 21
1
vote
2 answers

Spring Boot Test with Mockito : @Validated annotation is being ignored during unit tests

I'm using Spring Boot 2.1.1, JUnit 5, Mockito 2.23.4. org.springframework.boot spring-boot-starter-test test
Wolf359
  • 2,019
  • 1
  • 26
  • 48
1
vote
1 answer

Spring boot test: MockedBean conflicts with others

Currently, I've two RestTemplate beans: @Bean @Primary public RestTemplate jwtRestTemplate( RestTemplateBuilder builder, JWTService jwtService) { return builder .additionalInterceptors( …
Jordi
  • 15,016
  • 25
  • 94
  • 208
1
vote
1 answer

Mock Httpservletrequest and requestcontext

I am trying to mock RequestContext and HttpServletRequest classes/interfaces but they not working. code: @Override public Object run() { String accessToken= ""; ctx = RequestContext.getCurrentContext(); HttpServletRequest request =…
user09
  • 631
  • 7
  • 22
1
vote
1 answer

Mockito Test Case for Jdbc template and Spring's keyHolder

I wrote a test case but I get a null pointer exception at the return KeyHolder.getKey() line. My test case looks like this: @InjectMocks private UserDAOImpl userDAO; @Mock private JdbcTemplate jdbcTemplate; @Mock private KeyHolderFactory…
Amit
  • 119
  • 1
  • 12
1
vote
1 answer

spring boot not able to inject spring service in spring test class

I have been struggling to solve this problem but no luck, also I am a bit new to spring boot. This application is a user registration application. I have a service,controller class as below @Service("userService") @Transactional public class…
sachingupta
  • 699
  • 1
  • 8
  • 27
1
vote
1 answer

How to use the mapper created by Mapstruct as @Mock during testing

The context I have a simple test method testFindByUserName. I use mockito library. I have @Mock UserMapper which is created by Mapstruct library. The problem Mocito doesn't handle Static method INSTANCE which I use to mapping user to userDto. I have…
John Wind
  • 29
  • 7
1
vote
2 answers

Impossible to write integration test controller with DAO mock?

I become crazy, I tried all possible combination of various test Runners and possibles annotation for testing, the nearest solution of my need is following : @RunWith(SpringRunner.class) @SpringBootTest(classes =…
1
vote
1 answer

What is sense of @Mock annotation?

I have a question about bean creation in testing of controllers. For example, there is a such test @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {MainApplicationConfiguration.class,…
Alex
  • 2,343
  • 3
  • 16
  • 35
1
vote
1 answer

Junit test case falling with Mockito and Spring MVC

I have a Controller Class which i am trying to test using mockito. @Controller public class LoginController { final static Logger logger = Logger.getLogger(LoginController.class); private StaffService staffService; @Autowired public…
Mr Khan
  • 119
  • 9
1
vote
0 answers

@WebMvcTest content is null

I've already read this Q&A but it didn't solve the problem. I'm using Spring Boot 1.4.2.RELEASE and I'm attempting to speed up my tests. Up to this point, I've used @SpringBootTest and I'm testing switching some of these simpler tests to…
Gregg
  • 31,994
  • 13
  • 93
  • 189
1
vote
1 answer

Mocking spring model classes that have model classes in them as member variables

So, I have a class structure as: class ModelA { ModelB b; // Also a model object // Getters and setters } class B() { ModelC c; // Also a model object ModelD d; // Also a model object } I want to mock all of them…
1
vote
0 answers

NullPointerException in unit test with Mockito

I am working with Spring MVC, using hibernate and JPA configuration, and I'm testing it using Mockito. I'm getting an error but I don't see where I am wrong and why the test failed. @RunWith(MockitoJUnitRunner.class) public class StudentServiceTest…
Too You
  • 81
  • 4