| 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.IAnswer; |
| 11 |
|
import org.easymock.tests.IMethods; |
| 12 |
|
import org.junit.Before; |
| 13 |
|
import org.junit.Test; |
| 14 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 6 |
Complexity Density: 0,22 |
|
| 15 |
|
public class CallbackTest { |
| 16 |
|
|
| 17 |
|
private IMethods mock; |
| 18 |
|
|
|
|
|
| 87,5% |
Uncovered Elements: 1 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
| 19 |
|
private static class Callback<T> implements IAnswer<T> { |
| 20 |
|
private int callCount; |
| 21 |
|
|
| 22 |
|
private T result; |
| 23 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 24 |
3
|
public Callback(T result) {... |
| 25 |
3
|
this.result = result; |
| 26 |
|
} |
| 27 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 28 |
0
|
public void run() {... |
| 29 |
|
} |
| 30 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 31 |
3
|
public int getCallCount() {... |
| 32 |
3
|
return callCount; |
| 33 |
|
} |
| 34 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 35 |
5
|
public T answer() throws Throwable {... |
| 36 |
5
|
callCount++; |
| 37 |
5
|
return result; |
| 38 |
|
} |
| 39 |
|
} |
| 40 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 41 |
1
|
@Before... |
| 42 |
|
public void setUp() { |
| 43 |
1
|
mock = createStrictMock(IMethods.class); |
| 44 |
|
} |
| 45 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 5 |
Complexity Density: 0,19 |
1
PASS
|
|
| 46 |
1
|
@Test... |
| 47 |
|
public void callback() { |
| 48 |
1
|
Callback<String> c1 = new Callback<String>("1"); |
| 49 |
1
|
Callback<Object> c2 = new Callback<Object>(null); |
| 50 |
1
|
Callback<Object> c3 = new Callback<Object>(null); |
| 51 |
|
|
| 52 |
1
|
expect(mock.oneArg("2")).andAnswer(c1).times(2); |
| 53 |
1
|
mock.simpleMethodWithArgument("One"); |
| 54 |
1
|
expectLastCall().andAnswer(c2); |
| 55 |
1
|
mock.simpleMethodWithArgument("Two"); |
| 56 |
1
|
expectLastCall().andAnswer(c3).times(2); |
| 57 |
|
|
| 58 |
1
|
replay(mock); |
| 59 |
|
|
| 60 |
1
|
mock.oneArg("2"); |
| 61 |
1
|
mock.oneArg("2"); |
| 62 |
1
|
try { |
| 63 |
1
|
mock.oneArg("2"); |
| 64 |
|
} catch (AssertionError ignored) { |
| 65 |
|
} |
| 66 |
1
|
try { |
| 67 |
1
|
mock.simpleMethodWithArgument("Two"); |
| 68 |
|
} catch (AssertionError ignored) { |
| 69 |
|
} |
| 70 |
1
|
mock.simpleMethodWithArgument("One"); |
| 71 |
1
|
try { |
| 72 |
1
|
mock.simpleMethodWithArgument("One"); |
| 73 |
|
} catch (AssertionError ignored) { |
| 74 |
|
} |
| 75 |
1
|
mock.simpleMethodWithArgument("Two"); |
| 76 |
1
|
mock.simpleMethodWithArgument("Two"); |
| 77 |
1
|
try { |
| 78 |
1
|
mock.simpleMethodWithArgument("Two"); |
| 79 |
|
} catch (AssertionError ignored) { |
| 80 |
|
} |
| 81 |
1
|
verify(mock); |
| 82 |
|
|
| 83 |
1
|
assertEquals(2, c1.getCallCount()); |
| 84 |
1
|
assertEquals(1, c2.getCallCount()); |
| 85 |
1
|
assertEquals(2, c3.getCallCount()); |
| 86 |
|
} |
| 87 |
|
} |