I have a controller with multiple dependency which are solved by using spring configuration and Autowired in the controller class.
For Example:
@Controller
public class MyController{
@Autowired
private Type1 myDependency1;
@Autowired
private Type2 myDependency2;
}
I want to test this controller so that "mydependency1" is mocked and everything else is autowired.
How can I do this?
I was previously following following test:
@Mock
private Type1 myDependency1;
@InjectMocks
private Mycontroller controller = new MyController();
private MockMvc mockMvc;
@Before
public void setUp(){
mockMvc = standaloneSetup(controller).build();
}
But this is only returning the controller with mock of myDependency1 and not injecting myDependency2.