abstractexpectation.java

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

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

import org.jmock.core.Verifiable;


abstract public class AbstractExpectation implements Verifiable, Expectation
{
    protected boolean myFailureModeIsImmediate = true;
    protected String myName;

    private boolean myHasExpectations = false;

    public AbstractExpectation( String name ) {
        myName = name;
    }

    protected void assertEquals( String msg,
                                 int expectedValue,
                                 int actualValue ) {
        assertEquals(msg, new Integer(expectedValue), new Integer(actualValue));
    }

    /**
     * Due to junit Assert being a Singleton implemented with static methods, and java's
     * unfortunate implementation of class methods (e.g. no late binding) it is
     * necessary to re-implement this invokedMethod here instead of over-riding failNotEquals
     */

    protected void assertEquals( String msg,
                                 Object expectedValue,
                                 Object actualValue ) {
        if (!myHasExpectations) {
            return;
        }

        if (expectedValue == null && actualValue == null) {
            return;
        }

        if (expectedValue != null && expectedValue.equals(actualValue)) {
            return;
        }

        junit.framework.Assert.fail(myName
                                    + " "
                                    + msg
                                    + "\nExpected: "
                                    + expectedValue
                                    + "\nReceived: "
                                    + actualValue);

    }

    abstract public void clearActual();

    public boolean hasExpectations() {
        return myHasExpectations;
    }

    public void setFailOnVerify() {
        myFailureModeIsImmediate = false;
    }

    protected void setHasExpectations() {
        clearActual();
        myHasExpectations = true;
    }

    protected boolean shouldCheckImmediately() {
        return myFailureModeIsImmediate && myHasExpectations;
    }

    public abstract void verify();
}

⌨️ 快捷键说明

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