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

📄 testfailurematchertest.java

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

import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.jmock.core.Invocation;
import org.jmock.core.matcher.TestFailureMatcher;
import test.jmock.core.testsupport.MethodFactory;


public class TestFailureMatcherTest
        extends TestCase
{
    static final String MESSAGE = "MESSAGE";

    Invocation invocation;
    TestFailureMatcher testFailureMatcher;

    public void setUp() {
        MethodFactory methodFactory = new MethodFactory();

        invocation = new Invocation("INVOKED-OBJECT",
                                    methodFactory.newMethod("ignoredName", MethodFactory.NO_ARGUMENTS, void.class,
                                                            MethodFactory.NO_EXCEPTIONS),
                                    new Object[0]);

        testFailureMatcher = new TestFailureMatcher(MESSAGE);
    }

    public void testAlwaysMatches() {
        assertTrue("matches", testFailureMatcher.matches(invocation));
        invokeMatcher();
        assertTrue("matches", testFailureMatcher.matches(invocation));
    }

    public void testAlwaysVerifies() throws Throwable {
        testFailureMatcher.verify();
        invokeMatcher();
        testFailureMatcher.verify();
    }

    public void testThrowsAssertionFailedErrorWhenInvoked() throws Throwable {
        try {
            testFailureMatcher.invoked(invocation);
        }
        catch (AssertionFailedError ex) {
            assertEquals("should be error message from stub",
                         MESSAGE, ex.getMessage());
            return;
        }
        fail("expected AssertionFailedError");
    }

    public void testUsesErrorMessageAsDescription() {
        StringBuffer buffer = new StringBuffer();

        testFailureMatcher.describeTo(buffer);

        assertEquals("description", MESSAGE, buffer.toString());
    }

    private void invokeMatcher() {
        try {
            testFailureMatcher.invoked(invocation);
        }
        catch (AssertionFailedError ex) {
            // expected
        }
    }
}

⌨️ 快捷键说明

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