Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save regis-leray/05f7be67c88371aaaab1 to your computer and use it in GitHub Desktop.
Save regis-leray/05f7be67c88371aaaab1 to your computer and use it in GitHub Desktop.
Spring - Skip Nested dependency mock
public class MockPostProcessorAdapter extends InstantiationAwareBeanPostProcessorAdapter {
private static final MockUtil mockUtil = new MockUtil();
public MockPostProcessorAdapter() {
super();
}
@Override
public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
return !mockUtil.isMock(bean);
}
}
@regis-leray
Copy link
Author

I had the same problem and I found another solution.
When Spring instantiate all your beans, it will check if it's a Mockito Mock and in this case, I return false for injection property. To use it, just inject it in a Spring context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment