commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1241133 [2/2] - in /commons/sandbox/beanutils2/trunk: ./ src/main/java/org/apache/commons/beanutils2/type/ src/test/java/org/apache/commons/beanutils2/type/
Date Mon, 06 Feb 2012 19:56:43 GMT
Added: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypeLiteralTypeResolutionTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypeLiteralTypeResolutionTest.java?rev=1241133&view=auto
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypeLiteralTypeResolutionTest.java
(added)
+++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypeLiteralTypeResolutionTest.java
Mon Feb  6 19:56:42 2012
@@ -0,0 +1,469 @@
+package org.apache.commons.beanutils2.type;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+import static org.apache.commons.beanutils2.type.Asserts.assertEqualsBothWays;
+import static org.apache.commons.beanutils2.type.Asserts.assertNotSerializable;
+import static org.apache.commons.beanutils2.type.Types.arrayOf;
+import static org.apache.commons.beanutils2.type.Types.listOf;
+import static org.apache.commons.beanutils2.type.Types.newParameterizedType;
+import static org.apache.commons.beanutils2.type.Types.newParameterizedTypeWithOwner;
+import static org.apache.commons.beanutils2.type.Types.setOf;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.AbstractCollection;
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.apache.commons.beanutils2.type.TypeLiteral;
+import org.apache.commons.beanutils2.type.Types;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * This test checks that TypeLiteral can perform type resolution on its members.
+ *
+ * @author jessewilson@google.com (Jesse Wilson)
+ */
+public class TypeLiteralTypeResolutionTest
+{
+
+    Type arrayListOfString = newParameterizedType( ArrayList.class, String.class );
+
+    Type hasGenericFieldsOfShort = newParameterizedTypeWithOwner( getClass(), HasGenericFields.class,
Short.class );
+
+    Type hasGenericConstructorOfShort = newParameterizedTypeWithOwner( getClass(), GenericConstructor.class,
+                                                                       Short.class );
+
+    Type throwerOfNpe = newParameterizedTypeWithOwner( getClass(), Thrower.class, NullPointerException.class
);
+
+    Type hasArrayOfShort = newParameterizedTypeWithOwner( getClass(), HasArray.class, Short.class
);
+
+    Type hasRelatedOfString = newParameterizedTypeWithOwner( getClass(), HasRelated.class,
String.class, String.class );
+
+    Type mapK = Map.class.getTypeParameters()[0];
+
+    Type hashMapK = HashMap.class.getTypeParameters()[0];
+
+    Type setEntryKV;
+
+    Type entryStringInteger = setOf( newParameterizedTypeWithOwner( Map.class, Map.Entry.class,
String.class,
+                                                                    Integer.class ) );
+
+    Field list;
+
+    Field instance;
+
+    Constructor<GenericConstructor> newHasGenericConstructor;
+
+    Constructor<Thrower> newThrower;
+
+    Constructor newString;
+
+    Method stringIndexOf;
+
+    Method comparableCompareTo;
+
+    Method getArray;
+
+    Method getSetOfArray;
+
+    Method echo;
+
+    Method throwS;
+
+    @Before
+    public void setUp()
+        throws Exception
+    {
+
+        list = HasGenericFields.class.getField( "list" );
+        instance = HasGenericFields.class.getField( "instance" );
+        newHasGenericConstructor = GenericConstructor.class.getConstructor( Object.class,
Object.class );
+        newThrower = Thrower.class.getConstructor();
+        stringIndexOf = String.class.getMethod( "indexOf", String.class );
+        newString = String.class.getConstructor( String.class );
+        comparableCompareTo = Comparable.class.getMethod( "compareTo", Object.class );
+        getArray = HasArray.class.getMethod( "getArray" );
+        getSetOfArray = HasArray.class.getMethod( "getSetOfArray" );
+        echo = HasRelated.class.getMethod( "echo", Object.class );
+        throwS = Thrower.class.getMethod( "throwS" );
+        setEntryKV = HashMap.class.getMethod( "entrySet" ).getGenericReturnType();
+    }
+
+    @Test
+    public void testDirectInheritance()
+        throws NoSuchMethodException
+    {
+        TypeLiteral<?> resolver = TypeLiteral.get( arrayListOfString );
+        assertEquals( listOf( String.class ),
+                      resolver.getReturnType( List.class.getMethod( "subList", int.class,
int.class ) ).getType() );
+        assertEquals( ImmutableList.<TypeLiteral<?>> of( TypeLiteral.get( String.class
) ),
+                      resolver.getParameterTypes( Collection.class.getMethod( "add", Object.class
) ) );
+    }
+
+    @Test
+    public void testGenericSupertype()
+    {
+        TypeLiteral<?> resolver = TypeLiteral.get( arrayListOfString );
+        assertEquals( newParameterizedType( Collection.class, String.class ),
+                      resolver.getSupertype( Collection.class ).getType() );
+        assertEquals( newParameterizedType( Iterable.class, String.class ),
+                      resolver.getSupertype( Iterable.class ).getType() );
+        assertEquals( newParameterizedType( AbstractList.class, String.class ),
+                      resolver.getSupertype( AbstractList.class ).getType() );
+        assertEquals( Object.class, resolver.getSupertype( Object.class ).getType() );
+    }
+
+    @Test
+    public void testRecursiveTypeVariable()
+    {
+        TypeLiteral<?> resolver = TypeLiteral.get( MyInteger.class );
+        assertEquals( MyInteger.class, resolver.getParameterTypes( comparableCompareTo ).get(
0 ).getType() );
+    }
+
+    interface MyComparable<E extends MyComparable<E>>
+        extends Comparable<E>
+    {
+    }
+
+    static class MyInteger
+        implements MyComparable<MyInteger>
+    {
+        int value;
+
+        public int compareTo( MyInteger o )
+        {
+            return value - o.value;
+        }
+    }
+
+    @Test
+    public void testFields()
+    {
+        TypeLiteral<?> resolver = TypeLiteral.get( hasGenericFieldsOfShort );
+        assertEquals( listOf( Short.class ), resolver.getFieldType( list ).getType() );
+        assertEquals( Short.class, resolver.getFieldType( instance ).getType() );
+    }
+
+    static class HasGenericFields<T>
+    {
+        public List<T> list;
+
+        public T instance;
+    }
+
+    @Test
+    public void testGenericConstructor()
+        throws NoSuchMethodException
+    {
+        TypeLiteral<?> resolver = TypeLiteral.get( hasGenericConstructorOfShort );
+        assertEquals( Short.class, resolver.getParameterTypes( newHasGenericConstructor ).get(
0 ).getType() );
+    }
+
+    static class GenericConstructor<S>
+    {
+        @SuppressWarnings( "UnusedDeclaration" )
+        public <T> GenericConstructor( S s, T t )
+        {
+        }
+    }
+
+    @Test
+    public void testThrowsExceptions()
+    {
+        TypeLiteral<?> type = TypeLiteral.get( throwerOfNpe );
+        assertEquals( NullPointerException.class, type.getExceptionTypes( newThrower ).get(
0 ).getType() );
+        assertEquals( NullPointerException.class, type.getExceptionTypes( throwS ).get( 0
).getType() );
+    }
+
+    static class Thrower<S extends Exception>
+    {
+        public Thrower()
+            throws S
+        {
+        }
+
+        public void throwS()
+            throws S
+        {
+        }
+    }
+
+    @Test
+    public void testArrays()
+    {
+        TypeLiteral<?> resolver = TypeLiteral.get( hasArrayOfShort );
+        assertEquals( arrayOf( Short.class ), resolver.getReturnType( getArray ).getType()
);
+        assertEquals( setOf( arrayOf( Short.class ) ), resolver.getReturnType( getSetOfArray
).getType() );
+    }
+
+    static interface HasArray<T extends Number>
+    {
+        T[] getArray();
+
+        Set<T[]> getSetOfArray();
+    }
+
+    @Test
+    public void testRelatedTypeVariables()
+    {
+        TypeLiteral<?> resolver = TypeLiteral.get( hasRelatedOfString );
+        assertEquals( String.class, resolver.getParameterTypes( echo ).get( 0 ).getType()
);
+        assertEquals( String.class, resolver.getReturnType( echo ).getType() );
+    }
+
+    interface HasRelated<T, R extends T>
+    {
+        T echo( R r );
+    }
+
+    /** Ensure the cache doesn't cache too much */
+    @Test
+    public void testCachingAndReindexing()
+        throws NoSuchMethodException
+    {
+        TypeLiteral<?> resolver =
+            TypeLiteral.get( newParameterizedTypeWithOwner( getClass(), HasLists.class, String.class,
Short.class ) );
+        assertEquals( listOf( String.class ), resolver.getReturnType( HasLists.class.getMethod(
"listS" ) ).getType() );
+        assertEquals( listOf( Short.class ), resolver.getReturnType( HasLists.class.getMethod(
"listT" ) ).getType() );
+    }
+
+    interface HasLists<S, T>
+    {
+        List<S> listS();
+
+        List<T> listT();
+
+        List<Map.Entry<S, T>> listEntries();
+    }
+
+    @Test
+    public void testUnsupportedQueries()
+        throws NoSuchMethodException
+    {
+        TypeLiteral<?> resolver = TypeLiteral.get( arrayListOfString );
+
+        try
+        {
+            resolver.getExceptionTypes( stringIndexOf );
+            fail();
+        }
+        catch ( IllegalArgumentException e )
+        {
+            assertEquals( "public int java.lang.String.indexOf(java.lang.String) is not defined
by a "
+                + "supertype of java.util.ArrayList<java.lang.String>", e.getMessage()
);
+        }
+        try
+        {
+            resolver.getParameterTypes( stringIndexOf );
+            fail();
+        }
+        catch ( Exception e )
+        {
+            assertEquals( "public int java.lang.String.indexOf(java.lang.String) is not defined
by a "
+                + "supertype of java.util.ArrayList<java.lang.String>", e.getMessage()
);
+        }
+        try
+        {
+            resolver.getReturnType( stringIndexOf );
+            fail();
+        }
+        catch ( Exception e )
+        {
+            assertEquals( "public int java.lang.String.indexOf(java.lang.String) is not defined
by a "
+                + "supertype of java.util.ArrayList<java.lang.String>", e.getMessage()
);
+        }
+        try
+        {
+            resolver.getSupertype( String.class );
+            fail();
+        }
+        catch ( Exception e )
+        {
+            assertEquals( "class java.lang.String is not a supertype of " + "java.util.ArrayList<java.lang.String>",
+                          e.getMessage() );
+        }
+        try
+        {
+            resolver.getExceptionTypes( newString );
+            fail();
+        }
+        catch ( Exception e )
+        {
+            assertEquals( "public java.lang.String(java.lang.String) does not construct "
+                + "a supertype of java.util.ArrayList<java.lang.String>", e.getMessage()
);
+        }
+        try
+        {
+            resolver.getParameterTypes( newString );
+            fail();
+        }
+        catch ( Exception e )
+        {
+            assertEquals( "public java.lang.String(java.lang.String) does not construct "
+                + "a supertype of java.util.ArrayList<java.lang.String>", e.getMessage()
);
+        }
+    }
+
+    @Test
+    public void testResolve()
+    {
+        TypeLiteral<?> typeResolver = TypeLiteral.get( StringIntegerMap.class );
+        assertEquals( String.class, typeResolver.resolveType( mapK ) );
+
+        typeResolver = new TypeLiteral<Map<String, Integer>>()
+        {
+        };
+        assertEquals( String.class, typeResolver.resolveType( mapK ) );
+        assertEquals( Types.mapOf( String.class, Integer.class ), typeResolver.getSupertype(
Map.class ).getType() );
+
+        typeResolver = new TypeLiteral<BetterMap<String, Integer>>()
+        {
+        };
+        assertEquals( String.class, typeResolver.resolveType( mapK ) );
+
+        typeResolver = new TypeLiteral<BestMap<String, Integer>>()
+        {
+        };
+        assertEquals( String.class, typeResolver.resolveType( mapK ) );
+
+        typeResolver = TypeLiteral.get( StringIntegerHashMap.class );
+        assertEquals( String.class, typeResolver.resolveType( mapK ) );
+        assertEquals( String.class, typeResolver.resolveType( hashMapK ) );
+        assertEquals( entryStringInteger, typeResolver.resolveType( setEntryKV ) );
+        assertEquals( Object.class, typeResolver.getSupertype( Object.class ).getType() );
+    }
+
+    @Test
+    public void testOnObject()
+    {
+        TypeLiteral<?> typeResolver = TypeLiteral.get( Object.class );
+        assertEquals( Object.class, typeResolver.getSupertype( Object.class ).getType() );
+        assertEquals( Object.class, typeResolver.getRawType() );
+
+        // interfaces also resolve Object
+        typeResolver = TypeLiteral.get( Types.setOf( Integer.class ) );
+        assertEquals( Object.class, typeResolver.getSupertype( Object.class ).getType() );
+    }
+
+    interface StringIntegerMap
+        extends Map<String, Integer>
+    {
+    }
+
+    interface BetterMap<K1, V1>
+        extends Map<K1, V1>
+    {
+    }
+
+    interface BestMap<K2, V2>
+        extends BetterMap<K2, V2>
+    {
+    }
+
+    static class StringIntegerHashMap
+        extends HashMap<String, Integer>
+    {
+    }
+
+    @Test
+    public void testGetSupertype()
+    {
+        TypeLiteral<AbstractList<String>> listOfString = new TypeLiteral<AbstractList<String>>()
+        {
+        };
+        assertEquals( Types.newParameterizedType( AbstractCollection.class, String.class
),
+                      listOfString.getSupertype( AbstractCollection.class ).getType() );
+
+        TypeLiteral arrayListOfE =
+            TypeLiteral.get( newParameterizedType( ArrayList.class, ArrayList.class.getTypeParameters()
) );
+        assertEquals( newParameterizedType( AbstractCollection.class, ArrayList.class.getTypeParameters()
),
+                      arrayListOfE.getSupertype( AbstractCollection.class ).getType() );
+    }
+
+    @Test
+    public void testGetSupertypeForArraysAsList()
+    {
+        Class<? extends List> arraysAsListClass = Arrays.asList().getClass();
+        Type anotherE = arraysAsListClass.getTypeParameters()[0];
+        TypeLiteral type = TypeLiteral.get( newParameterizedType( AbstractList.class, anotherE
) );
+        assertEquals( newParameterizedType( AbstractCollection.class, anotherE ),
+                      type.getSupertype( AbstractCollection.class ).getType() );
+    }
+
+    @Test
+    public void testWildcards()
+        throws NoSuchFieldException
+    {
+        TypeLiteral<Parameterized<String>> ofString = new TypeLiteral<Parameterized<String>>()
+        {
+        };
+
+        assertEquals( new TypeLiteral<List<String>>()
+        {
+        }.getType(), ofString.getFieldType( Parameterized.class.getField( "t" ) ).getType()
);
+        assertEquals( new TypeLiteral<List<? extends String>>()
+        {
+        }.getType(), ofString.getFieldType( Parameterized.class.getField( "extendsT" ) ).getType()
);
+        assertEquals( new TypeLiteral<List<? super String>>()
+        {
+        }.getType(), ofString.getFieldType( Parameterized.class.getField( "superT" ) ).getType()
);
+    }
+
+    static class Parameterized<T>
+    {
+        public List<T> t;
+
+        public List<? extends T> extendsT;
+
+        public List<? super T> superT;
+    }
+
+    // TODO(jessewilson): tests for tricky bounded types like <T extends Collection, Serializable>
+
+    @Test
+    public void testEqualsAndHashCode()
+        throws IOException
+    {
+        TypeLiteral<?> a1 = TypeLiteral.get( arrayListOfString );
+        TypeLiteral<?> a2 = TypeLiteral.get( arrayListOfString );
+        TypeLiteral<?> b = TypeLiteral.get( listOf( String.class ) );
+        assertEqualsBothWays( a1, a2 );
+        assertNotSerializable( a1 );
+        assertFalse( a1.equals( b ) );
+    }
+
+}

