Switched test class to jUnit 4 style.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@925419 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oliver Heger 2010-03-19 21:08:06 +00:00
parent 53d9ad9ffb
commit cfff2579f5
1 changed files with 24 additions and 20 deletions

View File

@ -16,57 +16,51 @@
*/ */
package org.apache.commons.lang3.concurrent; package org.apache.commons.lang3.concurrent;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import junit.framework.TestCase; import org.junit.Test;
/** /**
* Test class for {@link ConcurrentUtils}. * Test class for {@link ConcurrentUtils}.
* *
* @version $Id$ * @version $Id$
*/ */
public class ConcurrentUtilsTest extends TestCase { public class ConcurrentUtilsTest {
/** /**
* Tests creating a ConcurrentException with a runtime exception as cause. * Tests creating a ConcurrentException with a runtime exception as cause.
*/ */
@Test(expected = IllegalArgumentException.class)
public void testConcurrentExceptionCauseUnchecked() { public void testConcurrentExceptionCauseUnchecked() {
try { new ConcurrentException(new RuntimeException());
new ConcurrentException(new RuntimeException());
fail("Could create ConcurrentException with unchecked cause!");
} catch (IllegalArgumentException iex) {
// ok
}
} }
/** /**
* Tests creating a ConcurrentException with an error as cause. * Tests creating a ConcurrentException with an error as cause.
*/ */
@Test(expected = IllegalArgumentException.class)
public void testConcurrentExceptionCauseError() { public void testConcurrentExceptionCauseError() {
try { new ConcurrentException("An error", new Error());
new ConcurrentException("An error", new Error());
fail("Could create ConcurrentException with an error cause!");
} catch (IllegalArgumentException iex) {
// ok
}
} }
/** /**
* Tests creating a ConcurrentException with null as cause. * Tests creating a ConcurrentException with null as cause.
*/ */
@Test(expected = IllegalArgumentException.class)
public void testConcurrentExceptionCauseNull() { public void testConcurrentExceptionCauseNull() {
try { new ConcurrentException(null);
new ConcurrentException(null);
fail("Could create ConcurrentException with null cause!");
} catch (IllegalArgumentException iex) {
// ok
}
} }
/** /**
* Tests extractCause() for a null exception. * Tests extractCause() for a null exception.
*/ */
@Test
public void testExtractCauseNull() { public void testExtractCauseNull() {
assertNull("Non null result", ConcurrentUtils.extractCause(null)); assertNull("Non null result", ConcurrentUtils.extractCause(null));
} }
@ -74,6 +68,7 @@ public class ConcurrentUtilsTest extends TestCase {
/** /**
* Tests extractCause() if the cause of the passed in exception is null. * Tests extractCause() if the cause of the passed in exception is null.
*/ */
@Test
public void testExtractCauseNullCause() { public void testExtractCauseNullCause() {
assertNull("Non null result", ConcurrentUtils assertNull("Non null result", ConcurrentUtils
.extractCause(new ExecutionException("Test", null))); .extractCause(new ExecutionException("Test", null)));
@ -82,6 +77,7 @@ public class ConcurrentUtilsTest extends TestCase {
/** /**
* Tests extractCause() if the cause is an error. * Tests extractCause() if the cause is an error.
*/ */
@Test
public void testExtractCauseError() { public void testExtractCauseError() {
Error err = new AssertionError("Test"); Error err = new AssertionError("Test");
try { try {
@ -95,6 +91,7 @@ public class ConcurrentUtilsTest extends TestCase {
/** /**
* Tests extractCause() if the cause is an unchecked exception. * Tests extractCause() if the cause is an unchecked exception.
*/ */
@Test
public void testExtractCauseUnchecked() { public void testExtractCauseUnchecked() {
RuntimeException rex = new RuntimeException("Test"); RuntimeException rex = new RuntimeException("Test");
try { try {
@ -108,6 +105,7 @@ public class ConcurrentUtilsTest extends TestCase {
/** /**
* Tests extractCause() if the cause is a checked exception. * Tests extractCause() if the cause is a checked exception.
*/ */
@Test
public void testExtractCauseChecked() { public void testExtractCauseChecked() {
Exception ex = new Exception("Test"); Exception ex = new Exception("Test");
ConcurrentException cex = ConcurrentUtils ConcurrentException cex = ConcurrentUtils
@ -118,6 +116,7 @@ public class ConcurrentUtilsTest extends TestCase {
/** /**
* Tests handleCause() if the cause is an error. * Tests handleCause() if the cause is an error.
*/ */
@Test
public void testHandleCauseError() throws ConcurrentException { public void testHandleCauseError() throws ConcurrentException {
Error err = new AssertionError("Test"); Error err = new AssertionError("Test");
try { try {
@ -131,6 +130,7 @@ public class ConcurrentUtilsTest extends TestCase {
/** /**
* Tests handleCause() if the cause is an unchecked exception. * Tests handleCause() if the cause is an unchecked exception.
*/ */
@Test
public void testHandleCauseUnchecked() throws ConcurrentException { public void testHandleCauseUnchecked() throws ConcurrentException {
RuntimeException rex = new RuntimeException("Test"); RuntimeException rex = new RuntimeException("Test");
try { try {
@ -144,6 +144,7 @@ public class ConcurrentUtilsTest extends TestCase {
/** /**
* Tests handleCause() if the cause is a checked exception. * Tests handleCause() if the cause is a checked exception.
*/ */
@Test
public void testHandleCauseChecked() { public void testHandleCauseChecked() {
Exception ex = new Exception("Test"); Exception ex = new Exception("Test");
try { try {
@ -159,6 +160,7 @@ public class ConcurrentUtilsTest extends TestCase {
* the method should do nothing. We can only test that no exception is * the method should do nothing. We can only test that no exception is
* thrown. * thrown.
*/ */
@Test
public void testHandleCauseNull() throws ConcurrentException { public void testHandleCauseNull() throws ConcurrentException {
ConcurrentUtils.handleCause(null); ConcurrentUtils.handleCause(null);
ConcurrentUtils.handleCause(new ExecutionException("Test", null)); ConcurrentUtils.handleCause(new ExecutionException("Test", null));
@ -168,6 +170,7 @@ public class ConcurrentUtilsTest extends TestCase {
/** /**
* Tests constant future. * Tests constant future.
*/ */
@Test
public void testConstantFuture_Integer() throws Exception { public void testConstantFuture_Integer() throws Exception {
Integer value = new Integer(5); Integer value = new Integer(5);
Future<Integer> test = ConcurrentUtils.constantFuture(value); Future<Integer> test = ConcurrentUtils.constantFuture(value);
@ -183,6 +186,7 @@ public class ConcurrentUtilsTest extends TestCase {
/** /**
* Tests constant future. * Tests constant future.
*/ */
@Test
public void testConstantFuture_null() throws Exception { public void testConstantFuture_null() throws Exception {
Integer value = null; Integer value = null;
Future<Integer> test = ConcurrentUtils.constantFuture(value); Future<Integer> test = ConcurrentUtils.constantFuture(value);