;
return providers;
}
public void testContextResolvers() {
ProvidersRegistry providers = createProvidersRegistryImpl();
assertTrue(providers.addProvider(new AtomContextResolver()));
assertTrue(providers.addProvider(new StringContextResolver()));
assertTrue(providers.addProvider(new IntegerContextResolver()));
assertTrue(providers.addProvider(new ByteContextResolver()));
assertTrue(providers.addProvider(new ListContextResolver()));
try {
providers.addProvider(new NotAProvider());
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
/*
* String and text/pain, should invoke StringContextResolver
*/
assertEquals(STRING, providers.getContextResolver(String.class,
MediaType.TEXT_PLAIN_TYPE,
null).getContext(null));
/*
* byte[] and text/plain, should invoke ByteContextResolver
*/
assertEquals(BYTE, providers.getContextResolver(byte[].class,
MediaType.TEXT_PLAIN_TYPE,
null).getContext(null));
/*
* There is no context resolver that handlers Integer and /
*/
assertEquals(_12345, providers.getContextResolver(Integer.class,
MediaType.WILDCARD_TYPE,
null).getContext(null));
/*
* StringContextResolver is registered after AtomContextResolver,
* therefore it should be invoked
*/
assertEquals(STRING, providers.getContextResolver(String.class,
MediaType.WILDCARD_TYPE,
null).getContext(null));
/*
* AtomContextResolver returns null, if the parameter is not null,
* therefore StringContextResolver should be invoked
*/
assertEquals(STRING, providers.getContextResolver(String.class,
MediaType.WILDCARD_TYPE,
null).getContext(String.class));
/*
* test ContextResolver with collections
*/
assertEquals(Collections.emptyList(), providers.getContextResolver(List.class,
MediaType.WILDCARD_TYPE,
null).getContext(null));
}