0

我试过这个:

<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,这意味着地图没有被填充。你能指导我吗?

   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。这里返回的值总是 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();

}
4

0 回答 0