diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AbstractMappingContext.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AbstractMappingContext.java index 2d3a419fa..e6419c837 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AbstractMappingContext.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/AbstractMappingContext.java @@ -162,6 +162,10 @@ public abstract class AbstractMappingContext descriptors = new HashMap(); @@ -196,8 +200,6 @@ public abstract class AbstractMappingContext(entity, typeInformation)); } - // Cache - persistentEntities.put(entity.getTypeInformation(), (E) entity); - return entity; } catch (IntrospectionException e) { throw new MappingException(e.getMessage(), e); @@ -270,7 +269,7 @@ public abstract class AbstractMappingContext initialEntity : initialEntitySet) { addPersistentEntity(initialEntity); } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/RepositoryProxy.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/RepositoryProxy.java index ab208f035..e3696abe9 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/RepositoryProxy.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/RepositoryProxy.java @@ -1,3 +1,18 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.repository; import java.io.Serializable; diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/AnnotationRepositoryMetadata.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/AnnotationRepositoryMetadata.java index 0f48c783c..faeab8328 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/AnnotationRepositoryMetadata.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/AnnotationRepositoryMetadata.java @@ -1,3 +1,18 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.repository.support; import org.springframework.data.repository.RepositoryProxy; diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/util/ArrayTypeDiscoverer.java b/spring-data-commons-core/src/main/java/org/springframework/data/util/ArrayTypeDiscoverer.java deleted file mode 100644 index 1ca2b5178..000000000 --- a/spring-data-commons-core/src/main/java/org/springframework/data/util/ArrayTypeDiscoverer.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.springframework.data.util; - -import java.lang.reflect.Array; -import java.lang.reflect.GenericArrayType; -import java.lang.reflect.Type; - -/** - * Special {@link TypeDiscoverer} handling {@link GenericArrayType}s. - * - * @author Oliver Gierke - */ -public class ArrayTypeDiscoverer extends TypeDiscoverer { - - private GenericArrayType type; - - /** - * @param type - * @param parent - * @param parent - */ - protected ArrayTypeDiscoverer(GenericArrayType type, TypeDiscoverer parent) { - super(type, null, parent); - this.type = type; - } - - /* (non-Javadoc) - * @see org.springframework.data.util.TypeDiscoverer#getType() - */ - @Override - @SuppressWarnings("unchecked") - public Class getType() { - - return (Class) Array.newInstance(resolveType(type.getGenericComponentType()), 0).getClass(); - } - - /* (non-Javadoc) - * @see org.springframework.data.util.TypeDiscoverer#getComponentType() - */ - @Override - public TypeInformation getComponentType() { - - Type componentType = type.getGenericComponentType(); - return createInfo(componentType); - } -} diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/util/ClassTypeInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/util/ClassTypeInformation.java index 941ecdeae..e98685cde 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/util/ClassTypeInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/util/ClassTypeInformation.java @@ -1,3 +1,18 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.util; import java.lang.reflect.Type; @@ -15,6 +30,13 @@ public class ClassTypeInformation extends TypeDiscoverer { private final Class type; + /** + * Simple factory method to easily create new instances of {@link ClassTypeInformation}. + * + * @param + * @param type + * @return + */ public static TypeInformation from(Class type) { return new ClassTypeInformation(type); } @@ -25,16 +47,13 @@ public class ClassTypeInformation extends TypeDiscoverer { * @param type */ public ClassTypeInformation(Class type) { - this(type, GenericTypeResolver.getTypeVariableMap(type), null); + this(type, GenericTypeResolver.getTypeVariableMap(type)); } - ClassTypeInformation(Class type, TypeDiscoverer parent) { - this(type, null, parent); - } - @SuppressWarnings("rawtypes") ClassTypeInformation(Class type, Map typeVariableMap, - TypeDiscoverer parent) { - super(type, typeVariableMap, parent); + @SuppressWarnings("rawtypes") + ClassTypeInformation(Class type, Map typeVariableMap) { + super(type, typeVariableMap); this.type = type; } @@ -68,27 +87,4 @@ public class ClassTypeInformation extends TypeDiscoverer { Class componentType = type.getComponentType(); return componentType.isArray() ? resolveArrayType(componentType) : componentType; } - - /* (non-Javadoc) - * @see org.springframework.data.util.TypeDiscoverer#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - - if (!super.equals(obj)) { - return false; - } - - ClassTypeInformation that = (ClassTypeInformation) obj; - return this.type.equals(that.type); - } - - /* (non-Javadoc) - * @see org.springframework.data.util.TypeDiscoverer#hashCode() - */ - @Override - public int hashCode() { - int result = super.hashCode(); - return result += 31 * type.hashCode(); - } } \ No newline at end of file diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/util/GenericArrayTypeInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/util/GenericArrayTypeInformation.java new file mode 100644 index 000000000..6e8828c07 --- /dev/null +++ b/spring-data-commons-core/src/main/java/org/springframework/data/util/GenericArrayTypeInformation.java @@ -0,0 +1,62 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.util; + +import java.lang.reflect.Array; +import java.lang.reflect.GenericArrayType; +import java.lang.reflect.Type; + +/** + * Special {@link TypeDiscoverer} handling {@link GenericArrayType}s. + * + * @author Oliver Gierke + */ +class GenericArrayTypeInformation extends ParameterizedTypeInformation { + + private GenericArrayType type; + + /** + * Creates a new {@link GenericArrayTypeInformation} for the given {@link GenericArrayTypeInformation} and + * {@link TypeDiscoverer}. + * + * @param type + * @param parent + */ + protected GenericArrayTypeInformation(GenericArrayType type, TypeDiscoverer parent) { + super(type, parent); + this.type = type; + } + + /* (non-Javadoc) + * @see org.springframework.data.util.TypeDiscoverer#getType() + */ + @Override + @SuppressWarnings("unchecked") + public Class getType() { + + return (Class) Array.newInstance(resolveType(type.getGenericComponentType()), 0).getClass(); + } + + /* (non-Javadoc) + * @see org.springframework.data.util.TypeDiscoverer#getComponentType() + */ + @Override + public TypeInformation getComponentType() { + + Type componentType = type.getGenericComponentType(); + return createInfo(componentType); + } +} diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java new file mode 100644 index 000000000..da780d6a0 --- /dev/null +++ b/spring-data-commons-core/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java @@ -0,0 +1,98 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.util; + +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.util.Map; + +import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; + +/** + * Base class for all types that include parameterization of some kind. Crucial as we have to take note of the parent + * class we will have to resolve generic parameters against. + * + * @author Oliver Gierke + */ +class ParameterizedTypeInformation extends TypeDiscoverer { + + private final TypeDiscoverer parent; + + + /** + * Creates a new {@link ParameterizedTypeInformation} for the given {@link Type} and parent {@link TypeDiscoverer}. + * + * @param type must not be {@literal null} + * @param parent must not be {@literal null} + */ + public ParameterizedTypeInformation(Type type, TypeDiscoverer parent) { + super(type, null); + Assert.notNull(parent); + this.parent = parent; + } + + /** + * Considers the parent's type variable map before invoking the super class method. + * + * @return + */ + @SuppressWarnings("rawtypes") + protected Map getTypeVariableMap() { + + return parent != null ? parent.getTypeVariableMap() : super.getTypeVariableMap(); + } + + /* (non-Javadoc) + * @see org.springframework.data.util.TypeDiscoverer#createInfo(java.lang.reflect.Type) + */ + @Override + protected TypeInformation createInfo(Type fieldType) { + if (parent.getType().equals(fieldType)) { + return parent; + } + + return super.createInfo(fieldType); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.util.TypeDiscoverer#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + + if (!super.equals(obj)) { + return false; + } + + if (!this.getClass().equals(obj.getClass())) { + return false; + } + + ParameterizedTypeInformation that = (ParameterizedTypeInformation) obj; + return this.parent == null ? that.parent == null : this.parent.equals(that.parent); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.util.TypeDiscoverer#hashCode() + */ + @Override + public int hashCode() { + return super.hashCode() + 31 * ObjectUtils.nullSafeHashCode(parent); + } +} diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeDiscoverer.java b/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeDiscoverer.java index df7de4b48..8c5dc3dfd 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeDiscoverer.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeDiscoverer.java @@ -1,3 +1,18 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.util; import static org.springframework.util.ObjectUtils.*; @@ -28,23 +43,19 @@ class TypeDiscoverer implements TypeInformation { @SuppressWarnings("rawtypes") private final Map typeVariableMap; private final Map> fieldTypes = new ConcurrentHashMap>(); - private final TypeDiscoverer parent; /** * Creates a ne {@link TypeDiscoverer} for the given type, type variable map and parent. * - * @param type must not be null. + * @param type must not be null. * @param typeVariableMap - * @param parent */ @SuppressWarnings("rawtypes") - protected TypeDiscoverer(Type type, Map typeVariableMap, - TypeDiscoverer parent) { + protected TypeDiscoverer(Type type, Map typeVariableMap) { Assert.notNull(type); this.type = type; this.typeVariableMap = typeVariableMap; - this.parent = parent; } /** @@ -54,9 +65,9 @@ class TypeDiscoverer implements TypeInformation { * @return */ @SuppressWarnings("rawtypes") - private Map getTypeVariableMap() { + protected Map getTypeVariableMap() { - return parent != null ? parent.getTypeVariableMap() : typeVariableMap; + return typeVariableMap; } /** @@ -71,10 +82,14 @@ class TypeDiscoverer implements TypeInformation { if (fieldType.equals(this.type)) { return this; } + + if (fieldType instanceof Class) { + return new ClassTypeInformation((Class) fieldType); + } if (fieldType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) fieldType; - return new TypeDiscoverer(parameterizedType, null, this); + return new ParameterizedTypeInformation(parameterizedType, this); } if (fieldType instanceof TypeVariable) { @@ -82,12 +97,8 @@ class TypeDiscoverer implements TypeInformation { return new TypeVariableTypeInformation(variable, type, this); } - if (fieldType instanceof Class) { - return new ClassTypeInformation((Class) fieldType, this); - } - if (fieldType instanceof GenericArrayType) { - return new ArrayTypeDiscoverer((GenericArrayType) fieldType, this); + return new GenericArrayTypeInformation((GenericArrayType) fieldType, this); } throw new IllegalArgumentException(); @@ -145,7 +156,7 @@ class TypeDiscoverer implements TypeInformation { String head = fieldname.substring(0, separatorIndex); TypeInformation info = fieldTypes.get(head); - return info.getProperty(fieldname.substring(separatorIndex + 1)); + return info == null ? null : info.getProperty(fieldname.substring(separatorIndex + 1)); } private TypeInformation getPropertyInformation(String fieldname) { @@ -237,9 +248,8 @@ class TypeDiscoverer implements TypeInformation { boolean typeEqual = nullSafeEquals(this.type, that.type); boolean typeVariableMapEqual = nullSafeEquals(this.typeVariableMap, that.typeVariableMap); - boolean parentEqual = nullSafeEquals(this.parent, that.parent); - return typeEqual && typeVariableMapEqual && parentEqual; + return typeEqual && typeVariableMapEqual; } /* @@ -253,7 +263,6 @@ class TypeDiscoverer implements TypeInformation { int result = 17; result += nullSafeHashCode(type); result += nullSafeHashCode(typeVariableMap); - result += nullSafeHashCode(parent); return result; } } \ No newline at end of file diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeVariableTypeInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeVariableTypeInformation.java index 9a84fee16..9185e775e 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeVariableTypeInformation.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/util/TypeVariableTypeInformation.java @@ -1,3 +1,18 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.util; import static org.springframework.util.ObjectUtils.*; @@ -14,7 +29,7 @@ import org.springframework.util.Assert; * * @author Oliver Gierke */ -class TypeVariableTypeInformation extends TypeDiscoverer { +class TypeVariableTypeInformation extends ParameterizedTypeInformation { private final TypeVariable variable; private final Type owningType; @@ -29,7 +44,7 @@ class TypeVariableTypeInformation extends TypeDiscoverer { */ public TypeVariableTypeInformation(TypeVariable variable, Type owningType, TypeDiscoverer parent) { - super(variable, null, parent); + super(variable, parent); Assert.notNull(variable); this.variable = variable; this.owningType = owningType; diff --git a/spring-data-commons-core/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java b/spring-data-commons-core/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java index 424a708f9..b700a832b 100644 --- a/spring-data-commons-core/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java +++ b/spring-data-commons-core/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java @@ -1,3 +1,18 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.util; import static org.hamcrest.CoreMatchers.*; @@ -109,6 +124,15 @@ public class ClassTypeInformationUnitTests { assertEquals(Map.class, map.getType()); assertEquals(Calendar.class, map.getMapValueType().getType()); } + + @Test + public void typeInfoDoesNotEqualForGenericTypesWithDifferentParent() { + + TypeInformation first = ClassTypeInformation.from(ConcreteWrapper.class); + TypeInformation second = ClassTypeInformation.from(AnotherConcreteWrapper.class); + + assertFalse(first.getProperty("wrapped").equals(second.getProperty("wrapped"))); + } static class StringMapContainer extends MapContainer { @@ -171,4 +195,8 @@ public class ClassTypeInformationUnitTests { static class ConcreteWrapper extends GenericWrapper { } + + static class AnotherConcreteWrapper extends GenericWrapper { + + } } diff --git a/spring-data-commons-core/src/test/java/org/springframework/data/util/ParameterizedTypeUnitTests.java b/spring-data-commons-core/src/test/java/org/springframework/data/util/ParameterizedTypeUnitTests.java new file mode 100644 index 000000000..3a68c1502 --- /dev/null +++ b/spring-data-commons-core/src/test/java/org/springframework/data/util/ParameterizedTypeUnitTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.util; + +import static org.junit.Assert.*; + +import org.junit.Test; + +/** + * Unit tests for {@link ParameterizedTypeInformation}. + * + * @author Oliver Gierke + */ +public class ParameterizedTypeUnitTests { + + @Test + public void considersTypeInformationsWithDifferingParentsNotEqual() { + + TypeDiscoverer stringParent = new TypeDiscoverer(String.class, null); + TypeDiscoverer objectParent = new TypeDiscoverer(Object.class, null); + + ParameterizedTypeInformation first = new ParameterizedTypeInformation(Object.class, stringParent); + ParameterizedTypeInformation second = new ParameterizedTypeInformation(Object.class, objectParent); + + assertFalse(first.equals(second)); + } + + @Test + public void considersTypeInformationsWithSameParentsNotEqual() { + + TypeDiscoverer stringParent = new TypeDiscoverer(String.class, null); + + ParameterizedTypeInformation first = new ParameterizedTypeInformation(Object.class, stringParent); + ParameterizedTypeInformation second = new ParameterizedTypeInformation(Object.class, stringParent); + + assertTrue(first.equals(second)); + } +} diff --git a/spring-data-commons-core/src/test/java/org/springframework/data/util/TypeDiscovererUnitTests.java b/spring-data-commons-core/src/test/java/org/springframework/data/util/TypeDiscovererUnitTests.java index 677fb6b79..23e628985 100644 --- a/spring-data-commons-core/src/test/java/org/springframework/data/util/TypeDiscovererUnitTests.java +++ b/spring-data-commons-core/src/test/java/org/springframework/data/util/TypeDiscovererUnitTests.java @@ -1,16 +1,96 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.util; +import static org.junit.Assert.*; + +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.util.Map; + import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; /** * Unit tests for {@link TypeDiscoverer}. - * + * * @author Oliver Gierke */ +@RunWith(MockitoJUnitRunner.class) public class TypeDiscovererUnitTests { + + @Mock + @SuppressWarnings("rawtypes") + Map firstMap; + + @Mock + @SuppressWarnings("rawtypes") + Map secondMap; @Test(expected = IllegalArgumentException.class) public void rejectsNullType() { - new TypeDiscoverer(null, null, null); + new TypeDiscoverer(null, null); + } + + @Test + public void isNotEqualIfTypesDiffer() { + + TypeDiscoverer objectTypeInfo = new TypeDiscoverer(Object.class, null); + TypeDiscoverer stringTypeInfo = new TypeDiscoverer(String.class, null); + + assertFalse(objectTypeInfo.equals(stringTypeInfo)); + } + + @Test + public void isNotEqualIfTypeVariableMapsDiffer() { + + assertFalse(firstMap.equals(secondMap)); + + TypeDiscoverer first = new TypeDiscoverer(Object.class, firstMap); + TypeDiscoverer second = new TypeDiscoverer(Object.class, secondMap); + + assertFalse(first.equals(second)); + } + + @Test + public void dealsWithTypesReferencingThemselves() { + + TypeInformation information = new ClassTypeInformation(SelfReferencing.class); + TypeInformation first = information.getProperty("parent").getMapValueType(); + TypeInformation second = first.getProperty("map").getMapValueType(); + assertEquals(first, second); + } + + @Test + public void dealsWithTypesReferencingThemselvesInAMap() { + + TypeInformation information = new ClassTypeInformation( + SelfReferencingMap.class); + TypeInformation mapValueType = information.getProperty("map").getMapValueType(); + assertEquals(mapValueType, information); + } + + class SelfReferencing { + + Map parent; + } + + class SelfReferencingMap { + Map map; } }