public void reporting_of_construction_failure() throws Exception
{
RuntimeException failure = new RuntimeException("Just cranky.");
Log log = mockLog();
ObjectCreatorSource source = mockObjectCreatorSource();
ObjectCreator delegate = mockObjectCreator();
Object service = new Object();
ServiceDef def = new ServiceDefImpl(Runnable.class, "Bar", "singleton", false, source);
expect(delegate.createObject()).andThrow(failure);
log.error("Construction of service Bar failed: Just cranky.", failure);
replay();
ObjectCreator wrapper = new RecursiveServiceCreationCheckWrapper(def, delegate, log);
try
{
wrapper.createObject();
unreachable();
}
catch (RuntimeException ex)
{
assertSame(ex, failure);
}
verify();
// Now test that the locked flag is not set and that the object may still be created.
train_createObject(delegate, service);
replay();
assertSame(service, wrapper.createObject());
verify();
}