expectationdoublevaluetest.java

来自「不管是测试驱动开发或者是其它的开发模式」· Java 代码 · 共 85 行

JAVA
85
字号
/*  Copyright (c) 2000-2004 jMock.org
 */
package test.jmock.expectation;

import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.jmock.expectation.AssertMo;
import org.jmock.expectation.ExpectationDoubleValue;


public class ExpectationDoubleValueTest extends TestCase
{

    private ExpectationDoubleValue myExpectation =
            new ExpectationDoubleValue("ExpectationDoubleValue for testing");

    public void testExpectNothing() {
        myExpectation.setExpectNothing();

        assertTrue("Should have an expectation",
                   myExpectation.hasExpectations());
    }

    public void testExpectNothingFail() {
        myExpectation.setExpectNothing();

        try {
            myExpectation.setActual(100.0);
            fail("Should fail fast");
        }
        catch (AssertionFailedError ex) {
            // expected
        }

    }

    public void testFailOnVerify() {
        myExpectation.setExpected(0.0, 0.0);
        myExpectation.setFailOnVerify();

        myExpectation.setActual(1.0);
        AssertMo.assertVerifyFails(myExpectation);
    }

    public void testFlushActual() {
        myExpectation.setActual(10);

        myExpectation.setExpectNothing();

        myExpectation.verify();
    }

    public void testHasNoExpectations() {
        myExpectation.setActual(0.0);

        assertTrue("Has no expectations",
                   !myExpectation.hasExpectations());
    }

    public void testFailOutsideError() {
        myExpectation.setExpected(100.0, 1.0);

        try {
            myExpectation.setActual(102.0);
            fail("Should fail fast on double");
        }
        catch (AssertionFailedError ex) {
            //expected
        }

    }

    public void testPassOnError() {
        myExpectation.setExpected(100.0, 1.0);
        myExpectation.setActual(101.0);
        myExpectation.verify();
    }

    public void testPassWithinError() {
        myExpectation.setExpected(100.0, 1.0);
        myExpectation.setActual(100);
        myExpectation.verify();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?