| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
package org.easymock.tests; |
| 6 |
|
|
| 7 |
|
import static org.junit.Assert.*; |
| 8 |
|
|
| 9 |
|
import java.io.IOException; |
| 10 |
|
|
| 11 |
|
import org.easymock.MockControl; |
| 12 |
|
import org.easymock.internal.ReplayState; |
| 13 |
|
import org.junit.Before; |
| 14 |
|
import org.junit.Test; |
| 15 |
|
|
| 16 |
|
@SuppressWarnings("deprecation") |
|
|
|
| 83,6% |
Uncovered Elements: 11 (67) |
Complexity: 14 |
Complexity Density: 0,23 |
|
| 17 |
|
public class UsageVerifyTest { |
| 18 |
|
private MockControl<IMethods> control; |
| 19 |
|
|
| 20 |
|
private IMethods mock; |
| 21 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 22 |
3
|
@Before... |
| 23 |
|
public void setup() { |
| 24 |
3
|
control = MockControl.createControl(IMethods.class); |
| 25 |
3
|
mock = control.getMock(); |
| 26 |
|
} |
| 27 |
|
|
|
|
|
| 81% |
Uncovered Elements: 4 (21) |
Complexity: 4 |
Complexity Density: 0,21 |
1
PASS
|
|
| 28 |
1
|
@Test... |
| 29 |
|
public void twoReturns() { |
| 30 |
1
|
mock.throwsNothing(true); |
| 31 |
1
|
control.setReturnValue("Test"); |
| 32 |
1
|
control.setReturnValue("Test2"); |
| 33 |
|
|
| 34 |
1
|
control.replay(); |
| 35 |
|
|
| 36 |
1
|
assertEquals("Test", mock.throwsNothing(true)); |
| 37 |
|
|
| 38 |
1
|
boolean failed = true; |
| 39 |
|
|
| 40 |
1
|
try { |
| 41 |
1
|
control.verify(); |
| 42 |
0
|
failed = false; |
| 43 |
|
} catch (AssertionError expected) { |
| 44 |
1
|
assertEquals("\n Expectation failure on verify:" |
| 45 |
|
+ "\n throwsNothing(true): expected: 2, actual: 1", |
| 46 |
|
expected.getMessage()); |
| 47 |
1
|
assertTrue("stack trace must be filled in", Util.getStackTrace( |
| 48 |
|
expected).indexOf(ReplayState.class.getName()) == -1); |
| 49 |
|
} |
| 50 |
|
|
| 51 |
1
|
if (!failed) |
| 52 |
0
|
fail("AssertionError expected"); |
| 53 |
|
|
| 54 |
1
|
assertEquals("Test2", mock.throwsNothing(true)); |
| 55 |
|
|
| 56 |
1
|
control.verify(); |
| 57 |
|
|
| 58 |
1
|
try { |
| 59 |
1
|
mock.throwsNothing(true); |
| 60 |
0
|
fail("AssertionError expected"); |
| 61 |
|
} catch (AssertionError expected) { |
| 62 |
1
|
assertEquals("\n Unexpected method call throwsNothing(true):" |
| 63 |
|
+ "\n throwsNothing(true): expected: 2, actual: 2 (+1)", |
| 64 |
|
expected.getMessage()); |
| 65 |
|
} |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 91,7% |
Uncovered Elements: 1 (12) |
Complexity: 2 |
Complexity Density: 0,17 |
1
PASS
|
|
| 68 |
1
|
@Test... |
| 69 |
|
public void atLeastTwoReturns() { |
| 70 |
1
|
mock.throwsNothing(true); |
| 71 |
1
|
control.setReturnValue("Test"); |
| 72 |
1
|
control.setReturnValue("Test2", MockControl.ONE_OR_MORE); |
| 73 |
|
|
| 74 |
1
|
control.replay(); |
| 75 |
|
|
| 76 |
1
|
assertEquals("Test", mock.throwsNothing(true)); |
| 77 |
|
|
| 78 |
1
|
try { |
| 79 |
1
|
control.verify(); |
| 80 |
0
|
fail("AssertionError expected"); |
| 81 |
|
} catch (AssertionError expected) { |
| 82 |
|
|
| 83 |
1
|
assertEquals( |
| 84 |
|
"\n Expectation failure on verify:" |
| 85 |
|
+ "\n throwsNothing(true): expected: at least 2, actual: 1", |
| 86 |
|
expected.getMessage()); |
| 87 |
|
} |
| 88 |
|
|
| 89 |
1
|
assertEquals("Test2", mock.throwsNothing(true)); |
| 90 |
1
|
assertEquals("Test2", mock.throwsNothing(true)); |
| 91 |
|
|
| 92 |
1
|
control.verify(); |
| 93 |
|
} |
| 94 |
|
|
|
|
|
| 78,6% |
Uncovered Elements: 6 (28) |
Complexity: 7 |
Complexity Density: 0,25 |
1
PASS
|
|
| 95 |
1
|
@Test... |
| 96 |
|
public void twoThrows() throws IOException { |
| 97 |
1
|
mock.throwsIOException(0); |
| 98 |
1
|
control.setThrowable(new IOException()); |
| 99 |
1
|
control.setThrowable(new IOException()); |
| 100 |
1
|
mock.throwsIOException(1); |
| 101 |
1
|
control.setThrowable(new IOException()); |
| 102 |
|
|
| 103 |
1
|
control.replay(); |
| 104 |
|
|
| 105 |
1
|
try { |
| 106 |
1
|
mock.throwsIOException(0); |
| 107 |
0
|
fail("IOException expected"); |
| 108 |
|
} catch (IOException expected) { |
| 109 |
|
} |
| 110 |
|
|
| 111 |
1
|
try { |
| 112 |
1
|
control.verify(); |
| 113 |
0
|
fail("AssertionError expected"); |
| 114 |
|
} catch (AssertionError expected) { |
| 115 |
1
|
assertEquals("\n Expectation failure on verify:" |
| 116 |
|
+ "\n throwsIOException(0): expected: 2, actual: 1" |
| 117 |
|
+ "\n throwsIOException(1): expected: 1, actual: 0", |
| 118 |
|
expected.getMessage()); |
| 119 |
|
} |
| 120 |
|
|
| 121 |
1
|
try { |
| 122 |
1
|
mock.throwsIOException(0); |
| 123 |
0
|
fail("IOException expected"); |
| 124 |
|
} catch (IOException expected) { |
| 125 |
|
} |
| 126 |
|
|
| 127 |
1
|
try { |
| 128 |
1
|
control.verify(); |
| 129 |
0
|
fail("AssertionError expected"); |
| 130 |
|
} catch (AssertionError expected) { |
| 131 |
1
|
assertEquals("\n Expectation failure on verify:" |
| 132 |
|
+ "\n throwsIOException(1): expected: 1, actual: 0", |
| 133 |
|
expected.getMessage()); |
| 134 |
|
} |
| 135 |
|
|
| 136 |
1
|
try { |
| 137 |
1
|
mock.throwsIOException(1); |
| 138 |
0
|
fail("IOException expected"); |
| 139 |
|
} catch (IOException expected) { |
| 140 |
|
} |
| 141 |
|
|
| 142 |
1
|
control.verify(); |
| 143 |
|
|
| 144 |
1
|
try { |
| 145 |
1
|
mock.throwsIOException(0); |
| 146 |
0
|
fail("AssertionError expected"); |
| 147 |
|
} catch (AssertionError expected) { |
| 148 |
1
|
assertEquals( |
| 149 |
|
"\n Unexpected method call throwsIOException(0):" |
| 150 |
|
+ "\n throwsIOException(0): expected: 2, actual: 2 (+1)", |
| 151 |
|
expected.getMessage()); |
| 152 |
|
} |
| 153 |
|
} |
| 154 |
|
} |