⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractexpectation.java

📁 不管是测试驱动开发或者是其它的开发模式
💻 JAVA
字号:
/*  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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -