diff options
author | Piotr Jastrzebski <haaawk@google.com> | 2014-08-06 12:02:48 +0100 |
---|---|---|
committer | Piotr Jastrzebski <haaawk@google.com> | 2014-08-06 14:34:49 +0100 |
commit | 68b539ed7be2762bcab43f1c05174ef4a1d15625 (patch) | |
tree | 1cedc03a0473716954d256dd183e53e00a92acf4 /test | |
parent | 4853f940efe0aaccf83a4af55a8dd640d8ef7274 (diff) | |
download | art-68b539ed7be2762bcab43f1c05174ef4a1d15625.tar.gz art-68b539ed7be2762bcab43f1c05174ef4a1d15625.tar.bz2 art-68b539ed7be2762bcab43f1c05174ef4a1d15625.zip |
Add test for equals and hashCode in ParameterizedType
and GenericArrayType.
Bug: 14590652
Bug: https://code.google.com/p/android/issues/detail?id=74060
Change-Id: Ic814bcc24b1461b42ac809eaaa7a41d9f5a60406
Diffstat (limited to 'test')
-rw-r--r-- | test/046-reflect/expected.txt | 14 | ||||
-rw-r--r-- | test/046-reflect/src/Main.java | 126 |
2 files changed, 140 insertions, 0 deletions
diff --git a/test/046-reflect/expected.txt b/test/046-reflect/expected.txt index ecb3599482..fa053fb92d 100644 --- a/test/046-reflect/expected.txt +++ b/test/046-reflect/expected.txt @@ -123,3 +123,17 @@ fields are unique fields are .equals methods are unique methods are .equals +type1 is a ParameterizedType +type2 is a ParameterizedType +type3 is a ParameterizedType +type1(java.util.Set<java.lang.String>) equals type2(java.util.Set<java.lang.String>) +type1(java.util.Set<java.lang.String>) equals type3(java.util.Set<java.lang.String>) +type1(java.util.Set<java.lang.String>) hashCode equals type2(java.util.Set<java.lang.String>) hashCode +type1(java.util.Set<java.lang.String>) hashCode equals type3(java.util.Set<java.lang.String>) hashCode +type1 is a GenericArrayType +type2 is a GenericArrayType +type3 is a GenericArrayType +type1(T[]) equals type2(T[]) +type1(T[]) equals type3(T[]) +type1(T[]) hashCode equals type2(T[]) hashCode +type1(T[]) hashCode equals type3(T[]) hashCode diff --git a/test/046-reflect/src/Main.java b/test/046-reflect/src/Main.java index 3e6d7007f9..11eb773cb4 100644 --- a/test/046-reflect/src/Main.java +++ b/test/046-reflect/src/Main.java @@ -18,8 +18,10 @@ import java.lang.reflect.*; import java.io.IOException; import java.util.Collections; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Set; /** * Reflection test. @@ -579,6 +581,118 @@ public class Main { } } + public static void checkParametrizedTypeEqualsAndHashCode() { + Method method1; + Method method2; + Method method3; + try { + method1 = ParametrizedTypeTest.class.getDeclaredMethod("aMethod", Set.class); + method2 = ParametrizedTypeTest.class.getDeclaredMethod("aMethod", Set.class); + method3 = ParametrizedTypeTest.class.getDeclaredMethod("aMethodIdentical", Set.class); + } catch (NoSuchMethodException nsme) { + throw new RuntimeException(nsme); + } + + List<Type> types1 = Arrays.asList(method1.getGenericParameterTypes()); + List<Type> types2 = Arrays.asList(method2.getGenericParameterTypes()); + List<Type> types3 = Arrays.asList(method3.getGenericParameterTypes()); + + Type type1 = types1.get(0); + Type type2 = types2.get(0); + Type type3 = types3.get(0); + + if (type1 instanceof ParameterizedType) { + System.out.println("type1 is a ParameterizedType"); + } + if (type2 instanceof ParameterizedType) { + System.out.println("type2 is a ParameterizedType"); + } + if (type3 instanceof ParameterizedType) { + System.out.println("type3 is a ParameterizedType"); + } + + if (type1.equals(type2)) { + System.out.println("type1("+type1+") equals type2("+type2+")"); + } else { + System.out.println("type1("+type1+") does not equal type2("+type2+")"); + } + + if (type1.equals(type3)) { + System.out.println("type1("+type1+") equals type3("+type3+")"); + } else { + System.out.println("type1("+type1+") does not equal type3("+type3+")"); + } + if (type1.hashCode() == type2.hashCode()) { + System.out.println("type1("+type1+") hashCode equals type2("+type2+") hashCode"); + } else { + System.out.println( + "type1("+type1+") hashCode does not equal type2("+type2+") hashCode"); + } + + if (type1.hashCode() == type3.hashCode()) { + System.out.println("type1("+type1+") hashCode equals type3("+type3+") hashCode"); + } else { + System.out.println( + "type1("+type1+") hashCode does not equal type3("+type3+") hashCode"); + } + } + + public static void checkGenericArrayTypeEqualsAndHashCode() { + Method method1; + Method method2; + Method method3; + try { + method1 = GenericArrayTypeTest.class.getDeclaredMethod("aMethod", Object[].class); + method2 = GenericArrayTypeTest.class.getDeclaredMethod("aMethod", Object[].class); + method3 = GenericArrayTypeTest.class.getDeclaredMethod("aMethodIdentical", Object[].class); + } catch (NoSuchMethodException nsme) { + throw new RuntimeException(nsme); + } + + List<Type> types1 = Arrays.asList(method1.getGenericParameterTypes()); + List<Type> types2 = Arrays.asList(method2.getGenericParameterTypes()); + List<Type> types3 = Arrays.asList(method3.getGenericParameterTypes()); + + Type type1 = types1.get(0); + Type type2 = types2.get(0); + Type type3 = types3.get(0); + + if (type1 instanceof GenericArrayType) { + System.out.println("type1 is a GenericArrayType"); + } + if (type2 instanceof GenericArrayType) { + System.out.println("type2 is a GenericArrayType"); + } + if (type3 instanceof GenericArrayType) { + System.out.println("type3 is a GenericArrayType"); + } + + if (type1.equals(type2)) { + System.out.println("type1("+type1+") equals type2("+type2+")"); + } else { + System.out.println("type1("+type1+") does not equal type2("+type2+")"); + } + + if (type1.equals(type3)) { + System.out.println("type1("+type1+") equals type3("+type3+")"); + } else { + System.out.println("type1("+type1+") does not equal type3("+type3+")"); + } + if (type1.hashCode() == type2.hashCode()) { + System.out.println("type1("+type1+") hashCode equals type2("+type2+") hashCode"); + } else { + System.out.println( + "type1("+type1+") hashCode does not equal type2("+type2+") hashCode"); + } + + if (type1.hashCode() == type3.hashCode()) { + System.out.println("type1("+type1+") hashCode equals type3("+type3+") hashCode"); + } else { + System.out.println( + "type1("+type1+") hashCode does not equal type3("+type3+") hashCode"); + } + } + public static void main(String[] args) throws Exception { Main test = new Main(); test.run(); @@ -589,6 +703,8 @@ public class Main { checkClinitForMethods(); checkGeneric(); checkUnique(); + checkParametrizedTypeEqualsAndHashCode(); + checkGenericArrayTypeEqualsAndHashCode(); } } @@ -696,3 +812,13 @@ class Thrower { throw new UnsupportedOperationException(); } } + +class ParametrizedTypeTest { + public void aMethod(Set<String> names) {} + public void aMethodIdentical(Set<String> names) {} +} + +class GenericArrayTypeTest<T> { + public void aMethod(T[] names) {} + public void aMethodIdentical(T[] names) {} +} |