View Javadoc
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 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( 52 actualValue.doubleValue() - expectedValue.doubleValue()); 53 54 AssertMo.assertTrue( 55 myName + " expected a value within " + expectedError + 56 " of " + expectedValue + ", was " + actualValue, 57 actualError <= expectedError); 58 } 59 } 60 }

This page was automatically generated by Maven