|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| AbstractExceptionTestCase.java | - | 88% | 100% | 88.9% |
|
||||||||||||||
| 1 |
/* ====================================================================
|
|
| 2 |
The Jicarilla Software License
|
|
| 3 |
|
|
| 4 |
Copyright (c) 2003 Leo Simons.
|
|
| 5 |
All rights reserved.
|
|
| 6 |
|
|
| 7 |
Permission is hereby granted, free of charge, to any person obtaining
|
|
| 8 |
a copy of this software and associated documentation files (the
|
|
| 9 |
"Software"), to deal in the Software without restriction, including
|
|
| 10 |
without limitation the rights to use, copy, modify, merge, publish,
|
|
| 11 |
distribute, sublicense, and/or sell copies of the Software, and to
|
|
| 12 |
permit persons to whom the Software is furnished to do so, subject to
|
|
| 13 |
the following conditions:
|
|
| 14 |
|
|
| 15 |
The above copyright notice and this permission notice shall be
|
|
| 16 |
included in all copies or substantial portions of the Software.
|
|
| 17 |
|
|
| 18 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
| 19 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
| 20 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
| 21 |
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
| 22 |
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
| 23 |
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
| 24 |
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
| 25 |
==================================================================== */
|
|
| 26 |
package org.jicarilla.container.test;
|
|
| 27 |
|
|
| 28 |
import junit.framework.TestCase;
|
|
| 29 |
|
|
| 30 |
/**
|
|
| 31 |
* <a href="http://www.junit.org/">JUnit</a> {@link junit.framework.TestCase
|
|
| 32 |
* testcase} for all exceptions.
|
|
| 33 |
*
|
|
| 34 |
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
|
|
| 35 |
* @version $Id: AbstractExceptionTestCase.java,v 1.2 2004/01/10 16:04:50 lsimons Exp $
|
|
| 36 |
*/
|
|
| 37 |
public abstract class AbstractExceptionTestCase extends TestCase |
|
| 38 |
{
|
|
| 39 |
protected abstract Throwable getInstance();
|
|
| 40 |
protected abstract Throwable getInstance( String message );
|
|
| 41 |
protected abstract Throwable getInstance( Throwable t );
|
|
| 42 |
protected abstract Throwable getInstance( String message,
|
|
| 43 |
Throwable cause ); |
|
| 44 |
|
|
| 45 | 7 |
public void testConstructor() |
| 46 |
{
|
|
| 47 | 7 |
assertNotNull( |
| 48 |
getInstance( "msg", new RuntimeException() ) ); |
|
| 49 |
|
|
| 50 | 7 |
try
|
| 51 |
{
|
|
| 52 | 7 |
assertNotNull( getInstance( null, null ) ); |
| 53 | 0 |
fail( "Expected an exception!" );
|
| 54 |
} |
|
| 55 |
catch( NullPointerException th )
|
|
| 56 |
{}
|
|
| 57 |
|
|
| 58 | 7 |
try
|
| 59 |
{
|
|
| 60 | 7 |
assertNotNull( getInstance( "msg", null ) ); |
| 61 | 0 |
fail( "Expected an exception!" );
|
| 62 |
} |
|
| 63 |
catch( NullPointerException th )
|
|
| 64 |
{}
|
|
| 65 |
|
|
| 66 | 7 |
try
|
| 67 |
{
|
|
| 68 | 7 |
assertNotNull( getInstance( null, new RuntimeException() ) ); |
| 69 | 0 |
fail( "Expected an exception!" );
|
| 70 |
} |
|
| 71 |
catch( NullPointerException th )
|
|
| 72 |
{}
|
|
| 73 |
|
|
| 74 | 7 |
assertNotNull( |
| 75 |
getInstance( new RuntimeException() ) );
|
|
| 76 | 7 |
assertNotNull( |
| 77 |
getInstance( "msg" ) );
|
|
| 78 |
} |
|
| 79 |
|
|
| 80 | 7 |
public void testGetCause() |
| 81 |
{
|
|
| 82 | 7 |
RuntimeException re = new RuntimeException();
|
| 83 | 7 |
Throwable e = getInstance( "msg",
|
| 84 |
re ); |
|
| 85 |
|
|
| 86 | 7 |
assertEquals( re, e.getCause() ); |
| 87 | 7 |
assertEquals( "msg", e.getMessage() );
|
| 88 |
|
|
| 89 | 7 |
e = getInstance( "msg" );
|
| 90 | 7 |
assertNull( e.getCause() ); |
| 91 | 7 |
assertEquals( "msg", e.getMessage() );
|
| 92 |
|
|
| 93 |
// default to jdk 1.3 cause (not that it seems to help,
|
|
| 94 |
// but it still makes sense)
|
|
| 95 | 7 |
Exception exc = new Exception("blah"); |
| 96 | 7 |
try
|
| 97 |
{
|
|
| 98 | 7 |
try
|
| 99 |
{
|
|
| 100 | 7 |
throw exc;
|
| 101 |
} |
|
| 102 |
catch( Exception ex )
|
|
| 103 |
{
|
|
| 104 | 7 |
throw getInstance();
|
| 105 |
} |
|
| 106 |
} |
|
| 107 |
catch( Throwable ex )
|
|
| 108 |
{
|
|
| 109 | 7 |
ex.getCause(); |
| 110 |
} |
|
| 111 |
} |
|
| 112 |
} |
|
| 113 |
|
|
||||||||||