AnyMapAdapter { public <I> void registerMapper(Class<? extends I> inputClass, Mapper<I, ?> mapper) { if (mappers.containsKey(inputClass)) { throw new IllegalStateException( "Mapper for class " + inputClass + " was already registered: " + mappers.get(inputClass) ); } mappers.put(inputClass, mapper); } AnyMapAdapter(); static O adapt(I object); static List<O> adaptList(Class<? extends I> type, List<I> list); void registerMapper(Class<? extends I> inputClass, Mapper<I, ?> mapper); O map(I object); List<O> mapList(Class<? extends I> type, List<I> input);  }
@Test(expected = IllegalStateException.class) public void testThrowIfMapperRegisteredTwice() throws Exception { AnyMapAdapter adapter = new AnyMapAdapter(); Mapper<Input, ?> mapper = mock(Mapper.class); adapter.registerMapper(Input.class, mapper); adapter.registerMapper(Input.class, mapper); }