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

📄 expectationcountertest.java

📁 不管是测试驱动开发或者是其它的开发模式
💻 JAVA
字号:
/*  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.ExpectationCounter;


public class ExpectationCounterTest extends TestCase
{

    public void testExpectNothing() {
        ExpectationCounter e = new ExpectationCounter("");
        e.setExpectNothing();

        assertTrue("Has expectation", e.hasExpectations());
        e.verify();
    }

    public void testExpectNothingFailure() {
        ExpectationCounter e = new ExpectationCounter("");
        e.setExpectNothing();

        assertTrue("Has expectation", e.hasExpectations());
        try {
            e.inc();
        }
        catch (AssertionFailedError ex) {
            return;
        }
        fail("Should have failed immediately");
    }

    public void testFailImmediately() {
        ExpectationCounter aCounter = new ExpectationCounter("a test counter");
        aCounter.setExpected(1);

        aCounter.inc();
        try {
            aCounter.inc();
        }
        catch (AssertionFailedError ex) {
            return;
        }
        fail("Should have failed immediately");
    }

    public void testFailOnVerify() {
        ExpectationCounter aCounter = new ExpectationCounter("a test counter");
        aCounter.setExpected(1);
        aCounter.setFailOnVerify();

        aCounter.inc();
        aCounter.inc();

        AssertMo.assertVerifyFails(aCounter);
    }

    public void testFailure() {
        ExpectationCounter e = new ExpectationCounter("");
        e.setExpected(1);

        AssertMo.assertVerifyFails(e);
    }

    public void testFlushActual() {
        ExpectationCounter e = new ExpectationCounter("");
        e.inc();

        e.setExpected(1);
        e.inc();

        e.verify();
    }

    public void testHasNoExpectations() {
        ExpectationCounter aCounter = new ExpectationCounter("a test counter");

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

    public void testSuccess() {
        ExpectationCounter e = new ExpectationCounter("");
        e.setExpected(1);
        e.inc();

        e.verify();
    }
}

⌨️ 快捷键说明

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