Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
66   160   20   9,43
0   122   0,3   7
7     2,86  
1    
 
  UsageExpectAndDefaultThrowTest       Line # 31 66 0% 20 10 86,3% 0.8630137
 
  (12)
 
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 org.junit.Before;
23    import org.junit.Test;
24   
25    /**
26    * Same as UsageExpectAndThrowTest except that each mocked method is called
27    * twice to make sure the defaulting works fine.
28    *
29    * @author OFFIS, Tammo Freese
30    */
 
31    public class UsageExpectAndDefaultThrowTest {
32   
33    private IMethods mock;
34   
35    private static RuntimeException EXCEPTION = new RuntimeException();
36   
 
37  12 toggle @Before
38    public void setup() {
39  12 mock = createMock(IMethods.class);
40    }
41   
 
42  2 toggle @Test
43    public void booleanType() {
44  2 expect(mock.booleanReturningMethod(4)).andStubThrow(EXCEPTION);
45  2 replay(mock);
46  2 try {
47  2 mock.booleanReturningMethod(4);
48  0 fail();
49    } catch (final RuntimeException exception) {
50  2 assertSame(EXCEPTION, exception);
51    }
52  2 try {
53  2 mock.booleanReturningMethod(4);
54  0 fail();
55    } catch (final RuntimeException exception) {
56  2 assertSame(EXCEPTION, exception);
57    }
58  2 verify(mock);
59    }
60   
 
61  2 toggle @Test
62    public void longType() {
63  2 expect(mock.longReturningMethod(4)).andStubThrow(EXCEPTION);
64  2 replay(mock);
65  2 try {
66  2 mock.longReturningMethod(4);
67  0 fail();
68    } catch (final RuntimeException exception) {
69  2 assertSame(EXCEPTION, exception);
70    }
71  2 try {
72  2 mock.longReturningMethod(4);
73  0 fail();
74    } catch (final RuntimeException exception) {
75  2 assertSame(EXCEPTION, exception);
76    }
77  2 verify(mock);
78    }
79   
 
80  2 toggle @Test
81    public void floatType() {
82  2 expect(mock.floatReturningMethod(4)).andStubThrow(EXCEPTION);
83  2 replay(mock);
84  2 try {
85  2 mock.floatReturningMethod(4);
86  0 fail();
87    } catch (final RuntimeException exception) {
88  2 assertSame(EXCEPTION, exception);
89    }
90  2 try {
91  2 mock.floatReturningMethod(4);
92  0 fail();
93    } catch (final RuntimeException exception) {
94  2 assertSame(EXCEPTION, exception);
95    }
96  2 verify(mock);
97    }
98   
 
99  2 toggle @Test
100    public void doubleType() {
101  2 expect(mock.doubleReturningMethod(4)).andStubThrow(EXCEPTION);
102  2 replay(mock);
103  2 try {
104  2 mock.doubleReturningMethod(4);
105  0 fail();
106    } catch (final RuntimeException exception) {
107  2 assertSame(EXCEPTION, exception);
108    }
109  2 try {
110  2 mock.doubleReturningMethod(4);
111  0 fail();
112    } catch (final RuntimeException exception) {
113  2 assertSame(EXCEPTION, exception);
114    }
115  2 verify(mock);
116    }
117   
 
118  2 toggle @Test
119    public void object() {
120  2 expect(mock.objectReturningMethod(4)).andStubThrow(EXCEPTION);
121  2 replay(mock);
122  2 try {
123  2 mock.objectReturningMethod(4);
124  0 fail();
125    } catch (final RuntimeException exception) {
126  2 assertSame(EXCEPTION, exception);
127    }
128  2 try {
129  2 mock.objectReturningMethod(4);
130  0 fail();
131    } catch (final RuntimeException exception) {
132  2 assertSame(EXCEPTION, exception);
133    }
134  2 verify(mock);
135    }
136   
 
137  2 toggle @Test
138    public void throwableAndDefaultThrowable() throws Exception {
139   
140  2 expect(mock.oneArg("1")).andThrow(new IllegalArgumentException());
141  2 expect(mock.oneArg((String) anyObject())).andStubThrow(new IllegalStateException());
142   
143  2 replay(mock);
144   
145  2 try {
146  2 mock.oneArg("1");
147    } catch (final IllegalArgumentException ignored) {
148    }
149  2 try {
150  2 mock.oneArg("1");
151    } catch (final IllegalStateException ignored) {
152    }
153  2 try {
154  2 mock.oneArg("2");
155    } catch (final IllegalStateException ignored) {
156    }
157  2 verify(mock);
158    }
159   
160    }