| 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.Capture; |
| 11 |
|
import org.easymock.tests.IMethods; |
| 12 |
|
import org.junit.After; |
| 13 |
|
import org.junit.Before; |
| 14 |
|
import org.junit.Test; |
| 15 |
|
|
|
|
|
| 97,6% |
Uncovered Elements: 2 (82) |
Complexity: 9 |
Complexity Density: 0,12 |
|
| 16 |
|
public class CaptureTest { |
| 17 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
| 18 |
|
public static class A { |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 19 |
0
|
public String foo(IMethods methods) {... |
| 20 |
0
|
return methods.oneArg(2); |
| 21 |
|
} |
| 22 |
|
} |
| 23 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 24 |
5
|
@Before... |
| 25 |
|
public void setUp() throws Exception { |
| 26 |
|
} |
| 27 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 28 |
5
|
@After... |
| 29 |
|
public void tearDown() throws Exception { |
| 30 |
|
} |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
1
PASS
|
|
| 35 |
1
|
@Test... |
| 36 |
|
public void testCaptureRightOne() { |
| 37 |
1
|
Capture<String> captured = new Capture<String>(); |
| 38 |
1
|
IMethods mock = createMock(IMethods.class); |
| 39 |
|
|
| 40 |
1
|
expect(mock.oneArg(and(eq("test"), capture(captured)))).andReturn( |
| 41 |
|
"answer1"); |
| 42 |
1
|
expect(mock.oneArg("a")).andReturn("answer2"); |
| 43 |
|
|
| 44 |
1
|
replay(mock); |
| 45 |
|
|
| 46 |
1
|
assertEquals("answer2", mock.oneArg("a")); |
| 47 |
1
|
assertFalse(captured.hasCaptured()); |
| 48 |
|
|
| 49 |
1
|
assertEquals("answer1", mock.oneArg("test")); |
| 50 |
1
|
assertEquals("test", captured.getValue()); |
| 51 |
|
|
| 52 |
1
|
verify(mock); |
| 53 |
|
} |
| 54 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
1
PASS
|
|
| 55 |
1
|
@Test... |
| 56 |
|
public void testPrimitiveVsObject() { |
| 57 |
1
|
Capture<Integer> capture = new Capture<Integer>(); |
| 58 |
1
|
IMethods mock = createMock(IMethods.class); |
| 59 |
|
|
| 60 |
1
|
expect(mock.oneArg(capture(capture))).andReturn("answer"); |
| 61 |
1
|
expect(mock.oneArg((Integer) capture(capture))).andReturn("answer"); |
| 62 |
|
|
| 63 |
1
|
replay(mock); |
| 64 |
|
|
| 65 |
1
|
assertEquals("answer", mock.oneArg(2)); |
| 66 |
1
|
assertEquals(2, capture.getValue().intValue()); |
| 67 |
|
|
| 68 |
1
|
assertEquals("answer", mock.oneArg(Integer.valueOf(3))); |
| 69 |
1
|
assertEquals(3, capture.getValue().intValue()); |
| 70 |
|
|
| 71 |
1
|
verify(mock); |
| 72 |
|
} |
| 73 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0,14 |
1
PASS
|
|
| 74 |
1
|
@Test... |
| 75 |
|
public void testAnd() { |
| 76 |
1
|
Capture<String> captured = new Capture<String>(); |
| 77 |
1
|
IMethods mock = createMock(IMethods.class); |
| 78 |
|
|
| 79 |
1
|
expect(mock.oneArg(and(capture(captured), eq("test")))).andReturn( |
| 80 |
|
"answer"); |
| 81 |
|
|
| 82 |
1
|
replay(mock); |
| 83 |
|
|
| 84 |
1
|
assertEquals("answer", mock.oneArg("test")); |
| 85 |
1
|
assertEquals("test", captured.getValue()); |
| 86 |
|
|
| 87 |
1
|
verify(mock); |
| 88 |
|
} |
| 89 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 1 |
Complexity Density: 0,04 |
1
PASS
|
|
| 90 |
1
|
@Test... |
| 91 |
|
public void testPrimitive() { |
| 92 |
1
|
Capture<Integer> captureI = new Capture<Integer>(); |
| 93 |
1
|
Capture<Long> captureL = new Capture<Long>(); |
| 94 |
1
|
Capture<Float> captureF = new Capture<Float>(); |
| 95 |
1
|
Capture<Double> captureD = new Capture<Double>(); |
| 96 |
1
|
Capture<Byte> captureB = new Capture<Byte>(); |
| 97 |
1
|
Capture<Character> captureC = new Capture<Character>(); |
| 98 |
|
|
| 99 |
1
|
IMethods mock = createMock(IMethods.class); |
| 100 |
|
|
| 101 |
1
|
expect(mock.oneArg(capture(captureI))).andReturn("answerI"); |
| 102 |
1
|
expect(mock.oneArg(capture(captureL))).andReturn("answerL"); |
| 103 |
1
|
expect(mock.oneArg(capture(captureF))).andReturn("answerF"); |
| 104 |
1
|
expect(mock.oneArg(capture(captureD))).andReturn("answerD"); |
| 105 |
1
|
expect(mock.oneArg(capture(captureB))).andReturn("answerB"); |
| 106 |
1
|
expect(mock.oneArg(capture(captureC))).andReturn("answerC"); |
| 107 |
|
|
| 108 |
1
|
replay(mock); |
| 109 |
|
|
| 110 |
1
|
assertEquals("answerI", mock.oneArg(1)); |
| 111 |
1
|
assertEquals("answerL", mock.oneArg(2l)); |
| 112 |
1
|
assertEquals("answerF", mock.oneArg(3.0f)); |
| 113 |
1
|
assertEquals("answerD", mock.oneArg(4.0)); |
| 114 |
1
|
assertEquals("answerB", mock.oneArg((byte) 5)); |
| 115 |
1
|
assertEquals("answerC", mock.oneArg((char) 6)); |
| 116 |
|
|
| 117 |
1
|
assertEquals(1, captureI.getValue().intValue()); |
| 118 |
1
|
assertEquals(2l, captureL.getValue().longValue()); |
| 119 |
1
|
assertEquals(3.0f, captureF.getValue().floatValue(), 0.0); |
| 120 |
1
|
assertEquals(4.0, captureD.getValue().doubleValue(), 0.0); |
| 121 |
1
|
assertEquals((byte) 5, captureB.getValue().byteValue()); |
| 122 |
1
|
assertEquals((char) 6, captureC.getValue().charValue()); |
| 123 |
|
|
| 124 |
1
|
verify(mock); |
| 125 |
|
} |
| 126 |
|
|
|
|
|
| 90,5% |
Uncovered Elements: 2 (21) |
Complexity: 3 |
Complexity Density: 0,14 |
1
PASS
|
|
| 127 |
1
|
@Test... |
| 128 |
|
public void testCapture() { |
| 129 |
1
|
Capture<String> capture = new Capture<String>(); |
| 130 |
1
|
assertFalse(capture.hasCaptured()); |
| 131 |
1
|
try { |
| 132 |
1
|
capture.getValue(); |
| 133 |
0
|
fail("Should not be allowed"); |
| 134 |
|
} |
| 135 |
|
catch(AssertionError e) { |
| 136 |
1
|
assertEquals("Nothing captured yet", e.getMessage()); |
| 137 |
|
} |
| 138 |
1
|
assertEquals("Nothing captured yet", capture.toString()); |
| 139 |
1
|
capture.setValue("s"); |
| 140 |
1
|
assertTrue(capture.hasCaptured()); |
| 141 |
1
|
assertEquals("s", capture.getValue()); |
| 142 |
1
|
assertEquals("s", capture.toString()); |
| 143 |
1
|
capture.reset(); |
| 144 |
1
|
assertFalse(capture.hasCaptured()); |
| 145 |
1
|
try { |
| 146 |
1
|
capture.getValue(); |
| 147 |
0
|
fail("Should not be allowed"); |
| 148 |
|
} |
| 149 |
|
catch(AssertionError e) { |
| 150 |
1
|
assertEquals("Nothing captured yet", e.getMessage()); |
| 151 |
|
} |
| 152 |
|
|
| 153 |
1
|
capture.setValue(null); |
| 154 |
1
|
assertTrue(capture.hasCaptured()); |
| 155 |
1
|
assertNull(capture.getValue()); |
| 156 |
1
|
assertNull(capture.toString()); |
| 157 |
|
} |
| 158 |
|
} |