{
RuntimeException failure = new RuntimeException("Just cranky.");
Log log = newLog();
Method method = getClass().getMethod("buildMyService");
ObjectCreator delegate = newObjectCreator();
Object service = new Object();
ServiceDef def = new ServiceDefImpl("foo.Bar", "singleton", method, false, null);
expect(delegate.createObject()).andThrow(failure);
log.error("Construction of service foo.Bar failed: Just cranky.", failure);
replay();
ObjectCreator oneShot = new OneShotServiceCreator(def, delegate, log);
try
{
oneShot.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, oneShot.createObject());
verify();
}