001: /*
002: * @(#)StackTraceLineParserUTest.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.util.throwable.v1;
028:
029: import org.easymock.EasyMock;
030: import org.easymock.MockControl;
031: import junit.framework.Test;
032: import junit.framework.TestCase;
033: import junit.framework.TestSuite;
034:
035: /**
036: * Tests the StackTraceLineParser class.
037: *
038: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
039: * @version $Date: 2003/02/10 22:52:43 $
040: * @since March 17, 2002
041: */
042: public class StackTraceLineParserUTest extends TestCase {
043: //-------------------------------------------------------------------------
044: // Standard JUnit Class-specific declarations
045:
046: private static final Class THIS_CLASS = StackTraceLineParserUTest.class;
047:
048: public StackTraceLineParserUTest(String name) {
049: super (name);
050: }
051:
052: //-------------------------------------------------------------------------
053: // setup
054:
055: /**
056: *
057: * @exception Exception thrown under any exceptional condition.
058: */
059: protected void setUp() throws Exception {
060: super .setUp();
061:
062: // set ourself up
063: }
064:
065: //-------------------------------------------------------------------------
066: // Tests
067:
068: public void testConstructor1() {
069: try {
070: new StackTraceLineParser(null, null);
071: fail("did not throw an IllegalArgumentException.");
072: } catch (IllegalArgumentException e) {
073: // parse exception?
074: }
075: }
076:
077: public void testConstructor2() {
078: try {
079: new StackTraceLineParser("me", null);
080: fail("did not throw an IllegalArgumentException.");
081: } catch (IllegalArgumentException e) {
082: // parse exception?
083: }
084: }
085:
086: public void testConstructor3() {
087: try {
088: new StackTraceLineParser(null, "you");
089: fail("did not throw an IllegalArgumentException.");
090: } catch (IllegalArgumentException e) {
091: // parse exception?
092: }
093: }
094:
095: public void testConstructor4() {
096: try {
097: new StackTraceLineParser(null, null, 1);
098: fail("did not throw an IllegalArgumentException.");
099: } catch (IllegalArgumentException e) {
100: // parse exception?
101: }
102: }
103:
104: public void testConstructor5() {
105: try {
106: new StackTraceLineParser("me", null, 1);
107: fail("did not throw an IllegalArgumentException.");
108: } catch (IllegalArgumentException e) {
109: // parse exception?
110: }
111: }
112:
113: public void testConstructor6() {
114: try {
115: new StackTraceLineParser(null, "you", 1);
116: fail("did not throw an IllegalArgumentException.");
117: } catch (IllegalArgumentException e) {
118: // parse exception?
119: }
120: }
121:
122: public void testInit1() {
123: StackTraceLineParser stlp = new StackTraceLineParser("me",
124: "you");
125: assertEquals("Did not save class name right.", "me", stlp
126: .getClassName());
127: assertEquals("Did not save method name right.", "you", stlp
128: .getMethodName());
129: assertEquals("Did not save default line number right.", -1,
130: stlp.getLineNumber());
131: }
132:
133: public void testInit2() {
134: StackTraceLineParser stlp = new StackTraceLineParser("me",
135: "you", -100);
136: assertEquals("Did not save class name right.", "me", stlp
137: .getClassName());
138: assertEquals("Did not save method name right.", "you", stlp
139: .getMethodName());
140: assertEquals("Did not set out-of-range line number right.", -1,
141: stlp.getLineNumber());
142: }
143:
144: public void testInit3() {
145: StackTraceLineParser stlp = new StackTraceLineParser("me",
146: "you", 100);
147: assertEquals("Did not save class name right.", "me", stlp
148: .getClassName());
149: assertEquals("Did not save method name right.", "you", stlp
150: .getMethodName());
151: assertEquals("Did not save line number right.", 100, stlp
152: .getLineNumber());
153: }
154:
155: //-------------------------------------------------------------------------
156: // Helpers
157:
158: //-------------------------------------------------------------------------
159: // Standard JUnit declarations
160:
161: public static Test suite() {
162: TestSuite suite = new TestSuite(THIS_CLASS);
163:
164: // Test the implementation's interface conformity.
165: /*
166: suite.addTest( IxUTestI.suite(
167: new ImplementationCreator[] {
168: new ImplementationCreator() {
169: public Object createImplementedObject() {
170: // XXXXXXXXXXXXXXXXXXXXXXXX
171: }
172: },
173: } ) );
174: */
175:
176: return suite;
177: }
178:
179: public static void main(String[] args) {
180: String[] name = { THIS_CLASS.getName() };
181:
182: // junit.textui.TestRunner.main( name );
183: // junit.swingui.TestRunner.main( name );
184:
185: junit.textui.TestRunner.main(name);
186: }
187:
188: /**
189: *
190: * @exception Exception thrown under any exceptional condition.
191: */
192: protected void tearDown() throws Exception {
193: // tear ourself down
194:
195: super.tearDown();
196: }
197: }
|