@Test
public void ensure_only_called_once() throws Exception
{
Method method = getClass().getMethod("buildMyService");
ObjectCreator delegate = newObjectCreator();
Object service = new Object();
ServiceDef def = new ServiceDefImpl("foo.Bar", "singleton", method, false, false);
train_createObject(delegate, service);
replay();
ObjectCreator oneShot = new OneShotServiceCreator(def, delegate);
assertSame(oneShot.createObject(), service);
try
{
oneShot.createObject();
unreachable();
}
catch (IllegalStateException ex)
{
assertEquals(