Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
68   156   20   9,71
0   129   0,29   7
7     2,86  
1    
 
 
  UsageExpectAndDefaultThrowTest       Line # 21 68 20 86,7% 0.8666667
 
  (6)
 
1    /*
2    * Copyright (c) 2001-2008 OFFIS, Tammo Freese.
3    * This program is made available under the terms of the MIT License.
4    */
5    package org.easymock.tests;
6   
7    import static org.easymock.EasyMock.*;
8    import static org.junit.Assert.*;
9   
10    import org.easymock.MockControl;
11    import org.junit.Before;
12    import org.junit.Test;
13   
14    /**
15    * Same as UsageExpectAndThrowTest except that each mocked method is called
16    * twice to make sure the defaulting works fine.
17    *
18    * @author Henri Tremblay
19    */
20    @SuppressWarnings("deprecation")
 
21    public class UsageExpectAndDefaultThrowTest {
22    private MockControl<IMethods> control;
23   
24    private IMethods mock;
25   
26    private static RuntimeException EXCEPTION = new RuntimeException();
27   
 
28  6 toggle @Before
29    public void setup() {
30  6 control = MockControl.createControl(IMethods.class);
31  6 mock = control.getMock();
32    }
33   
 
34  1 toggle @Test
35    public void booleanType() {
36  1 control
37    .expectAndDefaultThrow(mock.booleanReturningMethod(4),
38    EXCEPTION);
39  1 control.replay();
40  1 try {
41  1 mock.booleanReturningMethod(4);
42  0 fail();
43    } catch (RuntimeException exception) {
44  1 assertSame(EXCEPTION, exception);
45    }
46  1 try {
47  1 mock.booleanReturningMethod(4);
48  0 fail();
49    } catch (RuntimeException exception) {
50  1 assertSame(EXCEPTION, exception);
51    }
52  1 control.verify();
53    }
54   
 
55  1 toggle @Test
56    public void longType() {
57  1 control.expectAndDefaultThrow(mock.longReturningMethod(4), EXCEPTION);
58  1 control.replay();
59  1 try {
60  1 mock.longReturningMethod(4);
61  0 fail();
62    } catch (RuntimeException exception) {
63  1 assertSame(EXCEPTION, exception);
64    }
65  1 try {
66  1 mock.longReturningMethod(4);
67  0 fail();
68    } catch (RuntimeException exception) {
69  1 assertSame(EXCEPTION, exception);
70    }
71  1 control.verify();
72    }
73   
 
74  1 toggle @Test
75    public void floatType() {
76  1 control.expectAndDefaultThrow(mock.floatReturningMethod(4), EXCEPTION);
77  1 control.replay();
78  1 try {
79  1 mock.floatReturningMethod(4);
80  0 fail();
81    } catch (RuntimeException exception) {
82  1 assertSame(EXCEPTION, exception);
83    }
84  1 try {
85  1 mock.floatReturningMethod(4);
86  0 fail();
87    } catch (RuntimeException exception) {
88  1 assertSame(EXCEPTION, exception);
89    }
90  1 control.verify();
91    }
92   
 
93  1 toggle @Test
94    public void doubleType() {
95  1 control.expectAndDefaultThrow(mock.doubleReturningMethod(4), EXCEPTION);
96  1 control.replay();
97  1 try {
98  1 mock.doubleReturningMethod(4);
99  0 fail();
100    } catch (RuntimeException exception) {
101  1 assertSame(EXCEPTION, exception);
102    }
103  1 try {
104  1 mock.doubleReturningMethod(4);
105  0 fail();
106    } catch (RuntimeException exception) {
107  1 assertSame(EXCEPTION, exception);
108    }
109  1 control.verify();
110    }
111   
 
112  1 toggle @Test
113    public void object() {
114  1 control.expectAndDefaultThrow(mock.objectReturningMethod(4), EXCEPTION);
115  1 control.replay();
116  1 try {
117  1 mock.objectReturningMethod(4);
118  0 fail();
119    } catch (RuntimeException exception) {
120  1 assertSame(EXCEPTION, exception);
121    }
122  1 try {
123  1 mock.objectReturningMethod(4);
124  0 fail();
125    } catch (RuntimeException exception) {
126  1 assertSame(EXCEPTION, exception);
127    }
128  1 control.verify();
129    }
130   
 
131  1 toggle @Test
132    public void throwableAndDefaultThrowable() throws Exception {
133   
134  1 mock.oneArg("1");
135   
136  1 expectLastCall().andThrow(new IllegalArgumentException());
137  1 control.setDefaultThrowable(new IllegalStateException());
138   
139  1 control.replay();
140   
141  1 try {
142  1 mock.oneArg("1");
143    } catch (IllegalArgumentException ignored) {
144    }
145  1 try {
146  1 mock.oneArg("1");
147    } catch (IllegalStateException ignored) {
148    }
149  1 try {
150  1 mock.oneArg("2");
151    } catch (IllegalStateException ignored) {
152    }
153  1 control.verify();
154    }
155   
156    }