Registry { public void register(Class<?> serviceClass, Object serviceImpl) { synchronized (services) { services.put(serviceClass, serviceImpl); } } 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 register() { Registry registry = Registry.instance(); registry.register(String.class, "Hello"); Assert.assertEquals(registry.unregister(String.class), "Hello"); Assert.assertFalse(registry.isMapperRegistered(ContentTypeEx.SMILE)); Assert.assertTrue(registry.isMapperRegistered(ContentType.APPLICATION_JSON)); ObjectMapper mapper = new ObjectMapper(); registry.registerMapper("any/one", mapper); Assert.assertEquals(registry.unregisterMapper("any/one"), mapper); registry.registerMapper(ContentType.APPLICATION_SVG_XML, mapper); Assert.assertEquals(registry.unregisterMapper(ContentType.APPLICATION_SVG_XML), mapper); Registry.reset(); }