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