OutjectResult implements Interceptor { public void intercept(InterceptorStack stack, ResourceMethod method, Object resourceInstance) throws InterceptionException { Type returnType = method.getMethod().getGenericReturnType(); String name = extractor.nameFor(returnType); Object value = this.info.getResult(); logger.debug("outjecting {}={}", name, value); result.include(name, value); stack.next(method, resourceInstance); } OutjectResult(Result result, MethodInfo info, TypeNameExtractor extractor); boolean accepts(ResourceMethod method); void intercept(InterceptorStack stack, ResourceMethod method, Object resourceInstance);  }
@Test public void shouldOutjectWithASimpleTypeName() throws NoSuchMethodException { when(method.getMethod()).thenReturn(MyComponent.class.getMethod("returnsAString")); when(info.getResult()).thenReturn("myString"); when(extractor.nameFor(String.class)).thenReturn("string"); interceptor.intercept(stack, method, instance); verify(result).include("string", "myString"); verify(stack).next(method, instance); }
@Test public void shouldOutjectACollectionAsAList() throws NoSuchMethodException { Method myComponentMethod = MyComponent.class.getMethod("returnsStrings"); when(method.getMethod()).thenReturn(myComponentMethod); when(info.getResult()).thenReturn("myString"); when(extractor.nameFor(myComponentMethod.getGenericReturnType())).thenReturn("stringList"); interceptor.intercept(stack, method, instance); verify(result).include("stringList", "myString"); verify(stack).next(method, instance); }