I'm thoroughly confused by this one. I'm running a full package worth of unit tests. Here's the relevant shared code which gets used by a number of JUnit tests:
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;
}
The console output from the JUnit run includes the following two consecutive entries:
Created new context for 'com.somecompany.xmlschema.providepensionpaymentinfo.Interface'
Created new context for 'com.somecompany.xmlschema.providepensionpaymentinfo.Interface'
What am I missing? Why did jaxbContexts.containsKey()
not work in this instance for a String based key, unlike 46 other times during the JUnit execution? We aren't running our tests in parallel, but we do use Aspects if that makes a difference.