@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 willCreateATargerForEachFormalParameterDeclaredByTheMethod() throws Exception {
    final ControllerMethod buyAHouse = buyA;
    requestParameterIs(buyAHouse, "house", "");

    final InstantiatorWithErrors mockInstantiator = mock(InstantiatorWithErrors.class);
    IogiParametersProvider iogiProvider =
        new IogiParametersProvider(nameProvider, request, mockInstantiator);
    final Target<House> expectedTarget = Target.create(House.class, "house");

    iogiProvider.getParametersFor(buyAHouse, errors);

    verify(mockInstantiator).instantiate(eq(expectedTarget), any(Parameters.class), eq(errors));
  }
  @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);
  }
 private <T> T convertWith(
     final TypeConverter<T> instantiator, final Class<T> type, final String stringValue) {
   final Target<T> target = Target.create(type, "foo");
   assertTrue(instantiator.isAbleToInstantiate(target));
   return instantiator.instantiate(target, new Parameters(new Parameter("foo", stringValue)));
 }