harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r437186 - /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/
Date Sat, 26 Aug 2006 17:22:15 GMT
Author: ndbeyer
Date: Sat Aug 26 10:22:13 2006
New Revision: 437186

URL: http://svn.apache.org/viewvc?rev=437186&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/ThrowableTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnknownErrorTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsatisfiedLinkErrorTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsupportedOperationExceptionTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VerifyErrorTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VirtualMachineErrorTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThrowableTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThrowableTest.java?rev=437186&r1=437185&r2=437186&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThrowableTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThrowableTest.java
Sat Aug 26 10:22:13 2006
@@ -120,17 +120,6 @@
 	}
 
 	/**
-	 * @tests java.lang.Throwable#getMessage()
-	 */
-	public void test_getMessage() {
-		// Test for method java.lang.String java.lang.Throwable.getMessage()
-
-		Throwable x = new ClassNotFoundException("A Message");
-		assertEquals("Returned incorrect messasge string", 
-				"A Message", x.getMessage());
-	}
-
-	/**
 	 * @tests java.lang.Throwable#printStackTrace()
 	 */
 	public void test_printStackTrace() {
@@ -185,15 +174,8 @@
 	 * @tests java.lang.Throwable#toString()
 	 */
 	public void test_toString() {
-		// Test for method java.lang.String java.lang.Throwable.toString()
-		try {
-			if (true)
-				throw new Throwable("Throw");
-		} catch (Throwable e) {
-			assertEquals("Threw Throwable with incorrect string", "java.lang.Throwable: Throw", e.toString()
-					);
-			return;
-		}
-		fail("Failed to throw Throwable");
-	}
+        Throwable e = new Throwable("Throw");
+        assertEquals("java.lang.Throwable: Throw", e.toString());
+
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnknownErrorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnknownErrorTest.java?rev=437186&r1=437185&r2=437186&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnknownErrorTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnknownErrorTest.java
Sat Aug 26 10:22:13 2006
@@ -15,49 +15,26 @@
 
 package org.apache.harmony.luni.tests.java.lang;
 
-public class UnknownErrorTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
 
-	/**
-	 * @tests java.lang.UnknownError#UnknownError()
-	 */
-	public void test_Constructor() {
-		// Test for method java.lang.UnknownError()
-		try {
-			if (true)
-				throw new UnknownError();
-		} catch (UnknownError e) {
-			return;
-		}
-		fail("Failed to generate error");
-	}
+public class UnknownErrorTest extends TestCase {
 
 	/**
-	 * @tests java.lang.UnknownError#UnknownError(java.lang.String)
-	 */
-	public void test_ConstructorLjava_lang_String() {
-		// Test for method java.lang.UnknownError(java.lang.String)
-		try {
-			if (true)
-				throw new UnknownError("Unknown");
-		} catch (UnknownError e) {
-			assertEquals(" Incorrect msg string ", 
-					"Unknown", 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.UnknownError#UnknownError()
 	 */
-	protected void setUp() {
-	}
+    public void test_Constructor() {
+        UnknownError e = new UnknownError();
+        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.UnknownError#UnknownError(java.lang.String)
+     */
+    public void test_ConstructorLjava_lang_String() {
+        UnknownError e = new UnknownError("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/UnsatisfiedLinkErrorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsatisfiedLinkErrorTest.java?rev=437186&r1=437185&r2=437186&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsatisfiedLinkErrorTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsatisfiedLinkErrorTest.java
Sat Aug 26 10:22:13 2006
@@ -15,44 +15,26 @@
 
 package org.apache.harmony.luni.tests.java.lang;
 
-public class UnsatisfiedLinkErrorTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
 
-	/**
-	 * @tests java.lang.UnsatisfiedLinkError#UnsatisfiedLinkError()
-	 */
-	public void test_Constructor() {
-		// SM.
-		try {
-			if (true)
-				throw new UnsatisfiedLinkError();
-		} catch (UnsatisfiedLinkError e) {
-			assertNull("Initializer failed.", e.getMessage());
-			assertEquals("To string failed.", 
-					"java.lang.UnsatisfiedLinkError", e.toString());
-		}
-	}
+public class UnsatisfiedLinkErrorTest extends TestCase {
 
 	/**
-	 * @tests java.lang.UnsatisfiedLinkError#UnsatisfiedLinkError(java.lang.String)
+	 * @tests java.lang.UnsatisfiedLinkError#UnsatisfiedLinkError()
 	 */
-	public void test_ConstructorLjava_lang_String() {
-		// TODO : No method throws this error.
-		boolean exception = false;
-		try {
-			Runtime.getRuntime().loadLibrary("Hello World89797");
-		} catch (UnsatisfiedLinkError e) {
-			assertNotNull("Does not set message", e.getMessage());
-			exception = true;
-		}
-		assertTrue("Does not throw UnsatisfiedLinkError", exception);
-
-		UnsatisfiedLinkError err = new UnsatisfiedLinkError("my message");
-		assertEquals("Incorrect message", "my message", err.getMessage());
-	}
-
-	protected void setUp() {
-	}
+    public void test_Constructor() {
+        UnsatisfiedLinkError e = new UnsatisfiedLinkError();
+        assertNull(e.getMessage());
+        assertNull(e.getLocalizedMessage());
+        assertNull(e.getCause());
+    }
 
-	protected void tearDown() {
-	}
+    /**
+     * @tests java.lang.UnsatisfiedLinkError#UnsatisfiedLinkError(java.lang.String)
+     */
+    public void test_ConstructorLjava_lang_String() {
+        UnsatisfiedLinkError e = new UnsatisfiedLinkError("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/UnsupportedOperationExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsupportedOperationExceptionTest.java?rev=437186&r1=437185&r2=437186&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsupportedOperationExceptionTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsupportedOperationExceptionTest.java
Sat Aug 26 10:22:13 2006
@@ -15,12 +15,10 @@
 
 package org.apache.harmony.luni.tests.java.lang;
 
-import java.util.AbstractCollection;
-import java.util.Iterator;
-
+import junit.framework.TestCase;
 import tests.util.SerializationTester;
 
-public class UnsupportedOperationExceptionTest extends junit.framework.TestCase {
+public class UnsupportedOperationExceptionTest extends TestCase {
 
 	private static final String SERIALIZATION_FILE_NAME =
 		"serialization/java/lang/UnsupportedOperationException.ser"; //$NON-NLS-1$
@@ -28,46 +26,21 @@
 	/**
 	 * @tests java.lang.UnsupportedOperationException#UnsupportedOperationException()
 	 */
-	public void test_Constructor() {
-		// Test for method java.lang.UnsupportedOperationException()
-		class UnsupportedCollection extends AbstractCollection {
-			public int size() {
-				return 0;
-			}
-
-			public Iterator iterator() {
-				return null;
-			}
-		}
-		try {
-			UnsupportedCollection uc = new UnsupportedCollection();
-			uc.add(new Object());
-		} catch (UnsupportedOperationException e) {
-			return;
-		} catch (Exception e) {
-			fail("Exception during Constructor : " + e.getMessage());
-		}
-		fail("Constructor failed.");
-	}
-
-	/**
-	 * @tests java.lang.UnsupportedOperationException#UnsupportedOperationException(java.lang.String)
-	 */
-	public void test_ConstructorLjava_lang_String() {
-		// Test for method
-		// java.lang.UnsupportedOperationException(java.lang.String)
-		try {
-			throw new UnsupportedOperationException("HelloWorld");
-		} catch (UnsupportedOperationException e) {
-			assertEquals("Wrong message given.", 
-					"HelloWorld", e.getMessage());
-			return;
-		} catch (Exception e) {
-			fail("Exception during Constructor : " + e.getMessage());
-		}
-		fail("Constructor failed");
-	}
-	
+    public void test_Constructor() {
+        UnsupportedOperationException e = new UnsupportedOperationException();
+        assertNull(e.getMessage());
+        assertNull(e.getLocalizedMessage());
+        assertNull(e.getCause());
+    }
+
+    /**
+     * @tests java.lang.UnsupportedOperationException#UnsupportedOperationException(java.lang.String)
+     */
+    public void test_ConstructorLjava_lang_String() {
+        UnsupportedOperationException e = new UnsupportedOperationException("fixture");
+        assertEquals("fixture", e.getMessage());
+        assertNull(e.getCause());
+    }
 	
 	/**
 	 * @tests serialization/deserilazation.
@@ -86,19 +59,5 @@
 		UnsupportedOperationException destUnsupportedOperationException = (UnsupportedOperationException)
SerializationTester
 				.readObject(srcUnsupportedOperationException,
 						SERIALIZATION_FILE_NAME);
-	}
-
-	/**
-	 * 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() {
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VerifyErrorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VerifyErrorTest.java?rev=437186&r1=437185&r2=437186&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VerifyErrorTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VerifyErrorTest.java
Sat Aug 26 10:22:13 2006
@@ -15,39 +15,26 @@
 
 package org.apache.harmony.luni.tests.java.lang;
 
-public class VerifyErrorTest extends junit.framework.TestCase {
+import junit.framework.TestCase;
 
-	/**
-	 * @tests java.lang.VerifyError#VerifyError()
-	 */
-	public void test_Constructor() {
-		try {
-			if (true)
-				throw new VerifyError();
-		} catch (VerifyError e) {
-			return;
-		}
-		fail("Constructor failed");
-	}
+public class VerifyErrorTest extends TestCase {
 
 	/**
-	 * @tests java.lang.VerifyError#VerifyError(java.lang.String)
+	 * @tests java.lang.VerifyError#VerifyError()
 	 */
-	public void test_ConstructorLjava_lang_String() {
-		try {
-			if (true)
-				throw new VerifyError("HelloWorld");
-		} catch (VerifyError e) {
-			assertEquals("VerifyError(String) failed.", 
-					"HelloWorld", e.getMessage());
-			return;
-		}
-		fail("Constructor failed");
-	}
-
-	protected void setUp() {
-	}
+    public void test_Constructor() {
+        VerifyError e = new VerifyError();
+        assertNull(e.getMessage());
+        assertNull(e.getLocalizedMessage());
+        assertNull(e.getCause());
+    }
 
-	protected void tearDown() {
-	}
+    /**
+     * @tests java.lang.VerifyError#VerifyError(java.lang.String)
+     */
+    public void test_ConstructorLjava_lang_String() {
+        VerifyError e = new VerifyError("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/VirtualMachineErrorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VirtualMachineErrorTest.java?rev=437186&r1=437185&r2=437186&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VirtualMachineErrorTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VirtualMachineErrorTest.java
Sat Aug 26 10:22:13 2006
@@ -12,63 +12,30 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.harmony.luni.tests.java.lang;
 
-public class VirtualMachineErrorTest extends junit.framework.TestCase {
+package org.apache.harmony.luni.tests.java.lang;
 
-	public class TestVirtualMachineError extends VirtualMachineError {
-		public TestVirtualMachineError() {
-			super();
-		}
+import junit.framework.TestCase;
 
-		public TestVirtualMachineError(String detailMessage) {
-			super(detailMessage);
-		}
-	}
+@SuppressWarnings("serial")
+public class VirtualMachineErrorTest extends TestCase {
 
 	/**
 	 * @tests java.lang.VirtualMachineError#VirtualMachineError()
 	 */
-	public void test_Constructor() {
-		// Test for method java.lang.VirtualMachineError()
-		// Tested more via subclasses (i.e. StackOverFlowError).
-		try {
-			if (true)
-				throw new TestVirtualMachineError();
-		} catch (VirtualMachineError e) {
-			return;
-		}
-		fail("Constructor failed");
-	}
-
-	/**
-	 * @tests java.lang.VirtualMachineError#VirtualMachineError(java.lang.String)
-	 */
-	public void test_ConstructorLjava_lang_String() {
-		// Test for method java.lang.VirtualMachineError(java.lang.String)
-		// Tested more via subclasses (i.e. StackOverFlowError).
-		try {
-			if (true)
-				throw new TestVirtualMachineError("HelloWorld");
-		} catch (VirtualMachineError e) {
-			assertEquals("VerifyError(String) failed.", 
-					"HelloWorld", e.getMessage());
-			return;
-		}
-		fail("Constructor failed");
-	}
-
-	/**
-	 * 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() {
+        VirtualMachineError e = new VirtualMachineError() {};
+        assertNull(e.getMessage());
+        assertNull(e.getLocalizedMessage());
+        assertNull(e.getCause());
+    }
+
+    /**
+     * @tests java.lang.VirtualMachineError#VirtualMachineError(java.lang.String)
+     */
+    public void test_ConstructorLjava_lang_String() {
+        VirtualMachineError e = new VirtualMachineError("fixture") {};
+        assertEquals("fixture", e.getMessage());
+        assertNull(e.getCause());
+    }
 }



Mime
View raw message