Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
37   108   8   9,25
0   65   0,22   4
4     2  
1    
 
  MockedExceptionTest       Line # 27 37 0% 8 0 100% 1.0
 
  (8)
 
1    /**
2    * Copyright 2001-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16   
17    package org.easymock.tests2;
18   
19    import static org.easymock.EasyMock.*;
20    import static org.junit.Assert.*;
21   
22    import org.junit.Test;
23   
24    /**
25    * @author Henri Tremblay
26    */
 
27    public class MockedExceptionTest {
28   
 
29  2 toggle @Test
30    public void testMockedException() {
31  2 final RuntimeException expected = createNiceMock(RuntimeException.class);
32  2 final CharSequence c = createMock(CharSequence.class);
33  2 expect(c.length()).andStubThrow(expected);
34  2 replay(c, expected);
35   
36  2 try {
37  2 c.length(); // fillInStackTrace will be called internally here
38    } catch (final RuntimeException actual) {
39  2 assertSame(expected, actual);
40    }
41   
42  2 verify(c, expected);
43    }
44   
 
45  2 toggle @Test
46    public void testExplicitFillInStackTrace() {
47   
48  2 final RuntimeException expected = createNiceMock(RuntimeException.class);
49  2 final RuntimeException myException = new RuntimeException();
50  2 expect(expected.fillInStackTrace()).andReturn(myException);
51   
52  2 final CharSequence c = createMock(CharSequence.class);
53  2 expect(c.length()).andStubThrow(expected);
54   
55  2 replay(c, expected);
56   
57  2 try {
58  2 c.length(); // fillInStackTrace will be called internally here
59    } catch (final RuntimeException actual) {
60  2 assertSame(myException, actual.fillInStackTrace());
61  2 assertSame(expected, actual);
62    }
63   
64  2 verify(c, expected);
65    }
66   
 
67  2 toggle @Test
68    public void testNotMockedFillInStackTrace() {
69   
70  2 final RuntimeException expected = createMockBuilder(RuntimeException.class).createNiceMock();
71   
72  2 final CharSequence c = createMock(CharSequence.class);
73  2 expect(c.length()).andStubThrow(expected);
74   
75  2 replay(c, expected);
76   
77  2 try {
78  2 c.length(); // fillInStackTrace will be called internally here
79    } catch (final RuntimeException actual) {
80  2 assertSame(expected, actual);
81  2 assertEquals("fillInStackTrace should have been called normally", actual.getClass().getName(),
82    actual.getStackTrace()[0].getClassName());
83    }
84   
85  2 verify(c, expected);
86    }
87   
 
88  2 toggle @Test
89    public void testRealException() {
90   
91  2 final RuntimeException expected = new RuntimeException();
92   
93  2 final CharSequence c = createMock(CharSequence.class);
94  2 expect(c.length()).andStubThrow(expected);
95   
96  2 replay(c);
97   
98  2 try {
99  2 c.length(); // fillInStackTrace will be called internally here
100    } catch (final RuntimeException actual) {
101  2 assertSame(expected, actual);
102  2 assertEquals("fillInStackTrace should have been called normally",
103    "org.easymock.internal.MockInvocationHandler", actual.getStackTrace()[0].getClassName());
104    }
105   
106  2 verify(c);
107    }
108    }