当单元测试maven中的JDO GAE / J应用程序时,HashSet变成TreeSet

时间:2013-05-02 13:26:41

标签: google-app-engine maven junit jdo

我有一个GAE的Java应用程序,它使用maven(net.kindleit版本)和以下类:

public class C1 {

    ...
    @Persistent(mappedBy = "c1")
    @Element(dependent = "true")
    private Set<C2> c2s = new HashSet<C2>();

    public Set<C2> getC2s() {
        return this.c2s;
    }
    '''
}

public class C2 {

    private C1 c1;

    ...
    more properties, getters and setters
    ...

}

在我的一项测试中,我正在执行以下操作:

C2 myC2 = new C2(myC1);
myC1.getC2s().add(myC2);

单元测试在Eclipse中运行,代码也可以在生产应用程序中运行,但是当我在maven下运行单元测试时,测试失败并显示以下内容:

java.lang.ClassCastException: 
    com.me.model.C2 cannot be cast to java.lang.Comparable
    at java.util.TreeMap.compare(TreeMap.java:1188)
    at java.util.TreeMap.put(TreeMap.java:531)
    at java.util.TreeSet.add(TreeSet.java:255)
    at com.me.service.C2ServiceImpl.createC2(C2ServiceImpl.java:319)

我理解异常,因为C2没有实现可比性,并且需要将内容插入到TreeSet中,但问题是,为什么它返回由TreeSet支持的Set,而不是HashSet。

0 个答案:

没有答案