我试过这个:
<util:list id="list1">
<value>foo@bar.com</value>
<value>foo1@bar.com</value>
</util:list>
<util:list id="list2">
<value>foo2@bar.com</value>
<value>foo3@bar.com</value>
</util:list>
<util:map id="emailMap" value-type="java.util.List">
<!-- Map between String key and List -->
<entry key="entry1" value-ref="list1" />
<entry key="entry2" value-ref="list2" />
...
</util:map>
像这样调用这个地图
<bean id="myBean" class="com.sample.beans">
<property name="mapArray" ref="emailMap" />
</bean>
我已经编写了一个测试用例,看看是否填充了这个,但是在调用它的地方我添加了Map.isEmpty()
并且它总是返回true,这意味着map不会被填充。你能指导我吗?
public class beans()
{
Map<String, List<String>> mapArray= new HashMap<String,ArrayList<String>>();
public void setMapArray(Map<String, List<String>> map)
{
this.mapArray= map;
}
public Array<String, List<String>> getMapArray()
{
return mapArray;
}
public void makeObject(String key)
throws Exception {
System.out.println(mapArray.isEmpty());
}
}
测试用例调用函数makeobject。此处返回的值始终为true TEST:
public class testing{
@Test(enabled=true)
public void call1() throws {
ApplicationContext context = new ClassPathXmlApplicationContext("call.the.xml");
BeanFactory factory = context;
KeyedPoolFactory test = (KeyedPoolFactory) factor.getBean("myBean");
// CALLED MakeObject here. So the make object is being called for sure since it returning true for isEmpty();
}