Created
February 17, 2015 15:36
-
-
Save regis-leray/51682de444ff4027825d to your computer and use it in GitHub Desktop.
Mock Bean Factory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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