Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
53   151   14   13,25
2   101   0,26   4
4     3,5  
1    
 
  UsageVerifyTest       Line # 31 53 0% 14 11 81,4% 0.8135593
 
  (6)
 
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.easymock.internal.ReplayState;
25    import org.junit.Before;
26    import org.junit.Test;
27   
28    /**
29    * @author OFFIS, Tammo Freese
30    */
 
31    public class UsageVerifyTest {
32   
33    private IMethods mock;
34   
 
35  6 toggle @Before
36    public void setup() {
37  6 mock = createMock(IMethods.class);
38    }
39   
 
40  2 toggle @Test
41    public void twoReturns() {
42  2 expect(mock.throwsNothing(true)).andReturn("Test").andReturn("Test2");
43   
44  2 replay(mock);
45   
46  2 assertEquals("Test", mock.throwsNothing(true));
47   
48  2 boolean failed = true;
49   
50  2 try {
51  2 verify(mock);
52  0 failed = false;
53    } catch (final AssertionError expected) {
54  2 assertEquals("\n Expectation failure on verify:"
55    + "\n throwsNothing(true): expected: 2, actual: 1", expected.getMessage());
56  2 assertTrue("stack trace must be filled in", Util.getStackTrace(expected).indexOf(
57    ReplayState.class.getName()) == -1);
58    }
59   
60  2 if (!failed)
61  0 fail("AssertionError expected");
62   
63  2 assertEquals("Test2", mock.throwsNothing(true));
64   
65  2 verify(mock);
66   
67  2 try {
68  2 mock.throwsNothing(true);
69  0 fail("AssertionError expected");
70    } catch (final AssertionError expected) {
71  2 assertEquals("\n Unexpected method call throwsNothing(true):"
72    + "\n throwsNothing(true): expected: 2, actual: 3", expected.getMessage());
73    }
74    }
75   
 
76  2 toggle @Test
77    public void atLeastTwoReturns() {
78  2 expect(mock.throwsNothing(true)).andReturn("Test").andReturn("Test2").atLeastOnce();
79   
80  2 replay(mock);
81   
82  2 assertEquals("Test", mock.throwsNothing(true));
83   
84  2 try {
85  2 verify(mock);
86  0 fail("AssertionError expected");
87    } catch (final AssertionError expected) {
88   
89  2 assertEquals("\n Expectation failure on verify:"
90    + "\n throwsNothing(true): expected: at least 2, actual: 1", expected.getMessage());
91    }
92   
93  2 assertEquals("Test2", mock.throwsNothing(true));
94  2 assertEquals("Test2", mock.throwsNothing(true));
95   
96  2 verify(mock);
97    }
98   
 
99  2 toggle @Test
100    public void twoThrows() throws IOException {
101  2 expect(mock.throwsIOException(0)).andThrow(new IOException()).andThrow(new IOException());
102  2 expect(mock.throwsIOException(1)).andThrow(new IOException());
103   
104  2 replay(mock);
105   
106  2 try {
107  2 mock.throwsIOException(0);
108  0 fail("IOException expected");
109    } catch (final IOException expected) {
110    }
111   
112  2 try {
113  2 verify(mock);
114  0 fail("AssertionError expected");
115    } catch (final AssertionError expected) {
116  2 assertEquals("\n Expectation failure on verify:"
117    + "\n throwsIOException(0): expected: 2, actual: 1"
118    + "\n throwsIOException(1): expected: 1, actual: 0", expected.getMessage());
119    }
120   
121  2 try {
122  2 mock.throwsIOException(0);
123  0 fail("IOException expected");
124    } catch (final IOException expected) {
125    }
126   
127  2 try {
128  2 verify(mock);
129  0 fail("AssertionError expected");
130    } catch (final AssertionError expected) {
131  2 assertEquals("\n Expectation failure on verify:"
132    + "\n throwsIOException(1): expected: 1, actual: 0", expected.getMessage());
133    }
134   
135  2 try {
136  2 mock.throwsIOException(1);
137  0 fail("IOException expected");
138    } catch (final IOException expected) {
139    }
140   
141  2 verify(mock);
142   
143  2 try {
144  2 mock.throwsIOException(0);
145  0 fail("AssertionError expected");
146    } catch (final AssertionError expected) {
147  2 assertEquals("\n Unexpected method call throwsIOException(0):"
148    + "\n throwsIOException(0): expected: 2, actual: 3", expected.getMessage());
149    }
150    }
151    }