RestComponentResolver { @SuppressWarnings({"unchecked"}) public void addSingleton(Object instance) { Class clazz = instance.getClass(); if (clazz.getAnnotation(Provider.class) != null) { if (instance instanceof ContextResolver) { providers.addContextResolver((ContextResolver)instance); } if (instance instanceof ExceptionMapper) { providers.addExceptionMapper((ExceptionMapper)instance); } if (instance instanceof MessageBodyReader) { providers.addMessageBodyReader((MessageBodyReader)instance); } if (instance instanceof MessageBodyWriter) { providers.addMessageBodyWriter((MessageBodyWriter)instance); } } else if (clazz.getAnnotation(Filter.class) != null) { if (instance instanceof MethodInvokerFilter) { providers.addMethodInvokerFilter((MethodInvokerFilter)instance); } if (instance instanceof RequestFilter) { providers.addRequestFilter((RequestFilter)instance); } if (instance instanceof ResponseFilter) { providers.addResponseFilter((ResponseFilter)instance); } } else if (clazz.getAnnotation(Path.class) != null) { resources.addResource(instance, null); } } RestComponentResolver(ResourceBinder resources, ProviderBinder providers); @SuppressWarnings({"unchecked"}) void addSingleton(Object instance); @SuppressWarnings({"unchecked"}) void addPerRequest(Class clazz); @SuppressWarnings({"unchecked"}) void addFactory(ObjectFactory factory);  }
@Test public void resolvesSingletonResource() { Resource resource = new Resource(); componentResolver.addSingleton(resource); verify(resources).addResource(resource, null); }
@Test public void resolvesSingletonExceptionMapper() { ExceptionMapper exceptionMapper = new RuntimeExceptionMapper(); componentResolver.addSingleton(exceptionMapper); verify(providers).addExceptionMapper(exceptionMapper); }
@Test public void resolvesSingletonContextResolver() { ContextResolver contextResolver = new ContextResolverText(); componentResolver.addSingleton(contextResolver); verify(providers).addContextResolver(contextResolver); }
@Test public void resolvesSingletonMessageBodyReader() { MessageBodyReader<String> messageBodyReader = new StringEntityProvider(); componentResolver.addSingleton(messageBodyReader); verify(providers).addMessageBodyReader(messageBodyReader); }
@Test public void resolvesSingletonMessageBodyWriter() { MessageBodyWriter<String> messageBodyWriter = new StringEntityProvider(); componentResolver.addSingleton(messageBodyWriter); verify(providers).addMessageBodyWriter(messageBodyWriter); }
@Test public void resolvesSingletonMethodInvokerFilter() { MethodInvokerFilter methodInvokerFilter = new AllMatchesMethodInvokerFilter(); componentResolver.addSingleton(methodInvokerFilter); verify(providers).addMethodInvokerFilter(methodInvokerFilter); }
@Test public void resolvesSingletonRequestFilter() { RequestFilter requestFilter = new AllMatchesRequestFilter(); componentResolver.addSingleton(requestFilter); verify(providers).addRequestFilter(requestFilter); }
@Test public void resolvesSingletonResponseFilter() { ResponseFilter responseFilter = new AllMatchesResponseFilter(); componentResolver.addSingleton(responseFilter); verify(providers).addResponseFilter(responseFilter); }