@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 discoversTypeForNestedGenericField() { TypeInformation<ConcreteWrapper> discoverer = ClassTypeInformation.from(ConcreteWrapper.class); assertEquals(ConcreteWrapper.class, discoverer.getType()); TypeInformation<?> wrapper = discoverer.getProperty("wrapped"); assertEquals(GenericType.class, wrapper.getType()); TypeInformation<?> content = wrapper.getProperty("content"); assertEquals(String.class, content.getType()); assertEquals(String.class, discoverer.getProperty("wrapped").getProperty("content").getType()); assertEquals(String.class, discoverer.getProperty("wrapped.content").getType()); }
@Test public void handlesPropertyFieldMismatchCorrectly() { TypeInformation<PropertyGetter> from = ClassTypeInformation.from(PropertyGetter.class); TypeInformation<?> property = from.getProperty("_name"); assertThat(property, is(notNullValue())); assertThat(property.getType(), is(typeCompatibleWith(String.class))); property = from.getProperty("name"); assertThat(property, is(notNullValue())); assertThat(property.getType(), is(typeCompatibleWith(byte[].class))); }
@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 returnsComponentTypeForMultiDimensionalArrayCorrectly() { TypeInformation<?> information = from(String[][].class); assertThat(information.getType(), is((Object) String[][].class)); assertThat(information.getComponentType().getType(), is((Object) String[].class)); assertThat(information.getActualType().getActualType().getType(), is((Object) String.class)); }
@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()); }