| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
package org.easymock.tests; |
| 6 |
|
|
| 7 |
|
import static org.easymock.EasyMock.*; |
| 8 |
|
import static org.junit.Assert.*; |
| 9 |
|
|
| 10 |
|
import org.easymock.MockControl; |
| 11 |
|
import org.junit.Before; |
| 12 |
|
import org.junit.Test; |
| 13 |
|
|
| 14 |
|
@SuppressWarnings("deprecation") |
|
|
|
| 96,9% |
Uncovered Elements: 2 (64) |
Complexity: 8 |
Complexity Density: 0,14 |
|
| 15 |
|
public class UsageDefaultReturnValueTest { |
| 16 |
|
MockControl<IMethods> control; |
| 17 |
|
|
| 18 |
|
IMethods mock; |
| 19 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 20 |
5
|
@Before... |
| 21 |
|
public void setup() { |
| 22 |
5
|
control = MockControl.createControl(IMethods.class); |
| 23 |
5
|
mock = control.getMock(); |
| 24 |
|
} |
| 25 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0,07 |
1
PASS
|
|
| 26 |
1
|
@Test... |
| 27 |
|
public void defaultReturnValue() { |
| 28 |
1
|
mock.threeArgumentMethod(7, "", "test"); |
| 29 |
1
|
control.setReturnValue("test", 1); |
| 30 |
|
|
| 31 |
1
|
mock.threeArgumentMethod(8, null, "test2"); |
| 32 |
1
|
control.setReturnValue("test2", 1); |
| 33 |
|
|
| 34 |
1
|
Object defaultValue = new Object(); |
| 35 |
1
|
control.setDefaultReturnValue(defaultValue); |
| 36 |
|
|
| 37 |
1
|
control.replay(); |
| 38 |
1
|
assertEquals("test", mock.threeArgumentMethod(7, "", "test")); |
| 39 |
1
|
assertEquals("test2", mock.threeArgumentMethod(8, null, "test2")); |
| 40 |
1
|
assertSame(defaultValue, mock.threeArgumentMethod(7, new Object(), |
| 41 |
|
"test")); |
| 42 |
1
|
assertSame(defaultValue, mock.threeArgumentMethod(7, "", "test")); |
| 43 |
1
|
assertSame(defaultValue, mock.threeArgumentMethod(8, null, "test")); |
| 44 |
1
|
assertSame(defaultValue, mock.threeArgumentMethod(9, null, "test")); |
| 45 |
|
|
| 46 |
1
|
control.verify(); |
| 47 |
|
} |
| 48 |
|
|
|
|
|
| 92,3% |
Uncovered Elements: 1 (13) |
Complexity: 2 |
Complexity Density: 0,15 |
1
PASS
|
|
| 49 |
1
|
@Test... |
| 50 |
|
public void defaultVoidCallable() { |
| 51 |
|
|
| 52 |
1
|
mock.twoArgumentMethod(1, 2); |
| 53 |
1
|
control.setDefaultVoidCallable(); |
| 54 |
|
|
| 55 |
1
|
mock.twoArgumentMethod(1, 1); |
| 56 |
1
|
RuntimeException expected = new RuntimeException(); |
| 57 |
1
|
control.setThrowable(expected); |
| 58 |
|
|
| 59 |
1
|
control.replay(); |
| 60 |
1
|
mock.twoArgumentMethod(2, 1); |
| 61 |
1
|
mock.twoArgumentMethod(1, 2); |
| 62 |
1
|
mock.twoArgumentMethod(3, 7); |
| 63 |
|
|
| 64 |
1
|
try { |
| 65 |
1
|
mock.twoArgumentMethod(1, 1); |
| 66 |
0
|
fail("RuntimeException expected"); |
| 67 |
|
} catch (RuntimeException actual) { |
| 68 |
1
|
assertSame(expected, actual); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
} |
| 72 |
|
|
|
|
|
| 92,3% |
Uncovered Elements: 1 (13) |
Complexity: 2 |
Complexity Density: 0,15 |
1
PASS
|
|
| 73 |
1
|
@Test... |
| 74 |
|
public void defaultThrowable() { |
| 75 |
1
|
mock.twoArgumentMethod(1, 2); |
| 76 |
1
|
control.setVoidCallable(); |
| 77 |
1
|
mock.twoArgumentMethod(1, 1); |
| 78 |
1
|
control.setVoidCallable(); |
| 79 |
|
|
| 80 |
1
|
RuntimeException expected = new RuntimeException(); |
| 81 |
1
|
control.setDefaultThrowable(expected); |
| 82 |
|
|
| 83 |
1
|
control.replay(); |
| 84 |
|
|
| 85 |
1
|
mock.twoArgumentMethod(1, 2); |
| 86 |
1
|
mock.twoArgumentMethod(1, 1); |
| 87 |
1
|
try { |
| 88 |
1
|
mock.twoArgumentMethod(2, 1); |
| 89 |
0
|
fail("RuntimeException expected"); |
| 90 |
|
} catch (RuntimeException actual) { |
| 91 |
1
|
assertSame(expected, actual); |
| 92 |
|
} |
| 93 |
|
} |
| 94 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
1
PASS
|
|
| 95 |
1
|
@Test... |
| 96 |
|
public void defaultReturnValueBoolean() { |
| 97 |
1
|
mock.booleanReturningMethod(12); |
| 98 |
1
|
control.setReturnValue(true); |
| 99 |
1
|
control.setDefaultReturnValue(false); |
| 100 |
|
|
| 101 |
1
|
control.replay(); |
| 102 |
|
|
| 103 |
1
|
assertFalse(mock.booleanReturningMethod(11)); |
| 104 |
1
|
assertTrue(mock.booleanReturningMethod(12)); |
| 105 |
1
|
assertFalse(mock.booleanReturningMethod(13)); |
| 106 |
|
|
| 107 |
1
|
control.verify(); |
| 108 |
|
} |
| 109 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
1
PASS
|
|
| 110 |
1
|
@Test... |
| 111 |
|
public void returnValueAndDefaultReturnValue() throws Exception { |
| 112 |
|
|
| 113 |
1
|
mock.oneArg(""); |
| 114 |
|
|
| 115 |
1
|
expectLastCall().andReturn("1"); |
| 116 |
1
|
control.setDefaultReturnValue("2"); |
| 117 |
|
|
| 118 |
1
|
control.replay(); |
| 119 |
|
|
| 120 |
1
|
assertEquals("1", mock.oneArg("")); |
| 121 |
1
|
assertEquals("2", mock.oneArg("")); |
| 122 |
1
|
assertEquals("2", mock.oneArg("X")); |
| 123 |
|
|
| 124 |
1
|
control.verify(); |
| 125 |
|
} |
| 126 |
|
} |