harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r412166 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/lang/Enum.java test/java/org/apache/harmony/tests/java/lang/EnumTest.java
Date Tue, 06 Jun 2006 16:35:36 GMT
Author: tellison
Date: Tue Jun  6 09:35:35 2006
New Revision: 412166

URL: http://svn.apache.org/viewvc?rev=412166&view=rev
Log:
Additional tests and corresponding impl fixes for Enum

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Enum.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/EnumTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Enum.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Enum.java?rev=412166&r1=412165&r2=412166&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Enum.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Enum.java
Tue Jun  6 09:35:35 2006
@@ -80,6 +80,10 @@
     }
 
     public static <T extends Enum<T>> T valueOf(Class<T> enumType, String
name) {
+        if ((enumType == null) || (name == null)) {
+            // KA001=Argument must not be null
+            throw new NullPointerException(Msg.getString("KA001"));
+        }
         T[] values = getValues(enumType);
         if (values == null) {
             // KA005={0} is not an enum type

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/EnumTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/EnumTest.java?rev=412166&r1=412165&r2=412166&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/EnumTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/EnumTest.java
Tue Jun  6 09:35:35 2006
@@ -27,6 +27,13 @@
 
     Sample moe = Sample.MOE;
 
+    enum Empty {
+    }
+    
+    enum Bogus {
+        UNUSED
+    }
+    
     /**
      * @tests java.lang.Enum#compareTo(java.lang.Enum) 
      */
@@ -34,6 +41,11 @@
         assertTrue(0 < Sample.MOE.compareTo(Sample.LARRY));
         assertEquals(0, Sample.MOE.compareTo(Sample.MOE));
         assertTrue(0 > Sample.MOE.compareTo(Sample.CURLY));
+        try {
+            Sample.MOE.compareTo((Sample)null);
+        } catch (NullPointerException e) {
+            // Expected
+        }
     }
 
     /**
@@ -44,6 +56,7 @@
         assertTrue(moe.equals(Sample.MOE));
         assertFalse(Sample.LARRY.equals(Sample.CURLY));
         assertTrue(Sample.LARRY.equals(larry));
+        assertFalse(Sample.CURLY.equals(null));
     }
 
     /**
@@ -96,6 +109,42 @@
         } catch (IllegalArgumentException e){
             // Expected
         }
+        try {
+            Sample.valueOf(null);
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        Sample s = Enum.valueOf(Sample.class, "CURLY");
+        assertSame(s, Sample.CURLY);
+        s = Enum.valueOf(Sample.class, "LARRY");
+        assertSame(larry, s);
+        s = Enum.valueOf(Sample.class, "MOE");
+        assertSame(s, moe);
+        try {
+            Enum.valueOf(Bogus.class, "MOE");
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+        try {
+            Enum.valueOf((Class<Sample>)null, "a string");
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        try {
+            Enum.valueOf(Sample.class, null);
+            fail("Expected IllegalArgumentException");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        try {
+            Enum.valueOf((Class<Sample>)null, (String)null);
+            fail("Expected IllegalArgumentException");
+        } catch (NullPointerException e) {
+            // Expected
+        }
     }
 
     /**
@@ -108,5 +157,7 @@
         assertEquals(Sample.LARRY, myValues[0]);
         assertEquals(Sample.MOE, myValues[1]);
         assertEquals(Sample.CURLY, myValues[2]);
+        
+        assertEquals(0, Empty.values().length);
     }
 }



Mime
View raw message