@Test(expected = InvalidTypeException.class) public void ifNoAbleInstantiatorIsFoundWillThrowAnException() { final MultiInstantiator mutliInstantiator = new MultiInstantiator(theMockInstantiator); context.checking( new Expectations() { { allowing(mockSubInstantiator).isAbleToInstantiate(with(any(Target.class))); will(returnValue(false)); } }); mutliInstantiator.instantiate(Target.create(Object.class, ""), null); }
@Test public void multiInstantiatorWillUseAnAbleInstantiator() throws Exception { final MultiInstantiator multiInstantiator = new MultiInstantiator(theMockInstantiator); context.checking( new Expectations() { { allowing(mockSubInstantiator).isAbleToInstantiate(with(any(Target.class))); will(returnValue(true)); one(mockSubInstantiator) .instantiate(with(any(Target.class)), (with(any(Parameters.class)))); } }); multiInstantiator.instantiate(Target.create(Object.class, ""), null); }