Skip to content

Instantly share code, notes, and snippets.

@regis-leray
Created February 17, 2015 15:36
Show Gist options
  • Save regis-leray/51682de444ff4027825d to your computer and use it in GitHub Desktop.
Save regis-leray/51682de444ff4027825d to your computer and use it in GitHub Desktop.
Mock Bean Factory
import org.mockito.internal.util.MockUtil;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
/**
* Do not process wiring for mock which contains @Autowired / @inject annotations
*/
public class MockBeanFactory extends InstantiationAwareBeanPostProcessorAdapter {
private static final MockUtil mockUtil = new MockUtil();
public MockBeanFactory() {
super();
}
@Override
public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
return !mockUtil.isMock(bean);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment