| 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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (33) |
Complexity: 6 |
Complexity Density: 0,2 |
|
| 14 |
|
public class StubTest { |
| 15 |
|
private IMethods mock; |
| 16 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 17 |
2
|
@Before... |
| 18 |
|
public void setup() { |
| 19 |
2
|
mock = createStrictMock(IMethods.class); |
| 20 |
|
} |
| 21 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0,07 |
1
PASS
|
|
| 22 |
1
|
@Test... |
| 23 |
|
public void stub() { |
| 24 |
1
|
mock.simpleMethodWithArgument("1"); |
| 25 |
1
|
expectLastCall().anyTimes(); |
| 26 |
1
|
mock.simpleMethodWithArgument("2"); |
| 27 |
1
|
expectLastCall().anyTimes(); |
| 28 |
1
|
mock.simpleMethodWithArgument("3"); |
| 29 |
1
|
expectLastCall().asStub(); |
| 30 |
|
|
| 31 |
1
|
replay(mock); |
| 32 |
|
|
| 33 |
1
|
mock.simpleMethodWithArgument("3"); |
| 34 |
1
|
mock.simpleMethodWithArgument("3"); |
| 35 |
1
|
mock.simpleMethodWithArgument("1"); |
| 36 |
1
|
mock.simpleMethodWithArgument("2"); |
| 37 |
1
|
mock.simpleMethodWithArgument("3"); |
| 38 |
1
|
mock.simpleMethodWithArgument("3"); |
| 39 |
|
|
| 40 |
1
|
verify(mock); |
| 41 |
|
|
| 42 |
|
} |
| 43 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 4 |
Complexity Density: 0,27 |
1
PASS
|
|
| 44 |
1
|
@Test... |
| 45 |
|
public void stubWithReturnValue() { |
| 46 |
1
|
expect(mock.oneArg("1")).andReturn("A").andStubReturn("B"); |
| 47 |
1
|
expect(mock.oneArg("2")).andThrow(new IllegalArgumentException()) |
| 48 |
|
.andStubThrow(new IllegalStateException()); |
| 49 |
|
|
| 50 |
1
|
replay(mock); |
| 51 |
|
|
| 52 |
1
|
assertEquals("A", mock.oneArg("1")); |
| 53 |
1
|
assertEquals("B", mock.oneArg("1")); |
| 54 |
1
|
assertEquals("B", mock.oneArg("1")); |
| 55 |
1
|
try { |
| 56 |
1
|
mock.oneArg("2"); |
| 57 |
|
} catch (IllegalArgumentException ignored) { |
| 58 |
|
} |
| 59 |
1
|
assertEquals("B", mock.oneArg("1")); |
| 60 |
1
|
try { |
| 61 |
1
|
mock.oneArg("2"); |
| 62 |
|
} catch (IllegalStateException ignored) { |
| 63 |
|
} |
| 64 |
1
|
assertEquals("B", mock.oneArg("1")); |
| 65 |
1
|
try { |
| 66 |
1
|
mock.oneArg("2"); |
| 67 |
|
} catch (IllegalStateException ignored) { |
| 68 |
|
} |
| 69 |
1
|
verify(mock); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
} |