mercredi 25 mars 2015

How to mock PropertiesFactoryBean using Powermock? This bean is injected as a property in another bean

Im trying to mock a bean which is actually injected as a property in the class I'm writing Unit tests on. Here is the snippet beans.xml:



<bean id="mcgProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:mcg.properties</value>
</list>
</property>
</bean>

<bean id="summary" class="com....client.SummaryServiceImpl">
<property name="propMap" ref="mcgProperties"/>
</bean>


Im writing Unit tests for SummaryServiceImpl. And Im stuck at



propMap = PowerMockito.mock(Properties.class);
mcgProperties = PowerMockito.mock(PropertiesFactoryBean.class);
**when(mockAppContext.getBean("mcgProperties"), PropertiesFactoryBean.class).thenReturn(mcgProperties);**


I get an error "java.lang.IllegalArgumentException: The object to perform the operation on cannot be null."


Aucun commentaire:

Enregistrer un commentaire