InstantiateInterceptor implements Interceptor { public void intercept(InterceptorStack invocation, ResourceMethod method, Object instance) throws InterceptionException { if (instance == null) { Class<?> type = method.getResource().getType(); instance = container.instanceFor(type); } invocation.next(method, instance); } InstantiateInterceptor(Container container); void intercept(InterceptorStack invocation, ResourceMethod method,
			Object instance); boolean accepts(ResourceMethod method);  }
@Test public void shouldUseContainerForNewComponent() throws InterceptionException, IOException { final DogController myDog = new DogController(); InstanceContainer container = new InstanceContainer(myDog); InstantiateInterceptor interceptor = new InstantiateInterceptor(container); when(method.getResource()).thenReturn(new DefaultResourceClass(DogController.class)); interceptor.intercept(stack, method, null); assertTrue(container.isEmpty()); verify(stack).next(method, myDog); }
@Test public void shouldNotInstantiateIfThereIsAlreadyAResource() throws InterceptionException, IOException { final DogController myDog = new DogController(); InstantiateInterceptor interceptor = new InstantiateInterceptor(null); interceptor.intercept(stack, method, myDog); verify(stack).next(method, myDog); }