DATACMNS-485 - Fixed bug in ParameterizedTypeInformation.hashCode().

Previously, ParameterizedTypeInformation.hashCode() had been inconsistent to equals in case of a fully resolved parameterized type. This is now fixed by not including the parent reference in case a parameterized type is resolved completely.

Also, TypeDiscoverer.getActualType() does not return the component type for non-collection/non-maps anymore to make sure we don't accidentally unwrap parameterized types.
This commit is contained in:
Oliver Gierke
2014-04-02 09:38:02 +02:00
parent 389edd6748
commit f52635da13
3 changed files with 39 additions and 8 deletions

View File

@@ -95,6 +95,31 @@ public class ParameterizedTypeUnitTests {
is("org.springframework.data.util.ParameterizedTypeUnitTests$Localized<java.lang.String>"));
}
/**
* @see DATACMNS-485
*/
@Test
@SuppressWarnings("rawtypes")
public void hashCodeShouldBeConsistentWithEqualsForResolvedTypes() {
TypeInformation first = from(First.class).getProperty("property");
TypeInformation second = from(Second.class).getProperty("property");
assertThat(first, is(second));
assertThat(first.hashCode(), is(second.hashCode()));
}
/**
* @see DATACMNS-485
*/
@Test
@SuppressWarnings("rawtypes")
public void getActualTypeShouldNotUnwrapParameterizedTypes() {
TypeInformation type = from(First.class).getProperty("property");
assertThat(type.getActualType(), is(type));
}
@SuppressWarnings("serial")
class Localized<S> extends HashMap<Locale, S> {
S value;
@@ -109,4 +134,16 @@ public class ParameterizedTypeUnitTests {
Localized<String> param;
Localized2<String> param2;
}
class Parameterized<T> {
T property;
}
class First {
Parameterized<String> property;
}
class Second {
Parameterized<String> property;
}
}