ObjectMapperAwareImpl implements ObjectMapperAware { @Override public <T> ObjectMapper<T> get(Class<T> cls) { if (!storage.containsKey(cls)) { throw new IllegalArgumentException(String.format("Object mapper for bean class \"%s\" not found", cls.getCanonicalName())); } @SuppressWarnings("unchecked") ObjectMapper<T> objectMapper = (ObjectMapper<T>) storage.get(cls); return objectMapper; }  @PostConstruct void init(); @Override ObjectMapper<T> get(Class<T> cls);  }
@Test public void testGetExistingObjectMapper() { ObjectMapper<TestObject> testObjectMapper = objectMapperAware.get(TestObject.class); final String VALUE = "test"; final TestObject OBJECT = new TestObject(VALUE); Map<String, Object> mappedValues = testObjectMapper.map(OBJECT); assertThat(mappedValues.keySet(), contains(TestObjectMapper.COLUMN_NAME)); assertThat(mappedValues.get(TestObjectMapper.COLUMN_NAME), equalTo(VALUE)); }
@Test(expected = IllegalArgumentException.class) public void testGetMissingObjectMapper() { objectMapperAware.get(Void.class); }