| 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 (36) |
Complexity: 7 |
Complexity Density: 0,24 |
|
| 15 |
|
public class CallbackAndArgumentsTest { |
| 16 |
|
|
| 17 |
|
private IMethods mock; |
| 18 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 19 |
3
|
@Before... |
| 20 |
|
public void setUp() { |
| 21 |
3
|
mock = createStrictMock(IMethods.class); |
| 22 |
|
} |
| 23 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
1
PASS
|
|
| 24 |
1
|
@Test... |
| 25 |
|
public void callbackGetsArguments() { |
| 26 |
|
|
| 27 |
1
|
final StringBuffer buffer = new StringBuffer(); |
| 28 |
|
|
| 29 |
1
|
mock.simpleMethodWithArgument((String) notNull()); |
| 30 |
1
|
expectLastCall().andAnswer(new IAnswer<Object>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 31 |
2
|
public Object answer() {... |
| 32 |
2
|
buffer.append((String) getCurrentArguments()[0]); |
| 33 |
2
|
return null; |
| 34 |
|
} |
| 35 |
|
}).times(2); |
| 36 |
|
|
| 37 |
1
|
replay(mock); |
| 38 |
|
|
| 39 |
1
|
mock.simpleMethodWithArgument("1"); |
| 40 |
1
|
mock.simpleMethodWithArgument("2"); |
| 41 |
|
|
| 42 |
1
|
verify(mock); |
| 43 |
|
|
| 44 |
1
|
assertEquals("12", buffer.toString()); |
| 45 |
|
} |
| 46 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 47 |
1
|
@Test(expected = IllegalStateException.class)... |
| 48 |
|
public void currentArgumentsFailsOutsideCallbacks() { |
| 49 |
1
|
getCurrentArguments(); |
| 50 |
|
} |
| 51 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0,08 |
1
PASS
|
|
| 52 |
1
|
@Test... |
| 53 |
|
public void callbackGetsArgumentsEvenIfAMockCallsAnother() { |
| 54 |
|
|
| 55 |
1
|
final StringBuffer buffer = new StringBuffer(); |
| 56 |
|
|
| 57 |
1
|
final IMethods mock2 = createStrictMock(IMethods.class); |
| 58 |
1
|
mock2.simpleMethod(); |
| 59 |
1
|
expectLastCall().andAnswer(new IAnswer<Object>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 60 |
2
|
public Object answer() {... |
| 61 |
|
|
| 62 |
2
|
return null; |
| 63 |
|
} |
| 64 |
|
}).times(2); |
| 65 |
|
|
| 66 |
1
|
mock.simpleMethodWithArgument((String) notNull()); |
| 67 |
1
|
expectLastCall().andAnswer(new IAnswer<Object>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
| 68 |
2
|
public Object answer() {... |
| 69 |
2
|
mock2.simpleMethod(); |
| 70 |
2
|
buffer.append((String) getCurrentArguments()[0]); |
| 71 |
2
|
return null; |
| 72 |
|
} |
| 73 |
|
}).times(2); |
| 74 |
|
|
| 75 |
1
|
replay(mock); |
| 76 |
1
|
replay(mock2); |
| 77 |
|
|
| 78 |
1
|
mock.simpleMethodWithArgument("1"); |
| 79 |
1
|
mock.simpleMethodWithArgument("2"); |
| 80 |
|
|
| 81 |
1
|
verify(mock); |
| 82 |
1
|
verify(mock2); |
| 83 |
|
|
| 84 |
1
|
assertEquals("12", buffer.toString()); |
| 85 |
|
} |
| 86 |
|
} |