|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ExpectationDoubleValue.java | 83.3% | 100% | 100% | 96.7% |
|
1 |
/* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
|
|
2 |
package org.jmock.expectation;
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
public class ExpectationDoubleValue extends AbstractExpectation { |
|
8 |
private Double expectedValue = null; |
|
9 |
private double expectedError = 0.0; |
|
10 |
private boolean expectNothing = false; |
|
11 |
private Double actualValue = null; |
|
12 |
|
|
13 |
|
|
14 | 16 |
public ExpectationDoubleValue(String name) {
|
15 | 16 |
super(name);
|
16 | 16 |
clearActual(); |
17 |
} |
|
18 |
|
|
19 | 36 |
public void clearActual() { |
20 | 36 |
actualValue = null;
|
21 |
} |
|
22 |
|
|
23 | 14 |
public void setActual(double value) { |
24 | 14 |
actualValue = new Double(value);
|
25 | 14 |
if (shouldCheckImmediately()) {
|
26 | 8 |
verify(); |
27 |
} |
|
28 |
} |
|
29 |
|
|
30 | 8 |
public void setExpected(double value, double error) { |
31 | 8 |
expectedValue = new Double(value);
|
32 | 8 |
expectedError = Math.abs(error); |
33 | 8 |
setHasExpectations(); |
34 |
} |
|
35 |
|
|
36 | 6 |
public void setExpectNothing() { |
37 | 6 |
expectNothing = true;
|
38 | 6 |
clearActual(); |
39 | 6 |
setHasExpectations(); |
40 |
} |
|
41 |
|
|
42 | 16 |
public void verify() { |
43 | 16 |
if (expectNothing) {
|
44 | 4 |
AssertMo.assertNull(myName + " expected no value",
|
45 |
actualValue); |
|
46 |
|
|
47 | 12 |
} else if (expectedValue != null) { |
48 | 12 |
AssertMo.assertNotNull(myName + " expected a value",
|
49 |
actualValue); |
|
50 |
|
|
51 | 12 |
double actualError = Math.abs(
|
52 |
actualValue.doubleValue() - expectedValue.doubleValue()); |
|
53 |
|
|
54 | 12 |
AssertMo.assertTrue( |
55 |
myName + " expected a value within " + expectedError +
|
|
56 |
" of " + expectedValue + ", was " + actualValue, |
|
57 |
actualError <= expectedError); |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
|
|