You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2009/09/29 21:14:56 UTC

svn commit: r820071 - /commons/proper/lang/trunk/src/test/org/apache/commons/lang/concurrent/ConcurrentUtilsTest.java

Author: oheger
Date: Tue Sep 29 19:14:56 2009
New Revision: 820071

URL: http://svn.apache.org/viewvc?rev=820071&view=rev
Log:
[LANG-499] Test class for ConcurrentUtils

Added:
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/concurrent/ConcurrentUtilsTest.java   (with props)

Added: commons/proper/lang/trunk/src/test/org/apache/commons/lang/concurrent/ConcurrentUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/concurrent/ConcurrentUtilsTest.java?rev=820071&view=auto
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/concurrent/ConcurrentUtilsTest.java (added)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/concurrent/ConcurrentUtilsTest.java Tue Sep 29 19:14:56 2009
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang.concurrent;
+
+import java.util.concurrent.ExecutionException;
+
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link ConcurrentUtils}.
+ *
+ * @version $Id$
+ */
+public class ConcurrentUtilsTest extends TestCase {
+    /**
+     * Tests creating a ConcurrentException with a runtime exception as cause.
+     */
+    public void testConcurrentExceptionCauseUnchecked() {
+        try {
+            new ConcurrentException(new RuntimeException());
+            fail("Could create ConcurrentException with unchecked cause!");
+        } catch (IllegalArgumentException iex) {
+            // ok
+        }
+    }
+
+    /**
+     * Tests creating a ConcurrentException with an error as cause.
+     */
+    public void testConcurrentExceptionCauseError() {
+        try {
+            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.
+     */
+    public void testConcurrentExceptionCauseNull() {
+        try {
+            new ConcurrentException(null);
+            fail("Could create ConcurrentException with null cause!");
+        } catch (IllegalArgumentException iex) {
+            // ok
+        }
+    }
+
+    /**
+     * Tests extractCause() for a null exception.
+     */
+    public void testExtractCauseNull() {
+        assertNull("Non null result", ConcurrentUtils.extractCause(null));
+    }
+
+    /**
+     * Tests extractCause() if the cause of the passed in exception is null.
+     */
+    public void testExtractCauseNullCause() {
+        assertNull("Non null result", ConcurrentUtils
+                .extractCause(new ExecutionException("Test", null)));
+    }
+
+    /**
+     * Tests extractCause() if the cause is an error.
+     */
+    public void testExtractCauseError() {
+        Error err = new AssertionError("Test");
+        try {
+            ConcurrentUtils.extractCause(new ExecutionException(err));
+            fail("Error not thrown!");
+        } catch (Error e) {
+            assertEquals("Wrong error", err, e);
+        }
+    }
+
+    /**
+     * Tests extractCause() if the cause is an unchecked exception.
+     */
+    public void testExtractCauseUnchecked() {
+        RuntimeException rex = new RuntimeException("Test");
+        try {
+            ConcurrentUtils.extractCause(new ExecutionException(rex));
+            fail("Runtime exception not thrown!");
+        } catch (RuntimeException r) {
+            assertEquals("Wrong exception", rex, r);
+        }
+    }
+
+    /**
+     * Tests extractCause() if the cause is a checked exception.
+     */
+    public void testExtractCauseChecked() {
+        Exception ex = new Exception("Test");
+        ConcurrentException cex = ConcurrentUtils
+                .extractCause(new ExecutionException(ex));
+        assertSame("Wrong cause", ex, cex.getCause());
+    }
+
+    /**
+     * Tests handleCause() if the cause is an error.
+     */
+    public void testHandleCauseError() throws ConcurrentException {
+        Error err = new AssertionError("Test");
+        try {
+            ConcurrentUtils.handleCause(new ExecutionException(err));
+            fail("Error not thrown!");
+        } catch (Error e) {
+            assertEquals("Wrong error", err, e);
+        }
+    }
+
+    /**
+     * Tests handleCause() if the cause is an unchecked exception.
+     */
+    public void testHandleCauseUnchecked() throws ConcurrentException {
+        RuntimeException rex = new RuntimeException("Test");
+        try {
+            ConcurrentUtils.handleCause(new ExecutionException(rex));
+            fail("Runtime exception not thrown!");
+        } catch (RuntimeException r) {
+            assertEquals("Wrong exception", rex, r);
+        }
+    }
+
+    /**
+     * Tests handleCause() if the cause is a checked exception.
+     */
+    public void testHandleCauseChecked() throws ConcurrentException {
+        Exception ex = new Exception("Test");
+        try {
+            ConcurrentUtils.handleCause(new ExecutionException(ex));
+            fail("ConcurrentException not thrown!");
+        } catch (ConcurrentException cex) {
+            assertEquals("Wrong cause", ex, cex.getCause());
+        }
+    }
+
+    /**
+     * Tests handleCause() for a null parameter or a null cause. In this case
+     * the method should do nothing. We can only test that no exception is
+     * thrown.
+     */
+    public void testHandleCauseNull() throws ConcurrentException {
+        ConcurrentUtils.handleCause(null);
+        ConcurrentUtils.handleCause(new ExecutionException("Test", null));
+    }
+}

Propchange: commons/proper/lang/trunk/src/test/org/apache/commons/lang/concurrent/ConcurrentUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/lang/trunk/src/test/org/apache/commons/lang/concurrent/ConcurrentUtilsTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/lang/trunk/src/test/org/apache/commons/lang/concurrent/ConcurrentUtilsTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain