Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 22263 invoked from network); 29 Sep 2009 19:15:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Sep 2009 19:15:22 -0000 Received: (qmail 24803 invoked by uid 500); 29 Sep 2009 19:15:21 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 24723 invoked by uid 500); 29 Sep 2009 19:15:21 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 24709 invoked by uid 99); 29 Sep 2009 19:15:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Sep 2009 19:15:21 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Sep 2009 19:15:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BD8FC23888E2; Tue, 29 Sep 2009 19:14:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r820071 - /commons/proper/lang/trunk/src/test/org/apache/commons/lang/concurrent/ConcurrentUtilsTest.java Date: Tue, 29 Sep 2009 19:14:56 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090929191456.BD8FC23888E2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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