Clover Coverage Report - perfectjpattern(Aggregated)
Coverage timestamp: Sat Feb 28 2009 14:35:07 CET
18   120   6   9
0   67   0.33   2
2     3  
1    
23.1% of code in this file is excluded from these metrics.
 
  AbstractTestRuntimeException       Line # 33 18 23.1% 6 0 100% 1.0
 
  (2)
 
1    //----------------------------------------------------------------------
2    //
3    // PerfectJPattern: "Design patterns are good but components are better!"
4    // AbstractTestRuntimeException.java Copyright (c) 2009 Giovanni Azua Garcia
5    // bravegag@hotmail.com
6    //
7    // This program is free software; you can redistribute it and/or
8    // modify it under the terms of the GNU General Public License
9    // as published by the Free Software Foundation; either version 3
10    // of the License, or (at your option) any later version.
11    //
12    // This program is distributed in the hope that it will be useful,
13    // but WITHOUT ANY WARRANTY; without even the implied warranty of
14    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    // GNU General Public License for more details.
16    //
17    // You should have received a copy of the GNU General Public License
18    // along with this program; if not, see <http://www.gnu.org/licenses/>.
19    //
20    //----------------------------------------------------------------------
21    package org.perfectjpattern.support.test;
22   
23    import junit.framework.*;
24   
25    /**
26    * Abstract base reusable {@link TestCase} for testing user-defined subtypes of
27    * {@link RuntimeException}
28    *
29    * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
30    * @version $Revision: 1.0 $Date: Feb 12, 2009 10:06:38 AM $
31    */
32    public abstract
 
33    class AbstractTestRuntimeException<E extends RuntimeException>
34    extends TestCase
35    {
36    //------------------------------------------------------------------------
37    // public
38    //------------------------------------------------------------------------
 
39  2 toggle public
40    AbstractTestRuntimeException(Class<E> aClass)
41    {
42    assert aClass != null : "'aClass' must not be null";
43   
44  2 theClass = aClass;
45    }
46   
47    //------------------------------------------------------------------------
 
48  2 toggle public void
49    testException()
50    throws Exception
51    {
52  2 String myClassName = theClass.getSimpleName();
53   
54  2 String myCause2 = "Database corrupt";
55  2 Throwable myCause3 = new RuntimeException("Disconnected");
56  2 String myCause4a = "Illegal Statement";
57  2 Throwable myCause4b = new RuntimeException(myCause4a);
58   
59  2 RuntimeException myException1 = theClass.newInstance();
60  2 RuntimeException myException2 = theClass.getDeclaredConstructor(String.
61    class).newInstance(myCause2);
62  2 RuntimeException myException3 = theClass.getDeclaredConstructor(
63    Throwable.class).newInstance(myCause3);
64  2 RuntimeException myException4 = theClass.getDeclaredConstructor(
65    String.class, Throwable.class).newInstance(myCause4a, myCause4b);
66   
67  2 try
68    {
69    throw myException1;
70    }
71    // CHECKSTYLE:OFF
72    catch (RuntimeException anException)
73    // CHECKSTYLE:ON
74    {
75  2 assertNull(myClassName + " did not work as expected", anException.
76    getMessage());
77    }
78   
79  2 try
80    {
81    throw myException2;
82    }
83    // CHECKSTYLE:OFF
84    catch (RuntimeException anException)
85    // CHECKSTYLE:ON
86    {
87  2 assertEquals(myClassName + " did not work as expected", myCause2,
88    anException.getMessage());
89    }
90   
91  2 try
92    {
93    throw myException3;
94    }
95    // CHECKSTYLE:OFF
96    catch (RuntimeException anException)
97    // CHECKSTYLE:ON
98    {
99  2 assertEquals(myClassName + " did not work as expected", myCause3,
100    anException.getCause());
101    }
102   
103  2 try
104    {
105    throw myException4;
106    }
107    // CHECKSTYLE:OFF
108    catch (RuntimeException anException)
109    // CHECKSTYLE:ON
110    {
111  2 assertEquals(myClassName + " did not work as expected", myCause4b,
112    anException.getCause());
113    }
114    }
115   
116    //------------------------------------------------------------------------
117    // members
118    //------------------------------------------------------------------------
119    private final Class<E> theClass;
120    }