0

I am trying to create a Mock instance for spring Component class. Below is the spring component class.

@Component
public class MyComponentMapperClass {

@Value("${some.property}")
private String var;

public void someMapperMethod() { // }

This is my test class setup where I am trying to mock the above component class.

@RunWith(PowerMockRunner.class)
@PrepareForTest({MyDAOImpl.class})
public class MyDAOImplTest {

@Mock MyComponentMapperClass myComponentMapperClass;

}

While debugging, I see that Intellij highlights a mock object as "Mock Object of XYZClass", but for the mock I created above it doesn't happen like that. In addition I have tried:

MyComponentMapperClass myComponentMapperClass =  Mockito.mock(MyComponentMapperClass.class)

but still mock object is not created. This seems to be very straight-forward, but I haven't figured it out yet.

here is an answer from https://stackoverflow.com/users/2847174/ren%c3%a9-scheibe Mock Spring Component, which suggests to do the same, but is not working for me. Any help is appreciated. Thanks!

Abhinash Jha
  • 165
  • 1
  • 3
  • 17

0 Answers0