| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
package org.easymock.tests2; |
| 6 |
|
|
| 7 |
|
import static org.easymock.EasyMock.*; |
| 8 |
|
import static org.junit.Assert.*; |
| 9 |
|
|
| 10 |
|
import org.easymock.tests.IMethods; |
| 11 |
|
import org.junit.Before; |
| 12 |
|
import org.junit.Test; |
| 13 |
|
|
|
|
|
| 90,4% |
Uncovered Elements: 15 (156) |
Complexity: 30 |
Complexity Density: 0,22 |
|
| 14 |
|
public class UsageTest { |
| 15 |
|
|
| 16 |
|
IMethods mock; |
| 17 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 18 |
13
|
@Before... |
| 19 |
|
public void setup() { |
| 20 |
13
|
mock = createMock(IMethods.class); |
| 21 |
|
} |
| 22 |
|
|
|
|
|
| 83,3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0,3 |
1
PASS
|
|
| 23 |
1
|
@Test... |
| 24 |
|
public void exactCallCountByLastCall() { |
| 25 |
1
|
expect(mock.oneArg(false)).andReturn("Test").andReturn("Test2"); |
| 26 |
1
|
replay(mock); |
| 27 |
|
|
| 28 |
1
|
assertEquals("Test", mock.oneArg(false)); |
| 29 |
1
|
assertEquals("Test2", mock.oneArg(false)); |
| 30 |
|
|
| 31 |
1
|
boolean failed = false; |
| 32 |
1
|
try { |
| 33 |
1
|
mock.oneArg(false); |
| 34 |
|
} catch (AssertionError expected) { |
| 35 |
1
|
failed = true; |
| 36 |
|
} |
| 37 |
1
|
if (!failed) |
| 38 |
0
|
fail("expected AssertionError"); |
| 39 |
|
} |
| 40 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
1
PASS
|
|
| 41 |
1
|
@Test... |
| 42 |
|
public void openCallCountByLastCall() { |
| 43 |
1
|
expect(mock.oneArg(false)).andReturn("Test").andReturn("Test2") |
| 44 |
|
.atLeastOnce(); |
| 45 |
|
|
| 46 |
1
|
replay(mock); |
| 47 |
|
|
| 48 |
1
|
assertEquals("Test", mock.oneArg(false)); |
| 49 |
1
|
assertEquals("Test2", mock.oneArg(false)); |
| 50 |
1
|
assertEquals("Test2", mock.oneArg(false)); |
| 51 |
|
} |
| 52 |
|
|
|
|
|
| 73,3% |
Uncovered Elements: 4 (15) |
Complexity: 4 |
Complexity Density: 0,31 |
1
PASS
|
|
| 53 |
1
|
@Test... |
| 54 |
|
public void exactCallCountByLastThrowable() { |
| 55 |
1
|
expect(mock.oneArg(false)).andReturn("Test").andReturn("Test2") |
| 56 |
|
.andThrow(new IndexOutOfBoundsException()); |
| 57 |
|
|
| 58 |
1
|
replay(mock); |
| 59 |
|
|
| 60 |
1
|
assertEquals("Test", mock.oneArg(false)); |
| 61 |
1
|
assertEquals("Test2", mock.oneArg(false)); |
| 62 |
|
|
| 63 |
1
|
try { |
| 64 |
1
|
mock.oneArg(false); |
| 65 |
0
|
fail(); |
| 66 |
|
} catch (IndexOutOfBoundsException expected) { |
| 67 |
|
} |
| 68 |
|
|
| 69 |
1
|
boolean failed = true; |
| 70 |
1
|
try { |
| 71 |
1
|
mock.oneArg(false); |
| 72 |
0
|
failed = false; |
| 73 |
|
} catch (AssertionError expected) { |
| 74 |
|
} |
| 75 |
1
|
if (!failed) |
| 76 |
0
|
fail("expected AssertionError"); |
| 77 |
|
} |
| 78 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0,38 |
1
PASS
|
|
| 79 |
1
|
@Test... |
| 80 |
|
public void openCallCountByLastThrowable() { |
| 81 |
1
|
expect(mock.oneArg(false)).andReturn("Test").andReturn("Test2") |
| 82 |
|
.andThrow(new IndexOutOfBoundsException()).atLeastOnce(); |
| 83 |
|
|
| 84 |
1
|
replay(mock); |
| 85 |
|
|
| 86 |
1
|
assertEquals("Test", mock.oneArg(false)); |
| 87 |
1
|
assertEquals("Test2", mock.oneArg(false)); |
| 88 |
|
|
| 89 |
1
|
try { |
| 90 |
1
|
mock.oneArg(false); |
| 91 |
|
} catch (IndexOutOfBoundsException expected) { |
| 92 |
|
} |
| 93 |
1
|
try { |
| 94 |
1
|
mock.oneArg(false); |
| 95 |
|
} catch (IndexOutOfBoundsException expected) { |
| 96 |
|
} |
| 97 |
|
} |
| 98 |
|
|
|
|
|
| 75% |
Uncovered Elements: 3 (12) |
Complexity: 3 |
Complexity Density: 0,3 |
1
PASS
|
|
| 99 |
1
|
@Test... |
| 100 |
|
public void moreThanOneArgument() { |
| 101 |
1
|
expect(mock.threeArgumentMethod(1, "2", "3")).andReturn("Test") |
| 102 |
|
.times(2); |
| 103 |
|
|
| 104 |
1
|
replay(mock); |
| 105 |
|
|
| 106 |
1
|
assertEquals("Test", mock.threeArgumentMethod(1, "2", "3")); |
| 107 |
|
|
| 108 |
1
|
boolean failed = true; |
| 109 |
1
|
try { |
| 110 |
1
|
verify(mock); |
| 111 |
0
|
failed = false; |
| 112 |
|
} catch (AssertionError expected) { |
| 113 |
1
|
assertEquals( |
| 114 |
|
"\n Expectation failure on verify:" |
| 115 |
|
+ "\n threeArgumentMethod(1, \"2\", \"3\"): expected: 2, actual: 1", |
| 116 |
|
expected.getMessage()); |
| 117 |
|
} |
| 118 |
1
|
if (!failed) { |
| 119 |
0
|
fail("exception expected"); |
| 120 |
|
} |
| 121 |
|
} |
| 122 |
|
|
|
|
|
| 83,3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0,33 |
1
PASS
|
|
| 123 |
1
|
@Test... |
| 124 |
|
public void wrongArguments() { |
| 125 |
1
|
mock.simpleMethodWithArgument("3"); |
| 126 |
1
|
replay(mock); |
| 127 |
|
|
| 128 |
1
|
try { |
| 129 |
1
|
mock.simpleMethodWithArgument("5"); |
| 130 |
0
|
fail(); |
| 131 |
|
} catch (AssertionError expected) { |
| 132 |
1
|
assertEquals( |
| 133 |
|
"\n Unexpected method call simpleMethodWithArgument(\"5\"):" |
| 134 |
|
+ "\n simpleMethodWithArgument(\"3\"): expected: 1, actual: 0", |
| 135 |
|
expected.getMessage()); |
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
} |
| 139 |
|
|
|
|
|
| 85,7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0,29 |
1
PASS
|
|
| 140 |
1
|
@Test... |
| 141 |
|
public void summarizeSameObjectArguments() { |
| 142 |
1
|
mock.simpleMethodWithArgument("3"); |
| 143 |
1
|
mock.simpleMethodWithArgument("3"); |
| 144 |
1
|
replay(mock); |
| 145 |
|
|
| 146 |
1
|
try { |
| 147 |
1
|
mock.simpleMethodWithArgument("5"); |
| 148 |
0
|
fail(); |
| 149 |
|
} catch (AssertionError expected) { |
| 150 |
1
|
assertEquals( |
| 151 |
|
"\n Unexpected method call simpleMethodWithArgument(\"5\"):" |
| 152 |
|
+ "\n simpleMethodWithArgument(\"3\"): expected: 2, actual: 0", |
| 153 |
|
expected.getMessage()); |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
} |
| 157 |
|
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0,2 |
1
PASS
|
|
| 158 |
1
|
@Test... |
| 159 |
|
public void argumentsOrdered() { |
| 160 |
1
|
mock.simpleMethodWithArgument("4"); |
| 161 |
1
|
mock.simpleMethodWithArgument("3"); |
| 162 |
1
|
mock.simpleMethodWithArgument("2"); |
| 163 |
1
|
mock.simpleMethodWithArgument("0"); |
| 164 |
1
|
mock.simpleMethodWithArgument("1"); |
| 165 |
1
|
replay(mock); |
| 166 |
|
|
| 167 |
1
|
try { |
| 168 |
1
|
mock.simpleMethodWithArgument("5"); |
| 169 |
0
|
fail("exception expected"); |
| 170 |
|
} catch (AssertionError expected) { |
| 171 |
1
|
assertEquals( |
| 172 |
|
"\n Unexpected method call simpleMethodWithArgument(\"5\"):" |
| 173 |
|
+ "\n simpleMethodWithArgument(\"4\"): expected: 1, actual: 0" |
| 174 |
|
+ "\n simpleMethodWithArgument(\"3\"): expected: 1, actual: 0" |
| 175 |
|
+ "\n simpleMethodWithArgument(\"2\"): expected: 1, actual: 0" |
| 176 |
|
+ "\n simpleMethodWithArgument(\"0\"): expected: 1, actual: 0" |
| 177 |
|
+ "\n simpleMethodWithArgument(\"1\"): expected: 1, actual: 0", |
| 178 |
|
expected.getMessage()); |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
} |
| 182 |
|
|
|
|
|
| 92,3% |
Uncovered Elements: 2 (26) |
Complexity: 3 |
Complexity Density: 0,12 |
1
PASS
|
|
| 183 |
1
|
@Test... |
| 184 |
|
public void mixingOrderedAndUnordered() { |
| 185 |
1
|
mock.simpleMethodWithArgument("2"); |
| 186 |
1
|
mock.simpleMethodWithArgument("1"); |
| 187 |
1
|
checkOrder(mock, true); |
| 188 |
1
|
mock.simpleMethodWithArgument("3"); |
| 189 |
1
|
mock.simpleMethodWithArgument("4"); |
| 190 |
1
|
checkOrder(mock, false); |
| 191 |
1
|
mock.simpleMethodWithArgument("6"); |
| 192 |
1
|
mock.simpleMethodWithArgument("7"); |
| 193 |
1
|
mock.simpleMethodWithArgument("5"); |
| 194 |
|
|
| 195 |
1
|
replay(mock); |
| 196 |
|
|
| 197 |
1
|
mock.simpleMethodWithArgument("1"); |
| 198 |
1
|
mock.simpleMethodWithArgument("2"); |
| 199 |
|
|
| 200 |
1
|
boolean failed = false; |
| 201 |
1
|
try { |
| 202 |
1
|
mock.simpleMethodWithArgument("4"); |
| 203 |
|
} catch (AssertionError e) { |
| 204 |
1
|
failed = true; |
| 205 |
|
} |
| 206 |
1
|
if (!failed) { |
| 207 |
0
|
fail(); |
| 208 |
|
} |
| 209 |
|
|
| 210 |
1
|
mock.simpleMethodWithArgument("3"); |
| 211 |
1
|
mock.simpleMethodWithArgument("4"); |
| 212 |
1
|
mock.simpleMethodWithArgument("5"); |
| 213 |
1
|
mock.simpleMethodWithArgument("6"); |
| 214 |
1
|
mock.simpleMethodWithArgument("7"); |
| 215 |
|
|
| 216 |
1
|
verify(mock); |
| 217 |
|
|
| 218 |
|
} |
| 219 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0,25 |
1
PASS
|
|
| 220 |
1
|
@Test... |
| 221 |
|
public void resumeIfFailure() { |
| 222 |
1
|
IMethods mock = createMock(IMethods.class); |
| 223 |
1
|
expect(mock.oneArg(true)).andReturn("foo").anyTimes(); |
| 224 |
1
|
replay(mock); |
| 225 |
|
|
| 226 |
1
|
mock.oneArg(true); |
| 227 |
|
|
| 228 |
1
|
try { |
| 229 |
1
|
mock.simpleMethod(); |
| 230 |
|
} catch (AssertionError error) { |
| 231 |
|
} |
| 232 |
|
|
| 233 |
1
|
mock.oneArg(true); |
| 234 |
|
|
| 235 |
1
|
verify(mock); |
| 236 |
|
} |
| 237 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
1
PASS
|
|
| 238 |
1
|
@Test... |
| 239 |
|
public void defaultResetToNice() { |
| 240 |
1
|
IMethods mock = createMock(IMethods.class); |
| 241 |
|
|
| 242 |
1
|
expect(mock.oneArg(true)).andReturn("foo"); |
| 243 |
1
|
replay(mock); |
| 244 |
|
|
| 245 |
1
|
resetToNice(mock); |
| 246 |
|
|
| 247 |
1
|
replay(mock); |
| 248 |
|
|
| 249 |
1
|
assertNull(mock.oneArg(true)); |
| 250 |
|
|
| 251 |
1
|
verify(mock); |
| 252 |
|
} |
| 253 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0,09 |
1
PASS
|
|
| 254 |
1
|
@Test... |
| 255 |
|
public void strictResetToDefault() { |
| 256 |
1
|
IMethods mock = createStrictMock(IMethods.class); |
| 257 |
|
|
| 258 |
1
|
expect(mock.oneArg(true)).andReturn("foo"); |
| 259 |
1
|
expect(mock.oneArg(false)).andReturn("foo"); |
| 260 |
|
|
| 261 |
1
|
replay(mock); |
| 262 |
|
|
| 263 |
1
|
resetToDefault(mock); |
| 264 |
|
|
| 265 |
1
|
expect(mock.oneArg(false)).andReturn("foo"); |
| 266 |
1
|
expect(mock.oneArg(true)).andReturn("foo"); |
| 267 |
|
|
| 268 |
1
|
replay(mock); |
| 269 |
|
|
| 270 |
1
|
assertEquals("foo", mock.oneArg(false)); |
| 271 |
1
|
assertEquals("foo", mock.oneArg(true)); |
| 272 |
|
|
| 273 |
1
|
verify(mock); |
| 274 |
|
} |
| 275 |
|
|
|
|
|
| 92,9% |
Uncovered Elements: 1 (14) |
Complexity: 2 |
Complexity Density: 0,14 |
1
PASS
|
|
| 276 |
1
|
@Test... |
| 277 |
|
public void niceToStrict() { |
| 278 |
1
|
IMethods mock = createNiceMock(IMethods.class); |
| 279 |
|
|
| 280 |
1
|
expect(mock.oneArg(false)).andReturn("foo"); |
| 281 |
|
|
| 282 |
1
|
replay(mock); |
| 283 |
|
|
| 284 |
1
|
assertNull(mock.oneArg(true)); |
| 285 |
|
|
| 286 |
1
|
resetToStrict(mock); |
| 287 |
|
|
| 288 |
1
|
expect(mock.oneArg(false)).andReturn("foo"); |
| 289 |
1
|
expect(mock.oneArg(true)).andReturn("foo"); |
| 290 |
|
|
| 291 |
1
|
replay(mock); |
| 292 |
|
|
| 293 |
1
|
try { |
| 294 |
1
|
mock.oneArg(true); |
| 295 |
0
|
fail(); |
| 296 |
|
} |
| 297 |
|
catch(AssertionError e) { |
| 298 |
|
} |
| 299 |
|
|
| 300 |
1
|
assertEquals("foo", mock.oneArg(false)); |
| 301 |
1
|
assertEquals("foo", mock.oneArg(true)); |
| 302 |
|
|
| 303 |
1
|
verify(mock); |
| 304 |
|
} |
| 305 |
|
} |