Propchange: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypeLiteralTypeResolutionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypeLiteralTypeResolutionTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypeLiteralTypeResolutionTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypesTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypesTest.java?rev=1241133&view=auto
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypesTest.java
(added)
+++ commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypesTest.java
Mon Feb  6 19:56:42 2012
@@ -0,0 +1,277 @@
+package org.apache.commons.beanutils2.type;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.apache.commons.beanutils2.type.Asserts.assertContains;
+import static org.apache.commons.beanutils2.type.Asserts.assertEqualWhenReserialized;
+import static org.apache.commons.beanutils2.type.Asserts.assertEqualsBothWays;
+import static org.apache.commons.beanutils2.type.Types.subtypeOf;
+import static org.apache.commons.beanutils2.type.Types.supertypeOf;
+
+import java.io.IOException;
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.WildcardType;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.apache.commons.beanutils2.type.MoreTypes;
+import org.apache.commons.beanutils2.type.TypeLiteral;
+import org.apache.commons.beanutils2.type.Types;
+
+
+/**
+ * @author jessewilson@google.com (Jesse Wilson)
+ */
+public class TypesTest
+{
+
+    // generic types for comparison
+    Map<String, Integer> a;
+
+    Inner<Float, Double> b;
+
+    List<String[][]> c;
+
+    List<String> d;
+
+    Set<String> e;
+
+    Outer<String>.Inner f;
+
+    private ParameterizedType mapStringInteger;
+
+    private ParameterizedType innerFloatDouble;
+
+    private ParameterizedType listStringArray;
+
+    private ParameterizedType listString;
+
+    private ParameterizedType setString;
+
+    private GenericArrayType stringArray;
+
+    private ParameterizedType outerInner;
+
+    @Before
+    public void setUp()
+        throws Exception
+    {
+        mapStringInteger = (ParameterizedType) getClass().getDeclaredField( "a" ).getGenericType();
+        innerFloatDouble = (ParameterizedType) getClass().getDeclaredField( "b" ).getGenericType();
+        listStringArray = (ParameterizedType) getClass().getDeclaredField( "c" ).getGenericType();
+        listString = (ParameterizedType) getClass().getDeclaredField( "d" ).getGenericType();
+        setString = (ParameterizedType) getClass().getDeclaredField( "e" ).getGenericType();
+        stringArray = (GenericArrayType) listStringArray.getActualTypeArguments()[0];
+        outerInner = (ParameterizedType) getClass().getDeclaredField( "f" ).getGenericType();
+    }
+
+    @Test
+    public void testListSetMap()
+    {
+        assertEqualsBothWays( mapStringInteger, Types.mapOf( String.class, Integer.class
) );
+        assertEqualsBothWays( listString, Types.listOf( String.class ) );
+        assertEqualsBothWays( setString, Types.setOf( String.class ) );
+    }
+
+    @Test
+    public void testDefensiveCopies()
+    {
+        Type[] arguments = new Type[] { String.class, Integer.class };
+        ParameterizedType parameterizedType = Types.newParameterizedType( Map.class, arguments
);
+        arguments[0] = null;
+        assertEquals( String.class, parameterizedType.getActualTypeArguments()[0] );
+        parameterizedType.getActualTypeArguments()[1] = null;
+        assertEquals( Integer.class, parameterizedType.getActualTypeArguments()[1] );
+    }
+
+    @Test
+    public void testTypeWithOwnerType()
+    {
+        ParameterizedType actual =
+            Types.newParameterizedTypeWithOwner( TypesTest.class, Inner.class, Float.class,
Double.class );
+        assertEquals( TypesTest.class, actual.getOwnerType() );
+        assertEqualsBothWays( innerFloatDouble, actual );
+        // The JDK prints this out as:
+        // org.apache.commons.beanutils2.type.TypesTest.org.apache.commons.beanutils2.type.TypesTest$Inner<java.lang.Float,
java.lang.Double>
+        // and we think that's wrong, so the assertEquals comparison is worthless. :-(
+        // assertEquals(innerFloatDouble.toString(), actual.toString());
+
+        // We think the correct comparison is:
+        assertEquals( "org.apache.commons.beanutils2.type.TypesTest$Inner<java.lang.Float,
java.lang.Double>", actual.toString() );
+    }
+
+    @Test
+    public void testTypeParametersMustNotBePrimitives()
+    {
+        try
+        {
+            Types.newParameterizedType( Map.class, String.class, int.class );
+            fail();
+        }
+        catch ( IllegalArgumentException expected )
+        {
+            assertContains( expected.getMessage(), "Primitive types are not allowed in type
parameters: int" );
+        }
+    }
+
+    public List<? extends CharSequence> wildcardExtends;
+
+    public List<? super CharSequence> wildcardSuper;
+
+    public List<?> wildcardObject;
+
+    @Test
+    public void testWildcardTypes()
+        throws NoSuchFieldException, IOException
+    {
+        assertEqualsBothWays( getWildcard( "wildcardSuper" ), supertypeOf( CharSequence.class
) );
+        assertEqualsBothWays( getWildcard( "wildcardExtends" ), subtypeOf( CharSequence.class
) );
+        assertEqualsBothWays( getWildcard( "wildcardObject" ), subtypeOf( Object.class )
);
+
+        assertEquals( "? super java.lang.CharSequence", supertypeOf( CharSequence.class ).toString()
);
+        assertEquals( "? extends java.lang.CharSequence", subtypeOf( CharSequence.class ).toString()
);
+        assertEquals( "?", subtypeOf( Object.class ).toString() );
+
+        assertEqualWhenReserialized( supertypeOf( CharSequence.class ) );
+        assertEqualWhenReserialized( subtypeOf( CharSequence.class ) );
+    }
+
+    @Test
+    public void testWildcardBoundsMustNotBePrimitives()
+    {
+        try
+        {
+            supertypeOf( int.class );
+            fail();
+        }
+        catch ( IllegalArgumentException expected )
+        {
+            assertContains( expected.getMessage(), "Primitive types are not allowed in wildcard
bounds: int" );
+        }
+
+        try
+        {
+            subtypeOf( int.class );
+            fail();
+        }
+        catch ( IllegalArgumentException expected )
+        {
+            assertContains( expected.getMessage(), "Primitive types are not allowed in wildcard
bounds: int" );
+        }
+    }
+
+    private WildcardType getWildcard( String fieldName )
+        throws NoSuchFieldException
+    {
+        ParameterizedType type = (ParameterizedType) getClass().getField( fieldName ).getGenericType();
+        return (WildcardType) type.getActualTypeArguments()[0];
+    }
+
+    @Test
+    public void testEqualsAndHashcode()
+    {
+        ParameterizedType parameterizedType = Types.newParameterizedType( Map.class, String.class,
Integer.class );
+        assertEqualsBothWays( mapStringInteger, parameterizedType );
+        assertEquals( mapStringInteger.toString(), parameterizedType.toString() );
+
+        GenericArrayType genericArrayType = Types.arrayOf( Types.arrayOf( String.class )
);
+        assertEqualsBothWays( stringArray, genericArrayType );
+        assertEquals( stringArray.toString(), genericArrayType.toString() );
+    }
+
+    @Test
+    public void testToString()
+    {
+        Assert.assertEquals( "java.lang.String", MoreTypes.typeToString( String.class ) );
+        assertEquals( "java.lang.String[][]", MoreTypes.typeToString( stringArray ) );
+        assertEquals( "java.util.Map<java.lang.String, java.lang.Integer>", MoreTypes.typeToString(
mapStringInteger ) );
+        assertEquals( "java.util.List<java.lang.String[][]>", MoreTypes.typeToString(
listStringArray ) );
+        assertEquals( innerFloatDouble.toString(), MoreTypes.typeToString( innerFloatDouble
) );
+    }
+
+    static class Owning<A>
+    {
+    }
+
+    /**
+     * Ensure that owning types are required when necessary, and forbidden otherwise.
+     */
+    @Test
+    public void testCanonicalizeRequiresOwnerTypes()
+        throws NoSuchFieldException
+    {
+        try
+        {
+            Types.newParameterizedType( Owning.class, String.class );
+            fail();
+        }
+        catch ( IllegalArgumentException expected )
+        {
+            assertContains( expected.getMessage(), "No owner type for enclosed " + Owning.class
);
+        }
+
+        try
+        {
+            Types.newParameterizedTypeWithOwner( Object.class, Set.class, String.class );
+        }
+        catch ( IllegalArgumentException expected )
+        {
+            assertContains( expected.getMessage(), "Owner type for unenclosed " + Set.class
);
+        }
+    }
+
+    @SuppressWarnings( "UnusedDeclaration" )
+    class Inner<T1, T2>
+    {
+    }
+
+    @Test
+    public void testInnerParameterizedEvenWithZeroArgs()
+    {
+        TypeLiteral<Outer<String>.Inner> type = new TypeLiteral<Outer<String>.Inner>()
+        {
+        };
+        assertEqualsBothWays( outerInner, type.getType() );
+
+        ParameterizedType parameterizedType = (ParameterizedType) type.getType();
+        assertEquals( 0, parameterizedType.getActualTypeArguments().length );
+        assertEquals( new TypeLiteral<Outer<String>>()
+        {
+        }.getType(), parameterizedType.getOwnerType() );
+        assertEquals( Outer.Inner.class, parameterizedType.getRawType() );
+    }
+
+    static class Outer<T>
+    {
+        class Inner
+        {
+        }
+    }
+
+}

Propchange: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypesTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/beanutils2/trunk/src/test/java/org/apache/commons/beanutils2/type/TypesTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message