From 6f688e40bacd89ff3bbd9dedfcf593d1e43843d0 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Tue, 13 May 2014 21:12:31 +0000 Subject: [PATCH] add some failing tests with wildcards git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1594385 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/lang3/reflect/TypeUtilsTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java b/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java index 5809d2e7e..53c5e1303 100644 --- a/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; import java.util.TreeSet; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.reflect.testbed.Foo; import org.apache.commons.lang3.reflect.testbed.GenericParent; @@ -696,6 +697,30 @@ public class TypeUtilsTest { final Field cClass = AClass.class.getField("cClass"); Assert.assertTrue(TypeUtils.equals(((ParameterizedType) cClass.getGenericType()).getActualTypeArguments()[0], simpleWildcard)); + Assert.assertEquals(String.format("? extends %s", String.class.getName()), TypeUtils.toString(simpleWildcard)); + Assert.assertEquals(String.format("? extends %s", String.class.getName()), simpleWildcard.toString()); + } + + @Test + public void testUnboundedWildcardType() { + final WildcardType unbounded = TypeUtils.wildcardType().withLowerBounds((Type) null).withUpperBounds().build(); + Assert.assertTrue(TypeUtils.equals(TypeUtils.WILDCARD_ALL, unbounded)); + Assert.assertArrayEquals(new Type[] { Object.class }, TypeUtils.getImplicitUpperBounds(unbounded)); + Assert.assertArrayEquals(new Type[] { null }, TypeUtils.getImplicitLowerBounds(unbounded)); + Assert.assertEquals("?", TypeUtils.toString(unbounded)); + Assert.assertEquals("?", unbounded.toString()); + } + + @Test + public void testLowerBoundedWildcardType() { + final WildcardType lowerBounded = TypeUtils.wildcardType().withLowerBounds(java.sql.Date.class).build(); + Assert.assertEquals(String.format("? super %s", java.sql.Date.class.getName()), TypeUtils.toString(lowerBounded)); + Assert.assertEquals(String.format("? super %s", java.sql.Date.class.getName()), lowerBounded.toString()); + + final TypeVariable> iterableT0 = Iterable.class.getTypeParameters()[0]; + final WildcardType lowerTypeVariable = TypeUtils.wildcardType().withLowerBounds(iterableT0).build(); + Assert.assertEquals(String.format("? super %s", iterableT0.getName()), TypeUtils.toString(lowerTypeVariable)); + Assert.assertEquals(String.format("? super %s", iterableT0.getName()), lowerTypeVariable.toString()); } @Test