001: package net.firstpartners.nounit.utility.test;
002:
003: /**
004: * Title: NoUnit - Identify Classes that are not being unit Tested
005: *
006: * Copyright (C) 2001 Paul Browne , FirstPartners.net
007: *
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * @author Paul Browne
024: * @version 0.7
025: */
026:
027: import junit.framework.Test;
028: import junit.framework.TestCase;
029: import junit.framework.TestSuite;
030: import net.firstpartners.nounit.utility.NoUnitException;
031:
032: /**
033: * Class to test NoUnitException class
034: */
035: public class TestNoUnitException extends TestCase {
036:
037: /**
038: * Constructor required by Junit
039: * @param name for super constructor
040: */
041: public TestNoUnitException(String name) {
042: super (name);
043: }
044:
045: /**
046: * setup code is in this method
047: */
048: protected void setUp() {
049: //Put in Setup Code Here
050:
051: }
052:
053: /**
054: * Main required by Junit
055: * @param args
056: */
057: public static void main(String[] args) {
058: junit.textui.TestRunner.run(suite());
059: }
060:
061: /**
062: * suite giving list of tests for this class
063: * @return TestSuite
064: */
065: public static Test suite() {
066: return new TestSuite(TestNoUnitException.class);
067: }
068:
069: /**
070: * Test Constructor with two values
071: */
072: public void testException1Value() {
073:
074: try {
075: //Done this way to fool compiler
076: if (true)
077: throw new NoUnitException("SomeUserMessage");
078:
079: fail("Expected Exception Not thrown");
080: } catch (Exception e) {
081: //Check Exception
082: assertTrue(e instanceof Exception);
083: assertTrue(e instanceof NoUnitException);
084: assertTrue(e.toString() != null);
085: assertTrue(e.toString().indexOf("omeUserMessage") > 0);
086:
087: NoUnitException myException = (NoUnitException) e;
088: assertTrue(myException.getUserErrorMessage().equals(
089: "SomeUserMessage"));
090: }
091:
092: }
093:
094: /**
095: * Test Constructor with two values
096: */
097: public void testException2Values() {
098:
099: try {
100: //Done this way to fool compiler
101: if (true)
102: throw new NoUnitException("TestKey", "TestValue");
103:
104: fail("Expected Exception Not thrown");
105: } catch (Exception e) {
106: //Check Exception
107: assertTrue(e instanceof Exception);
108: assertTrue(e instanceof NoUnitException);
109: assertTrue(e.toString() != null);
110: assertTrue(e.toString().indexOf("TestKey") > 0);
111: assertTrue(e.toString().indexOf("TestValue") > 0);
112:
113: NoUnitException myException = (NoUnitException) e;
114: assertTrue(myException.getUserErrorMessage().indexOf(
115: "TestKey") > 0);
116: assertTrue(myException.getUserErrorMessage().indexOf(
117: "TestValue") > 0);
118: }
119:
120: }
121:
122: /**
123: * Test Constructor with three values
124: */
125: public void testException3Values() {
126:
127: try {
128: //Done this way to fool compiler
129: if (true)
130: throw new NoUnitException("TestKey", "TestValue",
131: "TestReason");
132: fail("Expected Exception Not thrown");
133: } catch (Exception e) {
134: //Check Exception
135: assertTrue(e instanceof Exception);
136: assertTrue(e instanceof NoUnitException);
137: assertTrue(e.toString() != null);
138: assertTrue(e.toString().indexOf("TestKey") > 0);
139: assertTrue(e.toString().indexOf("TestValue") > 0);
140: assertTrue(e.toString().indexOf("TestReason") > 0);
141:
142: NoUnitException myException = (NoUnitException) e;
143: assertTrue(myException.getUserErrorMessage().indexOf(
144: "TestKey") > 0);
145: assertTrue(myException.getUserErrorMessage().indexOf(
146: "TestValue") > 0);
147: assertTrue(myException.getUserErrorMessage().indexOf(
148: "TestReason") > 0);
149:
150: }
151:
152: }
153:
154: }
|