Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
77   205   24   7,7
6   149   0,31   10
10     2,4  
1    
 
  UsageTest       Line # 28 77 0% 24 12 87,1% 0.87096775
 
  (18)
 
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    * @author OFFIS, Tammo Freese
27    */
 
28    public class UsageTest {
29   
30    private IMethods mock;
31   
 
32  18 toggle @Before
33    public void setup() {
34  18 mock = createMock(IMethods.class);
35    }
36   
 
37  2 toggle @Test
38    public void exactCallCountByLastCall() {
39  2 expect(mock.oneArg(false)).andReturn("Test").andReturn("Test2");
40   
41  2 replay(mock);
42   
43  2 assertEquals("Test", mock.oneArg(false));
44  2 assertEquals("Test2", mock.oneArg(false));
45   
46  2 boolean failed = false;
47  2 try {
48  2 mock.oneArg(false);
49    } catch (final AssertionError expected) {
50  2 failed = true;
51    }
52  2 if (!failed)
53  0 fail("expected AssertionError");
54    }
55   
 
56  2 toggle @Test
57    public void openCallCountByLastCall() {
58  2 expect(mock.oneArg(false)).andReturn("Test").andReturn("Test2").atLeastOnce();
59   
60  2 replay(mock);
61   
62  2 assertEquals("Test", mock.oneArg(false));
63  2 assertEquals("Test2", mock.oneArg(false));
64  2 assertEquals("Test2", mock.oneArg(false));
65    }
66   
 
67  2 toggle @Test
68    public void exactCallCountByLastThrowable() {
69  2 expect(mock.oneArg(false)).andReturn("Test").andReturn("Test2").andThrow(
70    new IndexOutOfBoundsException()).once();
71   
72  2 replay(mock);
73   
74  2 assertEquals("Test", mock.oneArg(false));
75  2 assertEquals("Test2", mock.oneArg(false));
76   
77  2 try {
78  2 mock.oneArg(false);
79    } catch (final IndexOutOfBoundsException expected) {
80    }
81   
82  2 boolean failed = true;
83  2 try {
84  2 try {
85  2 mock.oneArg(false);
86    } catch (final IndexOutOfBoundsException expected) {
87    }
88  0 failed = false;
89    } catch (final AssertionError expected) {
90    }
91  2 if (!failed)
92  0 fail("expected AssertionError");
93    }
94   
 
95  2 toggle @Test
96    public void openCallCountByLastThrowable() {
97  2 expect(mock.oneArg(false)).andReturn("Test").andReturn("Test2").andThrow(
98    new IndexOutOfBoundsException()).atLeastOnce();
99   
100  2 replay(mock);
101   
102  2 assertEquals("Test", mock.oneArg(false));
103  2 assertEquals("Test2", mock.oneArg(false));
104   
105  2 try {
106  2 mock.oneArg(false);
107    } catch (final IndexOutOfBoundsException expected) {
108    }
109  2 try {
110  2 mock.oneArg(false);
111    } catch (final IndexOutOfBoundsException expected) {
112    }
113    }
114   
 
115  2 toggle @Test
116    public void moreThanOneArgument() {
117  2 expect(mock.threeArgumentMethod(1, "2", "3")).andReturn("Test").times(2);
118   
119  2 replay(mock);
120   
121  2 assertEquals("Test", mock.threeArgumentMethod(1, "2", "3"));
122   
123  2 boolean failed = true;
124  2 try {
125  2 verify(mock);
126  0 failed = false;
127    } catch (final AssertionError expected) {
128  2 assertEquals("\n Expectation failure on verify:"
129    + "\n threeArgumentMethod(1, \"2\", \"3\"): expected: 2, actual: 1", expected
130    .getMessage());
131    }
132  2 if (!failed) {
133  0 fail("exception expected");
134    }
135    }
136   
 
137  2 toggle @Test
138    public void unexpectedCallWithArray() {
139  2 reset(mock);
140  2 replay(mock);
141  2 final String[] strings = new String[] { "Test" };
142  2 try {
143  2 mock.arrayMethod(strings);
144  0 fail("exception expected");
145    } catch (final AssertionError expected) {
146  2 assertEquals("\n Unexpected method call arrayMethod(" + "[\"Test\"]" + "):", expected
147    .getMessage());
148    }
149    }
150   
 
151  2 toggle @Test
152    public void wrongArguments() {
153  2 mock.simpleMethodWithArgument("3");
154  2 replay(mock);
155   
156  2 try {
157  2 mock.simpleMethodWithArgument("5");
158  0 fail();
159    } catch (final AssertionError expected) {
160  2 assertEquals("\n Unexpected method call simpleMethodWithArgument(\"5\"):"
161    + "\n simpleMethodWithArgument(\"3\"): expected: 1, actual: 0", expected.getMessage());
162    }
163   
164    }
165   
 
166  2 toggle @Test
167    public void summarizeSameObjectArguments() {
168  2 mock.simpleMethodWithArgument("3");
169  2 mock.simpleMethodWithArgument("3");
170  2 replay(mock);
171   
172  2 try {
173  2 mock.simpleMethodWithArgument("5");
174  0 fail();
175    } catch (final AssertionError expected) {
176  2 assertEquals("\n Unexpected method call simpleMethodWithArgument(\"5\"):"
177    + "\n simpleMethodWithArgument(\"3\"): expected: 2, actual: 0", expected.getMessage());
178    }
179   
180    }
181   
 
182  2 toggle @Test
183    public void argumentsOrdered() {
184  2 mock.simpleMethodWithArgument("4");
185  2 mock.simpleMethodWithArgument("3");
186  2 mock.simpleMethodWithArgument("2");
187  2 mock.simpleMethodWithArgument("0");
188  2 mock.simpleMethodWithArgument("1");
189  2 replay(mock);
190   
191  2 try {
192  2 mock.simpleMethodWithArgument("5");
193  0 fail();
194    } catch (final AssertionError expected) {
195  2 assertEquals("\n Unexpected method call simpleMethodWithArgument(\"5\"):"
196    + "\n simpleMethodWithArgument(\"4\"): expected: 1, actual: 0"
197    + "\n simpleMethodWithArgument(\"3\"): expected: 1, actual: 0"
198    + "\n simpleMethodWithArgument(\"2\"): expected: 1, actual: 0"
199    + "\n simpleMethodWithArgument(\"0\"): expected: 1, actual: 0"
200    + "\n simpleMethodWithArgument(\"1\"): expected: 1, actual: 0", expected.getMessage());
201    }
202   
203    }
204   
205    }