harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qi...@apache.org
Subject svn commit: r707523 - in /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/reflect: ConstructorTest.java MethodTest.java
Date Fri, 24 Oct 2008 01:36:16 GMT
Author: qiuxx
Date: Thu Oct 23 18:36:16 2008
New Revision: 707523

URL: http://svn.apache.org/viewvc?rev=707523&view=rev
Log:
Apply patch for HARMONY-5999, (Add Test Case for java.lang.reflect.Constructor and java.lang.reflect.Method)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/reflect/ConstructorTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/reflect/MethodTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/reflect/ConstructorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/reflect/ConstructorTest.java?rev=707523&r1=707522&r2=707523&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/reflect/ConstructorTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/reflect/ConstructorTest.java
Thu Oct 23 18:36:16 2008
@@ -18,7 +18,9 @@
 package org.apache.harmony.luni.tests.java.lang.reflect;
 
 import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Modifier;
+import java.util.Vector;
 
 public class ConstructorTest extends junit.framework.TestCase {
 
@@ -175,6 +177,78 @@
 
         assertEquals("improper instance created", 99, test.check());
     }
+    
+    /**
+     * @tests java.lang.reflect.Constructor#newInstance(java.lang.Object[])
+     */
+    public void test_newInstance_IAE() throws Exception {
+        Constructor constructor = Vector.class
+                .getConstructor(new Class[] { Integer.TYPE });
+
+        try {
+            constructor.newInstance(new Object[] { null });
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+    }
+    
+    public void test_newInstance_InvocationTargetException() throws Exception {
+        Constructor constructor = MockObject.class.getConstructor(Class.class);
+
+        try {
+            constructor.newInstance(InvocationTargetException.class);
+            fail("should throw InvocationTargetException");
+        } catch (InvocationTargetException e) {
+            // Expected
+        }
+
+        try {
+            constructor.newInstance(IllegalAccessException.class);
+            fail("should throw InvocationTargetException");
+        } catch (InvocationTargetException e) {
+            // Expected
+        }
+
+        try {
+            constructor.newInstance(IllegalArgumentException.class);
+            fail("should throw InvocationTargetException");
+        } catch (InvocationTargetException e) {
+            // Expected
+        }
+
+        try {
+            constructor.newInstance(InvocationTargetException.class);
+            fail("should throw InvocationTargetException");
+        } catch (InvocationTargetException e) {
+            // Expected
+        }
+        
+        try {
+            constructor.newInstance(Throwable.class);
+            fail("should throw InvocationTargetException");
+        } catch (InvocationTargetException e) {
+            // Expected
+        }
+    }
+
+    static class MockObject {
+
+        public MockObject(Class<?> clazz) throws Exception {
+            if (clazz == InstantiationException.class) {
+                throw new InstantiationException();
+            } else if (clazz == IllegalAccessException.class) {
+                throw new IllegalAccessException();
+            } else if (clazz == IllegalArgumentException.class) {
+                throw new IllegalArgumentException();
+            } else if (clazz == InvocationTargetException.class) {
+                throw new InvocationTargetException(new Throwable());
+            } else {
+                throw new Exception();
+            }
+        }
+
+    }
 
     /**
      * @tests java.lang.reflect.Constructor#toString()

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/reflect/MethodTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/reflect/MethodTest.java?rev=707523&r1=707522&r2=707523&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/reflect/MethodTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/reflect/MethodTest.java
Thu Oct 23 18:36:16 2008
@@ -394,7 +394,15 @@
 			ret = mth.invoke(new TestMethod(), new Object[0]);
 		} catch (InvocationTargetException e) {
 			// Correct behaviour
-		} 
+		}
+		
+		mth = String.class.getMethod("valueOf", new Class[] { Integer.TYPE });
+        try {
+            mth.invoke(String.class, new Object[] { null });
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
 
 		TestMethod testMethod = new TestMethod();
 		Method methods[] = cl.getMethods();
@@ -533,6 +541,63 @@
 			}
 		}
 	}
+	
+	public void test_invoke_InvocationTargetException() throws Exception {
+        Method method = MockObject.class.getDeclaredMethod("mockMethod", Class.class);
+        MockObject mockObject = new MockObject();
+        
+        try {
+            method.invoke(mockObject, InvocationTargetException.class);
+            fail("should throw InvocationTargetException");
+        } catch (InvocationTargetException e) {
+            // Expected
+        }
+
+        try {
+            method.invoke(mockObject, IllegalAccessException.class);
+            fail("should throw InvocationTargetException");
+        } catch (InvocationTargetException e) {
+            // Expected
+        }
+
+        try {
+            method.invoke(mockObject, IllegalArgumentException.class);
+            fail("should throw InvocationTargetException");
+        } catch (InvocationTargetException e) {
+            // Expected
+        }
+
+        try {
+            method.invoke(mockObject, InvocationTargetException.class);
+            fail("should throw InvocationTargetException");
+        } catch (InvocationTargetException e) {
+            // Expected
+        }
+        
+        try {
+            method.invoke(mockObject, Throwable.class);
+            fail("should throw InvocationTargetException");
+        } catch (InvocationTargetException e) {
+            // Expected
+        }
+    }
+
+    static class MockObject {
+
+        public void mockMethod (Class<?> clazz) throws Exception {
+            if (clazz == InstantiationException.class) {
+                throw new InstantiationException();
+            } else if (clazz == IllegalAccessException.class) {
+                throw new IllegalAccessException();
+            } else if (clazz == IllegalArgumentException.class) {
+                throw new IllegalArgumentException();
+            } else if (clazz == InvocationTargetException.class) {
+                throw new InvocationTargetException(new Throwable());
+            } else {
+                throw new Exception();
+            }
+        }
+    }
 
 	/**
 	 * @tests java.lang.reflect.Method#toString()



Mime
View raw message