我完全被这个弄糊涂了。我正在运行一整套完整的单元测试。以下是有关共享代码被使用一些JUnit测试:什么会导致HashMap containsKey()失败并以String为关键字?
private static Map<String, JAXBContext> jaxbContexts =
new HashMap<String, JAXBContext>();
private synchronized JAXBContext getJAXBContext(Class clazz) throws JAXBException {
JAXBContext context = null;
if (jaxbContexts.containsKey(clazz.getName())) {
context = jaxbContexts.get(clazz.getName());
} else {
context = JAXBContext.newInstance(clazz);
System.out.println("Created new context for '" + clazz.getName() + "'");
jaxbContexts.put(clazz.getName(), context);
}
return context;
}
从JUnit的运行输出控制台包括以下两个连续的条目:
Created new context for 'com.somecompany.xmlschema.providepensionpaymentinfo.Interface'
Created new context for 'com.somecompany.xmlschema.providepensionpaymentinfo.Interface'
我缺少什么?为什么jaxbContexts.containsKey()
在这种情况下不能用于基于字符串的键,与JUnit执行期间的其他46次不同?我们并不是在同时运行我们的测试,但是如果这有所作为,我们会使用Aspects。
您确定这两行之间没有停止/启动JVM吗? – Pointy 2011-01-20 14:20:59