1 3 package org.jmock.expectation; 4 5 6 public class ExpectationDoubleValue extends AbstractExpectation 7 { 8 private Double expectedValue = null; 9 private double expectedError = 0.0; 10 private boolean expectNothing = false; 11 private Double actualValue = null; 12 13 14 public ExpectationDoubleValue( String name ) { 15 super(name); 16 clearActual(); 17 } 18 19 public void clearActual() { 20 actualValue = null; 21 } 22 23 public void setActual( double value ) { 24 actualValue = new Double (value); 25 if (shouldCheckImmediately()) { 26 verify(); 27 } 28 } 29 30 public void setExpected( double value, double error ) { 31 expectedValue = new Double (value); 32 expectedError = Math.abs(error); 33 setHasExpectations(); 34 } 35 36 public void setExpectNothing() { 37 expectNothing = true; 38 clearActual(); 39 setHasExpectations(); 40 } 41 42 public void verify() { 43 if (expectNothing) { 44 AssertMo.assertNull(myName + " expected no value", 45 actualValue); 46 47 } else if (expectedValue != null) { 48 AssertMo.assertNotNull(myName + " expected a value", 49 actualValue); 50 51 double actualError = Math.abs(actualValue.doubleValue() - expectedValue.doubleValue()); 52 53 AssertMo.assertTrue(myName + " expected a value within " + expectedError + 54 " of " + expectedValue + ", was " + actualValue, 55 actualError <= expectedError); 56 } 57 } 58 } 59 | Popular Tags |