ClassAliasTypeResolverBuilder extends DefaultTypeResolverBuilder { public void setClassToId(final Map<Class<?>, String> classToId) { Map<String, Class<?>> reverseMap = new HashMap<String, Class<?>>(); for (Map.Entry<Class<?>, String> entry : classToId.entrySet()) { Assert.notNull(entry.getKey(), "Class cannot be null: " + entry); Assert.hasText(entry.getValue(), "Alias (id) cannot be null or contain only whitespaces" + entry); if (reverseMap.put(entry.getValue(), entry.getKey()) != null) { throw new IllegalArgumentException("Two or more classes with the same alias (id): " + entry.getValue()); } } this.classToId = classToId; this.idToClass = reverseMap; } ClassAliasTypeResolverBuilder(final DefaultTyping typing); void setClassToId(final Map<Class<?>, String> classToId);  }
@Test public void setClassToIdMap() { Map<Class<?>, String> map = new HashMap<Class<?>, String>(); map.put(ClassAliasIdResolverTest.class, "cairt"); builder.setClassToId(map); }
@Test(expected = IllegalArgumentException.class) public void invalidSetClassToIdMapNotUniqueAlias() { Map<Class<?>, String> map = new HashMap<Class<?>, String>(); map.put(ClassAliasIdResolverTest.class, "cairt"); map.put(Object.class, "cairt"); builder.setClassToId(map); }
@Test(expected = IllegalArgumentException.class) public void invalidSetClassToIdMapNullAlias() { Map<Class<?>, String> map = new HashMap<Class<?>, String>(); map.put(ClassAliasIdResolverTest.class, "cairt"); map.put(Object.class, null); builder.setClassToId(map); }
@Test(expected = IllegalArgumentException.class) public void invalidSetClassToIdMapEmptyAlias() { Map<Class<?>, String> map = new HashMap<Class<?>, String>(); map.put(ClassAliasIdResolverTest.class, "cairt"); map.put(Object.class, ""); builder.setClassToId(map); }