@Test public void discoversMapValueType() { TypeInformation<StringMapContainer> information = ClassTypeInformation.from(StringMapContainer.class); TypeInformation<?> genericMap = information.getProperty("genericMap"); assertEquals(Map.class, genericMap.getType()); assertEquals(String.class, genericMap.getMapValueType().getType()); TypeInformation<?> map = information.getProperty("map"); assertEquals(Map.class, map.getType()); assertEquals(Calendar.class, map.getMapValueType().getType()); }
@Test public void discoversTypeForSimpleGenericField() { TypeInformation<ConcreteType> discoverer = ClassTypeInformation.from(ConcreteType.class); assertEquals(ConcreteType.class, discoverer.getType()); TypeInformation<?> content = discoverer.getProperty("content"); assertEquals(String.class, content.getType()); assertNull(content.getComponentType()); assertNull(content.getMapValueType()); }
@Test public void discoversArraysAndCollections() { TypeInformation<StringCollectionContainer> information = ClassTypeInformation.from(StringCollectionContainer.class); TypeInformation<?> property = information.getProperty("array"); assertEquals(property.getComponentType().getType(), String.class); Class<?> type = property.getType(); assertEquals(String[].class, type); assertThat(type.isArray(), is(true)); property = information.getProperty("foo"); assertEquals(Collection[].class, property.getType()); assertEquals(Collection.class, property.getComponentType().getType()); assertEquals(String.class, property.getComponentType().getComponentType().getType()); property = information.getProperty("rawSet"); assertEquals(Set.class, property.getType()); assertEquals(Object.class, property.getComponentType().getType()); assertNull(property.getMapValueType()); }