Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
39   141   18   3,55
0   108   0,46   5,5
11     1,64  
2    
 
  StacktraceTest       Line # 34 38 0% 17 1 97,9% 0.9791667
  StacktraceTest.ToStringThrowsException       Line # 43 1 0% 1 0 100% 1.0
 
  (14)
 
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.tests;
18   
19    import static org.easymock.EasyMock.*;
20    import static org.junit.Assert.*;
21   
22    import java.lang.reflect.InvocationHandler;
23    import java.lang.reflect.Method;
24    import java.lang.reflect.Proxy;
25   
26    import org.easymock.IAnswer;
27    import org.easymock.internal.MockInvocationHandler;
28    import org.junit.Before;
29    import org.junit.Test;
30   
31    /**
32    * @author OFFIS, Tammo Freese
33    */
 
34    public class StacktraceTest {
35   
36    private IMethods mock;
37   
 
38  14 toggle @Before
39    public void setup() {
40  14 mock = createMock(IMethods.class);
41    }
42   
 
43    private static class ToStringThrowsException {
 
44  8 toggle @Override
45    public String toString() {
46  8 throw new NullPointerException();
47    }
48    }
49   
 
50  2 toggle @Test
51    public void assertRecordStateNoFillInStacktraceWhenExceptionNotFromEasyMock() {
52  2 mock.oneArg(new ToStringThrowsException());
53  2 try {
54  2 mock.oneArg(new ToStringThrowsException());
55    } catch (final NullPointerException expected) {
56  2 assertTrue("stack trace must not be cut", Util.getStackTrace(expected).indexOf(
57    ToStringThrowsException.class.getName()) > 0);
58    }
59    }
60   
 
61  2 toggle @Test
62    public void assertReplayNoFillInStacktraceWhenExceptionNotFromEasyMock() {
63  2 mock.oneArg(new ToStringThrowsException());
64  2 try {
65  2 replay(mock);
66    } catch (final NullPointerException expected) {
67  2 assertTrue("stack trace must not be cut", Util.getStackTrace(expected).indexOf(
68    ToStringThrowsException.class.getName()) > 0);
69    }
70    }
71   
 
72  2 toggle @Test
73    public void assertReplayStateNoFillInStacktraceWhenExceptionNotFromEasyMock() {
74  2 replay(mock);
75  2 try {
76  2 mock.oneArg(new ToStringThrowsException());
77    } catch (final NullPointerException expected) {
78  2 assertTrue("stack trace must not be cut", Util.getStackTrace(expected).indexOf(
79    ToStringThrowsException.class.getName()) > 0);
80    }
81    }
82   
 
83  2 toggle @Test
84    public void assertVerifyNoFillInStacktraceWhenExceptionNotFromEasyMock() {
85  2 expect(mock.oneArg(new ToStringThrowsException())).andReturn("");
86  2 replay(mock);
87  2 try {
88  2 verify(mock);
89  0 fail();
90    } catch (final NullPointerException expected) {
91  2 assertTrue("stack trace must not be cut", Util.getStackTrace(expected).indexOf(
92    ToStringThrowsException.class.getName()) > 0);
93    }
94    }
95   
 
96  2 toggle @Test
97    public void assertFillWhenThrowingAnswer() {
98  2 expect(mock.oneArg("")).andThrow(new NullPointerException());
99  2 replay(mock);
100  2 try {
101  2 mock.oneArg("");
102    } catch (final NullPointerException expected) {
103  2 assertTrue("stack trace should cut", Util.startWithClass(expected, MockInvocationHandler.class));
104    }
105    }
106   
 
107  2 toggle @Test
108    public void assertNoFillWhenDelegatingAnswer() {
109  2 final IMethods answer = (IMethods) Proxy.newProxyInstance(getClass().getClassLoader(),
110    new Class<?>[] { IMethods.class }, new InvocationHandler() {
 
111  2 toggle public Object invoke(final Object proxy, final Method method, final Object[] args)
112    throws Throwable {
113  2 throw new NullPointerException();
114    }
115    });
116  2 expect(mock.oneArg("")).andDelegateTo(answer);
117  2 replay(mock);
118  2 try {
119  2 mock.oneArg("");
120    } catch (final NullPointerException expected) {
121  2 assertTrue("stack trace must not be cut", Util.startWithClass(expected, Proxy
122    .getInvocationHandler(answer).getClass()));
123    }
124    }
125   
 
126  2 toggle @Test
127    public void assertNoFillWhenIAnswerAnswer() {
128  2 final IAnswer<String> answer = new IAnswer<String>() {
 
129  2 toggle public String answer() throws Throwable {
130  2 throw new NullPointerException();
131    }
132    };
133  2 expect(mock.oneArg("")).andAnswer(answer);
134  2 replay(mock);
135  2 try {
136  2 mock.oneArg("");
137    } catch (final NullPointerException expected) {
138  2 assertTrue("stack trace must not be cut", Util.startWithClass(expected, answer.getClass()));
139    }
140    }
141    }