You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/08/24 06:05:17 UTC
svn commit: r434297 -
/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/
Author: ndbeyer
Date: Wed Aug 23 21:05:15 2006
New Revision: 434297
URL: http://svn.apache.org/viewvc?rev=434297&view=rev
Log:
Rework java.lang exception tests to assert the exceptions classes behavior, not the behavior that causes it.
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassCastExceptionTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassNotFoundExceptionTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CloneNotSupportedExceptionTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ErrorTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionInInitializerErrorTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessErrorTest.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessExceptionTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassCastExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassCastExceptionTest.java?rev=434297&r1=434296&r2=434297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassCastExceptionTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassCastExceptionTest.java Wed Aug 23 21:05:15 2006
@@ -15,57 +15,26 @@
package org.apache.harmony.luni.tests.java.lang;
-public class ClassCastExceptionTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
+
+public class ClassCastExceptionTest extends TestCase {
/**
* @tests java.lang.ClassCastException#ClassCastException()
*/
public void test_Constructor() {
- // Test for method java.lang.ClassCastException()
- try {
- try {
- String z = (String) new Object();
- if (z == null)
- ; // use z to avoid a warning msg
- } catch (ClassCastException e) {
- return;
- }
- fail("Failed to generate expected exception");
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
+ ClassCastException e = new ClassCastException();
+ assertNull(e.getMessage());
+ assertNull(e.getLocalizedMessage());
+ assertNull(e.getCause());
}
/**
* @tests java.lang.ClassCastException#ClassCastException(java.lang.String)
*/
public void test_ConstructorLjava_lang_String() {
- // Test for method java.lang.ClassCastException(java.lang.String)
- try {
- try {
- String z = (String) new Object();
- if (z == null)
- ; // use z to avoid a warning msg
- } catch (ClassCastException e) {
- return;
- }
- fail("Failed to generate expected exception");
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
+ ClassCastException e = new ClassCastException("fixture");
+ assertEquals("fixture", e.getMessage());
+ assertNull(e.getCause());
}
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassNotFoundExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassNotFoundExceptionTest.java?rev=434297&r1=434296&r2=434297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassNotFoundExceptionTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassNotFoundExceptionTest.java Wed Aug 23 21:05:15 2006
@@ -15,53 +15,26 @@
package org.apache.harmony.luni.tests.java.lang;
-public class ClassNotFoundExceptionTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
+
+public class ClassNotFoundExceptionTest extends TestCase {
/**
* @tests java.lang.ClassNotFoundException#ClassNotFoundException()
*/
public void test_Constructor() {
- // Test for method java.lang.ClassNotFoundException()
- try {
- try {
- Class.forName("zz.xx.ll.Wiggum");
- } catch (ClassNotFoundException e) {
- return;
- }
- fail("Failed to generate expected exception");
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
+ ClassNotFoundException e = new ClassNotFoundException();
+ assertNull(e.getMessage());
+ assertNull(e.getLocalizedMessage());
+ assertNull(e.getCause());
}
/**
* @tests java.lang.ClassNotFoundException#ClassNotFoundException(java.lang.String)
*/
public void test_ConstructorLjava_lang_String() {
- // Test for method java.lang.ClassNotFoundException(java.lang.String)
- try {
- try {
- Class.forName("zz.xx.ll.Wiggum");
- } catch (ClassNotFoundException e) {
- return;
- }
- fail("Failed to generate expected exception");
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
+ ClassNotFoundException e = new ClassNotFoundException("fixture");
+ assertEquals("fixture", e.getMessage());
+ assertNull(e.getCause());
}
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CloneNotSupportedExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CloneNotSupportedExceptionTest.java?rev=434297&r1=434296&r2=434297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CloneNotSupportedExceptionTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CloneNotSupportedExceptionTest.java Wed Aug 23 21:05:15 2006
@@ -15,58 +15,26 @@
package org.apache.harmony.luni.tests.java.lang;
-public class CloneNotSupportedExceptionTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
+
+public class CloneNotSupportedExceptionTest extends TestCase {
/**
* @tests java.lang.CloneNotSupportedException#CloneNotSupportedException()
*/
public void test_Constructor() {
- // Test for method java.lang.CloneNotSupportedException()
- class NoClone extends Object {
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
- }
- try {
- NoClone x = new NoClone();
- NoClone y = (NoClone) x.clone();
- } catch (CloneNotSupportedException e) {
- return;
- }
- fail("Failed to generate expected exception");
+ CloneNotSupportedException e = new CloneNotSupportedException();
+ assertNull(e.getMessage());
+ assertNull(e.getLocalizedMessage());
+ assertNull(e.getCause());
}
/**
* @tests java.lang.CloneNotSupportedException#CloneNotSupportedException(java.lang.String)
*/
public void test_ConstructorLjava_lang_String() {
- // Test for method
- // java.lang.CloneNotSupportedException(java.lang.String)
- class NoClone extends Object {
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
- }
- try {
- NoClone x = new NoClone();
- x.clone();
- } catch (CloneNotSupportedException e) {
- return;
- }
- fail("Failed to generate expected exception");
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
+ CloneNotSupportedException e = new CloneNotSupportedException("fixture");
+ assertEquals("fixture", e.getMessage());
+ assertNull(e.getCause());
}
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ErrorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ErrorTest.java?rev=434297&r1=434296&r2=434297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ErrorTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ErrorTest.java Wed Aug 23 21:05:15 2006
@@ -15,49 +15,26 @@
package org.apache.harmony.luni.tests.java.lang;
-public class ErrorTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
- /**
- * @tests java.lang.Error#Error()
- */
- public void test_Constructor() {
- // Test for method java.lang.Error()
- try {
- if (true)
- throw new Error();
- } catch (Error e) {
- return;
- }
- fail("Failed to generate Error");
- }
+public class ErrorTest extends TestCase {
/**
- * @tests java.lang.Error#Error(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.lang.Error(java.lang.String)
- try {
- if (true)
- throw new Error("Throw an Error");
- } catch (Error e) {
- assertEquals("Incorrect message string generated", "Throw an Error", e.getMessage()
- );
- return;
- }
- fail("Failed to generate Error");
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
+ * @tests java.lang.Error#Error()
*/
- protected void setUp() {
- }
+ public void test_Constructor() {
+ Error e = new Error();
+ assertNull(e.getMessage());
+ assertNull(e.getLocalizedMessage());
+ assertNull(e.getCause());
+ }
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
+ /**
+ * @tests java.lang.Error#Error(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ Error e = new Error("fixture");
+ assertEquals("fixture", e.getMessage());
+ assertNull(e.getCause());
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionInInitializerErrorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionInInitializerErrorTest.java?rev=434297&r1=434296&r2=434297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionInInitializerErrorTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionInInitializerErrorTest.java Wed Aug 23 21:05:15 2006
@@ -20,65 +20,32 @@
/**
* @tests java.lang.ExceptionInInitializerError#ExceptionInInitializerError()
*/
- public void test_Constructor() {
- try {
- if (true)
- throw new ExceptionInInitializerError();
- } catch (ExceptionInInitializerError e) {
- assertTrue("Initializer failed." + e.toString(), e.toString()
- .equals("java.lang.ExceptionInInitializerError"));
- assertNull("Initializer failed.", e.getException());
- assertNull("Initializer failed.", e.getMessage());
- return;
- }
- fail("Constructor failed.");
- }
+ public void test_Constructor() {
+ ExceptionInInitializerError e = new ExceptionInInitializerError();
+ assertNull(e.getMessage());
+ assertNull(e.getLocalizedMessage());
+ assertNull(e.getCause());
+ }
- /**
- * @tests java.lang.ExceptionInInitializerError#ExceptionInInitializerError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) {
- throw new ExceptionInInitializerError("HelloWorld");
- }
- fail("Constructor failed.");
- } catch (ExceptionInInitializerError e) {
- assertTrue("Initializer failed: " + e.getMessage(), e.getMessage()
- .equals("HelloWorld"));
- }
- }
+ /**
+ * @tests java.lang.ExceptionInInitializerError#ExceptionInInitializerError(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ ExceptionInInitializerError e = new ExceptionInInitializerError("fixture");
+ assertEquals("fixture", e.getMessage());
+ assertNull(e.getCause());
+ }
/**
- * @tests java.lang.ExceptionInInitializerError#ExceptionInInitializerError(java.lang.Throwable)
+ * @tests java.lang.ExceptionInInitializerExceptionInInitializerError#ExceptionInInitializerError(java.lang.Throwable)
*/
public void test_ConstructorLjava_lang_Throwable() {
- try {
- if (true) {
- throw new ExceptionInInitializerError(
- new ExceptionInInitializerError("HelloWorld"));
- }
- fail("Constructor failed.");
- } catch (ExceptionInInitializerError e) {
- assertNull("Initializer failed." + e.getMessage(),
- e.getMessage());
- assertTrue("Initializer failed." + e.toString(),
- e.getException() != null
- && e.getException().getMessage().equals(
- "HelloWorld"));
- }
+ NullPointerException npe = new NullPointerException("fixture");
+ ExceptionInInitializerError e = new ExceptionInInitializerError(npe);
+ assertNull(e.getMessage());
+ assertNull(e.getLocalizedMessage());
+ assertSame(npe, e.getException());
+ assertSame(npe, e.getCause());
}
- /**
- * @tests java.lang.ExceptionInInitializerError#getException()
- */
- public void test_getException() {
- assertTrue("Already tested.", true);
- }
-
- protected void setUp() {
- }
-
- protected void tearDown() {
- }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionTest.java?rev=434297&r1=434296&r2=434297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionTest.java Wed Aug 23 21:05:15 2006
@@ -15,49 +15,26 @@
package org.apache.harmony.luni.tests.java.lang;
-public class ExceptionTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
- /**
- * @tests java.lang.Exception#Exception()
- */
- public void test_Constructor() {
- // Test for method java.lang.Exception()
- try {
- if (true)
- throw new Exception();
- } catch (Exception e) {
- return;
- }
- fail("Failed to generate Error");
- }
+public class ExceptionTest extends TestCase {
/**
- * @tests java.lang.Exception#Exception(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.lang.Exception(java.lang.String)
- try {
- if (true)
- throw new Exception("Throw an Error");
- } catch (Exception e) {
- assertEquals("Incorrect message string generated", "Throw an Error", e.getMessage()
- );
- return;
- }
- fail("Failed to generate Error");
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
+ * @tests java.lang.Exception#Exception()
*/
- protected void setUp() {
- }
+ public void test_Constructor() {
+ Exception e = new Exception();
+ assertNull(e.getMessage());
+ assertNull(e.getLocalizedMessage());
+ assertNull(e.getCause());
+ }
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
+ /**
+ * @tests java.lang.Exception#Exception(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ Exception e = new Exception("fixture");
+ assertEquals("fixture", e.getMessage());
+ assertNull(e.getCause());
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessErrorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessErrorTest.java?rev=434297&r1=434296&r2=434297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessErrorTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessErrorTest.java Wed Aug 23 21:05:15 2006
@@ -15,47 +15,26 @@
package org.apache.harmony.luni.tests.java.lang;
-public class IllegalAccessErrorTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
- /**
- * @tests java.lang.IllegalAccessError#IllegalAccessError()
- */
- public void test_Constructor() {
- try {
- if (true) {
- throw new IllegalAccessError();
- }
- fail("IllegalAccessError not thrown.");
- } catch (IllegalAccessError e) {
- assertTrue("Initializer failed." + e.toString(), e.toString()
- .equals("java.lang.IllegalAccessError"));
- } catch (Exception e) {
- fail("Exception in test : " + e.getMessage());
- }
- }
+public class IllegalAccessErrorTest extends TestCase {
/**
- * @tests java.lang.IllegalAccessError#IllegalAccessError(java.lang.String)
+ * @tests java.lang.IllegalAccessError#IllegalAccessError()
*/
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true)
- throw new IllegalAccessError("hello world.");
- } catch (IllegalAccessError e) {
- assertTrue("Wrong toString displayed." + e.toString(), e.toString()
- .equals("java.lang.IllegalAccessError: hello world."));
- assertTrue("Wrong message displayed." + e.getMessage(), e
- .getMessage().equals("hello world."));
- return;
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
- fail("Error not thrown.");
- }
-
- protected void setUp() {
- }
+ public void test_Constructor() {
+ IllegalAccessError e = new IllegalAccessError();
+ assertNull(e.getMessage());
+ assertNull(e.getLocalizedMessage());
+ assertNull(e.getCause());
+ }
- protected void tearDown() {
- }
+ /**
+ * @tests java.lang.IllegalAccessError#IllegalAccessError(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ IllegalAccessError e = new IllegalAccessError("fixture");
+ assertEquals("fixture", e.getMessage());
+ assertNull(e.getCause());
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessExceptionTest.java?rev=434297&r1=434296&r2=434297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessExceptionTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessExceptionTest.java Wed Aug 23 21:05:15 2006
@@ -15,66 +15,26 @@
package org.apache.harmony.luni.tests.java.lang;
-public class IllegalAccessExceptionTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
- static class PClass {
- int t;
-
- private PClass() {
- }
- }
-
- static int x;
+public class IllegalAccessExceptionTest extends TestCase {
/**
* @tests java.lang.IllegalAccessException#IllegalAccessException()
*/
- public void test_Constructor() {
- // Test for method java.lang.IllegalAccessException()
- try {
- try {
- Class cl = null;
- cl = Class.forName(getClass().getName() + "$PClass");
- cl.newInstance();
- } catch (IllegalAccessException e) {
- return;
- }
- fail("Failed to generate Exception");
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.lang.IllegalAccessException#IllegalAccessException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.lang.IllegalAccessException(java.lang.String)
- try {
- try {
- Class cl = null;
- cl = Class.forName(getClass().getName() + "$PClass");
- cl.newInstance();
- } catch (IllegalAccessException e) {
- return;
- }
- fail("Failed to generate Exception");
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
+ public void test_Constructor() {
+ IllegalAccessException e = new IllegalAccessException();
+ assertNull(e.getMessage());
+ assertNull(e.getLocalizedMessage());
+ assertNull(e.getCause());
+ }
+
+ /**
+ * @tests java.lang.IllegalAccessException#IllegalAccessException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ IllegalAccessException e = new IllegalAccessException("fixture");
+ assertEquals("fixture", e.getMessage());
+ assertNull(e.getCause());
+ }
}