コード例 #1
0
  @Test
  @SuppressWarnings("rawtypes")
  public void discoversBoundTypeForNested() {

    TypeInformation<AnotherGenericType> information =
        ClassTypeInformation.from(AnotherGenericType.class);
    assertEquals(GenericTypeWithBound.class, information.getProperty("nested").getType());
    assertEquals(Person.class, information.getProperty("nested.person").getType());
  }
コード例 #2
0
  @Test
  public void typeInfoDoesNotEqualForGenericTypesWithDifferentParent() {

    TypeInformation<ConcreteWrapper> first = ClassTypeInformation.from(ConcreteWrapper.class);
    TypeInformation<AnotherConcreteWrapper> second =
        ClassTypeInformation.from(AnotherConcreteWrapper.class);

    assertFalse(first.getProperty("wrapped").equals(second.getProperty("wrapped")));
  }
コード例 #3
0
  @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());
  }
コード例 #4
0
  @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)));
  }
コード例 #5
0
  @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());
  }
コード例 #6
0
  @Test
  public void discoversBoundTypeForSpecialization() {

    TypeInformation<SpecialGenericTypeWithBound> information =
        ClassTypeInformation.from(SpecialGenericTypeWithBound.class);
    assertEquals(SpecialPerson.class, information.getProperty("person").getType());
  }
コード例 #7
0
  @Test
  @SuppressWarnings("rawtypes")
  public void discoversBoundType() {

    TypeInformation<GenericTypeWithBound> information =
        ClassTypeInformation.from(GenericTypeWithBound.class);
    assertEquals(Person.class, information.getProperty("person").getType());
  }
コード例 #8
0
  /** @see DATACMNS-39 */
  @Test
  public void resolvesWildCardTypeCorrectly() {

    TypeInformation<ClassWithWildCardBound> information =
        ClassTypeInformation.from(ClassWithWildCardBound.class);

    TypeInformation<?> property = information.getProperty("wildcard");
    assertThat(property.isCollectionLike(), is(true));
    assertThat(property.getComponentType().getType(), is(typeCompatibleWith(String.class)));

    property = information.getProperty("complexWildcard");
    assertThat(property.isCollectionLike(), is(true));

    TypeInformation<?> component = property.getComponentType();
    assertThat(component.isCollectionLike(), is(true));
    assertThat(component.getComponentType().getType(), is(typeCompatibleWith(String.class)));
  }
コード例 #9
0
  @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());
  }
コード例 #10
0
  /** @see DATACMNS-309 */
  @Test
  @SuppressWarnings("rawtypes")
  public void findsGetterOnInterface() {

    TypeInformation<Product> information = from(Product.class);
    TypeInformation<?> categoryIdInfo = information.getProperty("category.id");

    assertThat(categoryIdInfo, is(notNullValue()));
    assertThat(categoryIdInfo, is((TypeInformation) from(Long.class)));
  }
コード例 #11
0
  @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());
  }