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

📄 returnvalues.java

📁 不管是测试驱动开发或者是其它的开发模式
💻 JAVA
字号:
/*  Copyright (c) 2000-2004 jMock.org
 */
package org.jmock.expectation;

import java.util.Collection;
import java.util.Vector;
import junit.framework.AssertionFailedError;


/**
 * Sequence values as required by MockMaker
 * This is a generic class that should have been introduced to the mockobjects code stream instead of
 * being separately included in org.mockobjects.
 * It is possibly similar to a ReturnObjectList?
 */
public class ReturnValues
{
    private String myName;
    protected Vector myContents = new Vector();
    private boolean myKeepUsingLastReturnValue = false;

    public ReturnValues() {
        this("Generate me with a useful name!", true);
    }

    public ReturnValues( String name, boolean keepUsingLastReturnValue ) {
        myName = name;
        myKeepUsingLastReturnValue = keepUsingLastReturnValue;
    }

    public ReturnValues( boolean keepUsingLastReturnValue ) {
        this("Generate me with a useful name!", keepUsingLastReturnValue);
    }

    public void add( Object element ) {
        myContents.addElement(element);
    }

    public void addAll( Collection returnValues ) {
        myContents.addAll(returnValues);
    }

    public Object getNext() {
        if (myContents.isEmpty()) {
            throw new AssertionFailedError(getClass().getName() + "[" + myName + "] was not setup with enough values");
        }
        return pop();
    }

    public boolean isEmpty() {
        return myContents.size() == 0;
    }

    protected Object pop() {
        Object result = myContents.firstElement();
        boolean shouldNotRemoveElement = myContents.size() == 1 && myKeepUsingLastReturnValue;
        if (!shouldNotRemoveElement) {
            myContents.removeElementAt(0);
        }
        return result;
    }
}

⌨️ 快捷键说明

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