Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
54   143   15   4,91
0   110   0,28   11
11     1,36  
1    
 
 
  UsageThrowableTest       Line # 16 54 15 93,8% 0.93846154
 
  (8)
 
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.junit.Assert.*;
8   
9    import java.io.IOException;
10   
11    import org.easymock.MockControl;
12    import org.junit.Before;
13    import org.junit.Test;
14   
15    @SuppressWarnings("deprecation")
 
16    public class UsageThrowableTest {
17   
18    private MockControl<IMethods> control;
19   
20    private IMethods mock;
21   
 
22  8 toggle @Before
23    public void setup() {
24  8 control = MockControl.createControl(IMethods.class);
25  8 mock = control.getMock();
26    }
27   
 
28  1 toggle @Test
29    public void noUpperLimit() {
30  1 mock.simpleMethodWithArgument("1");
31  1 control.setVoidCallable(MockControl.ONE_OR_MORE);
32  1 mock.simpleMethodWithArgument("2");
33  1 control.replay();
34  1 mock.simpleMethodWithArgument("1");
35  1 mock.simpleMethodWithArgument("1");
36  1 mock.simpleMethodWithArgument("2");
37  1 mock.simpleMethodWithArgument("1");
38  1 mock.simpleMethodWithArgument("1");
39  1 control.verify();
40    }
41   
 
42  1 toggle @Test
43    public void throwRuntimeException() {
44  1 testThrowUncheckedException(new RuntimeException());
45    }
46   
 
47  1 toggle @Test
48    public void throwSubclassOfRuntimeException() {
49  1 testThrowUncheckedException(new RuntimeException() {
50    private static final long serialVersionUID = 1L;
51    });
52    }
53   
 
54  1 toggle @Test
55    public void throwError() {
56  1 testThrowUncheckedException(new Error());
57    }
58   
 
59  1 toggle @Test
60    public void throwSubclassOfError() {
61  1 testThrowUncheckedException(new Error() {
62    private static final long serialVersionUID = 1L;
63    });
64    }
65   
 
66  4 toggle private void testThrowUncheckedException(Throwable throwable) {
67  4 mock.throwsNothing(true);
68  4 control.setReturnValue("true");
69  4 mock.throwsNothing(false);
70  4 control.setThrowable(throwable);
71   
72  4 control.replay();
73   
74  4 try {
75  4 mock.throwsNothing(false);
76  0 fail("Trowable expected");
77    } catch (Throwable expected) {
78  4 assertSame(throwable, expected);
79    }
80   
81  4 assertEquals("true", mock.throwsNothing(true));
82    }
83   
 
84  1 toggle @Test
85    public void throwCheckedException() throws IOException {
86  1 testThrowCheckedException(new IOException());
87    }
88   
 
89  1 toggle @Test
90    public void throwSubclassOfCheckedException() throws IOException {
91  1 testThrowCheckedException(new IOException() {
92    private static final long serialVersionUID = 1L;
93    });
94    }
95   
 
96  2 toggle private void testThrowCheckedException(IOException expected)
97    throws IOException {
98  2 try {
99  2 mock.throwsIOException(0);
100  2 control.setReturnValue("Value 0");
101  2 mock.throwsIOException(1);
102  2 control.setThrowable(expected);
103  2 mock.throwsIOException(2);
104  2 control.setReturnValue("Value 2");
105    } catch (IOException e) {
106  0 fail("Unexpected Exception");
107    }
108   
109  2 control.replay();
110   
111  2 assertEquals("Value 0", mock.throwsIOException(0));
112  2 assertEquals("Value 2", mock.throwsIOException(2));
113   
114  2 try {
115  2 mock.throwsIOException(1);
116  0 fail("IOException expected");
117    } catch (IOException expectedException) {
118  2 assertSame(expectedException, expected);
119    }
120    }
121   
 
122  1 toggle @Test
123    public void throwAfterReturnValue() {
124  1 mock.throwsNothing(false);
125  1 control.setReturnValue("");
126  1 RuntimeException expectedException = new RuntimeException();
127  1 control.setThrowable(expectedException);
128   
129  1 control.replay();
130   
131  1 assertEquals("", mock.throwsNothing(false));
132   
133  1 try {
134  1 mock.throwsNothing(false);
135  0 fail("RuntimeException expected");
136    } catch (RuntimeException actualException) {
137  1 assertSame(expectedException, actualException);
138    }
139   
140  1 control.verify();
141    }
142   
143    }