commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r890328 - /commons/proper/lang/trunk/src/test/org/apache/commons/lang3/ClassUtilsTest.java
Date Mon, 14 Dec 2009 13:54:06 GMT
Author: sebb
Date: Mon Dec 14 13:54:06 2009
New Revision: 890328

URL: http://svn.apache.org/viewvc?rev=890328&view=rev
Log:
Fix up raw types

Modified:
    commons/proper/lang/trunk/src/test/org/apache/commons/lang3/ClassUtilsTest.java

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang3/ClassUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang3/ClassUtilsTest.java?rev=890328&r1=890327&r2=890328&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang3/ClassUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang3/ClassUtilsTest.java Mon Dec
14 13:54:06 2009
@@ -210,8 +210,8 @@
     
     // -------------------------------------------------------------------------
     public void test_convertClassNamesToClasses_List() {
-        List list = new ArrayList();
-        List result = ClassUtils.convertClassNamesToClasses(list);
+        List<String> list = new ArrayList<String>();
+        List<Class<?>> result = ClassUtils.convertClassNamesToClasses(list);
         assertEquals(0, result.size());
         
         list.add("java.lang.String");
@@ -223,17 +223,19 @@
         assertEquals(null, result.get(1));
         assertEquals(Object.class, result.get(2));
 
-        list.add(new Object());
+        @SuppressWarnings("unchecked") // test what happens when non-gneric code adds wrong
type of element
+        List<Object> olist = (List<Object>)(List<?>)list; 
+        olist.add(new Object());
         try {
             ClassUtils.convertClassNamesToClasses(list);
-            fail();
-        } catch (ClassCastException ex) {}
+            fail("Should not have been able to convert list");
+        } catch (ClassCastException expected) {}
         assertEquals(null, ClassUtils.convertClassNamesToClasses(null));
     }
     
     public void test_convertClassesToClassNames_List() {
-        List list = new ArrayList();
-        List result = ClassUtils.convertClassesToClassNames(list);
+        List<Class<?>> list = new ArrayList<Class<?>>();
+        List<String> result = ClassUtils.convertClassesToClassNames(list);
         assertEquals(0, result.size());
         
         list.add(String.class);
@@ -245,11 +247,13 @@
         assertEquals(null, result.get(1));
         assertEquals("java.lang.Object", result.get(2));
 
-        list.add(new Object());
+        @SuppressWarnings("unchecked") // test what happens when non-gneric code adds wrong
type of element
+        List<Object> olist = (List<Object>)(List<?>)list; 
+        olist.add(new Object());
         try {
             ClassUtils.convertClassesToClassNames(list);
-            fail();
-        } catch (ClassCastException ex) {}
+            fail("Should not have been able to convert list");
+        } catch (ClassCastException expected) {}
         assertEquals(null, ClassUtils.convertClassesToClassNames(null));
     }
     



Mime
View raw message