KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > easymock > tests > StacktraceTest


1 /*
2  * Copyright (c) 2001-2005 OFFIS. This program is made available under the terms of
3  * the MIT License.
4  */

5 package org.easymock.tests;
6
7 import junit.framework.TestCase;
8
9 import org.easymock.MockControl;
10
11 public class StacktraceTest extends TestCase {
12
13     private MockControl<IMethods> control;
14
15     private IMethods mock;
16
17     protected void setUp() {
18         control = MockControl.createStrictControl(IMethods.class);
19         mock = control.getMock();
20     }
21
22     private static class ToStringThrowsException {
23         public String JavaDoc toString() {
24             throw new NullPointerException JavaDoc();
25         }
26     }
27
28     public void testAssertRecordStateNoFillInStacktraceWhenExceptionNotFromEasyMock() {
29         mock.oneArgumentMethod(new ToStringThrowsException());
30         try {
31             mock.oneArgumentMethod(new ToStringThrowsException());
32         } catch (NullPointerException JavaDoc expected) {
33             assertTrue("stack trace must not be cut",
34                     Util.getStackTrace(expected).indexOf(
35                             ToStringThrowsException.class.getName()) > 0);
36         }
37     }
38
39     public void testAssertReplayNoFillInStacktraceWhenExceptionNotFromEasyMock() {
40         mock.oneArgumentMethod(new ToStringThrowsException());
41         try {
42             control.replay();
43         } catch (NullPointerException JavaDoc expected) {
44             assertTrue("stack trace must not be cut",
45                     Util.getStackTrace(expected).indexOf(
46                             ToStringThrowsException.class.getName()) > 0);
47         }
48     }
49
50     public void testAssertReplayStateNoFillInStacktraceWhenExceptionNotFromEasyMock() {
51         control.replay();
52         try {
53             mock.oneArgumentMethod(new ToStringThrowsException());
54         } catch (NullPointerException JavaDoc expected) {
55             assertTrue("stack trace must not be cut",
56                     Util.getStackTrace(expected).indexOf(
57                             ToStringThrowsException.class.getName()) > 0);
58         }
59     }
60
61     public void testAssertVerifyNoFillInStacktraceWhenExceptionNotFromEasyMock() {
62         mock.oneArgumentMethod(new ToStringThrowsException());
63         control.setReturnValue("");
64         control.replay();
65         try {
66             control.verify();
67             fail();
68         } catch (NullPointerException JavaDoc expected) {
69             assertTrue("stack trace must not be cut",
70                     Util.getStackTrace(expected).indexOf(
71                             ToStringThrowsException.class.getName()) > 0);
72         }
73     }
74 }
75
Popular Tags