KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > firstpartners > nounit > utility > test > TestNoUnitException


1 package net.firstpartners.nounit.utility.test;
2
3 /**
4  * Title: NoUnit - Identify Classes that are not being unit Tested
5  *
6  * Copyright (C) 2001 Paul Browne , FirstPartners.net
7  *
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * @author Paul Browne
24  * @version 0.7
25  */

26
27 import junit.framework.Test;
28 import junit.framework.TestCase;
29 import junit.framework.TestSuite;
30 import net.firstpartners.nounit.utility.NoUnitException;
31
32 /**
33  * Class to test NoUnitException class
34  */

35 public class TestNoUnitException extends TestCase {
36
37   /**
38    * Constructor required by Junit
39    * @param name for super constructor
40    */

41   public TestNoUnitException(String JavaDoc name) {
42     super(name);
43   }
44
45   /**
46    * setup code is in this method
47    */

48   protected void setUp()
49   {
50       //Put in Setup Code Here
51

52   }
53
54   /**
55    * Main required by Junit
56    * @param args
57    */

58   public static void main(String JavaDoc[] args) {
59       junit.textui.TestRunner.run (suite());
60   }
61
62   /**
63    * suite giving list of tests for this class
64    * @return TestSuite
65    */

66   public static Test suite() {
67       return new TestSuite(TestNoUnitException.class);
68   }
69
70   /**
71    * Test Constructor with two values
72    */

73   public void testException1Value()
74   {
75
76     try {
77       //Done this way to fool compiler
78
if (true)
79         throw new NoUnitException("SomeUserMessage");
80
81       fail("Expected Exception Not thrown");
82     }
83     catch (Exception JavaDoc e)
84     {
85       //Check Exception
86
assertTrue(e instanceof Exception JavaDoc);
87       assertTrue(e instanceof NoUnitException);
88       assertTrue(e.toString()!=null);
89       assertTrue(e.toString().indexOf("omeUserMessage")>0);
90
91       NoUnitException myException =(NoUnitException)e;
92       assertTrue(myException.getUserErrorMessage().equals("SomeUserMessage"));
93     }
94
95   }
96
97   /**
98    * Test Constructor with two values
99    */

100   public void testException2Values()
101   {
102
103     try {
104       //Done this way to fool compiler
105
if (true)
106        throw new NoUnitException("TestKey","TestValue");
107
108       fail("Expected Exception Not thrown");
109     }
110     catch (Exception JavaDoc e)
111     {
112       //Check Exception
113
assertTrue(e instanceof Exception JavaDoc);
114       assertTrue(e instanceof NoUnitException);
115       assertTrue(e.toString()!=null);
116       assertTrue(e.toString().indexOf("TestKey")>0);
117       assertTrue(e.toString().indexOf("TestValue")>0);
118
119       NoUnitException myException =(NoUnitException)e;
120       assertTrue(myException.getUserErrorMessage().indexOf("TestKey")>0);
121       assertTrue(myException.getUserErrorMessage().indexOf("TestValue")>0);
122     }
123
124   }
125
126   /**
127    * Test Constructor with three values
128    */

129   public void testException3Values()
130   {
131
132     try {
133       //Done this way to fool compiler
134
if (true)
135        throw new NoUnitException("TestKey","TestValue","TestReason");
136       fail("Expected Exception Not thrown");
137     }
138     catch (Exception JavaDoc e)
139     {
140       //Check Exception
141
assertTrue(e instanceof Exception JavaDoc);
142       assertTrue(e instanceof NoUnitException);
143       assertTrue(e.toString()!=null);
144       assertTrue(e.toString().indexOf("TestKey")>0);
145       assertTrue(e.toString().indexOf("TestValue")>0);
146       assertTrue(e.toString().indexOf("TestReason")>0);
147
148       NoUnitException myException =(NoUnitException)e;
149       assertTrue(myException.getUserErrorMessage().indexOf("TestKey")>0);
150       assertTrue(myException.getUserErrorMessage().indexOf("TestValue")>0);
151       assertTrue(myException.getUserErrorMessage().indexOf("TestReason")>0);
152
153     }
154
155   }
156
157 }
158
Popular Tags