Registry { public String namespace() { return namespace; } private  Registry(String namespace); static Registry defaultedInstance(String namespace); static Registry instance(); static Registry instance(String namespace); static Collection<Registry> instances(); static boolean isRegitered(Class<?> type); static boolean isRegitered(String namespace, Class<?> type); static T lookup(Class<T> type); @SuppressWarnings("unchecked") static T lookup(String namespace, Class<T> type); static ObjectMapper lookupMapper(ContentType type); static ObjectMapper lookupMapper(String contentType); static ObjectMapper lookupMapper(String namespace, ContentType type); static ObjectMapper lookupMapper(String namespace, String contentType); boolean isMapperRegistered(ContentType type); String namespace(); void register(Class<?> serviceClass, Object serviceImpl); void registerMapper(ContentType type, ObjectMapper mapper); void registerMapper(String mimeType, ObjectMapper mapper); @Override String toString(); @SuppressWarnings("unchecked") T unregister(Class<?> type); ObjectMapper unregisterMapper(ContentType type); ObjectMapper unregisterMapper(String mime); static final String NS_DEFAULT; }
@Test public void namespace() { MyProvider stringProvider = new MyProvider(); Registry reg = Registry.getOrCreate(stringProvider); reg.register(String.class, stringProvider.serviceImpl()); reg.logState(); Assert.assertEquals(reg.namespace(), "myapi"); Assert.assertEquals(Registry.lookup("myapi", String.class).toString(), "Hello"); Registry.reset(); }