mockobjecttestcasetest.java

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

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

import junit.framework.TestCase;
import org.jmock.MockObjectTestCase;
import org.jmock.core.Verifiable;
import org.jmock.expectation.ExpectationList;


public class MockObjectTestCaseTest extends TestCase
{

    private class SampleMockObjectTestCase extends MockObjectTestCase
    {
        public void registerToVerify( Verifiable verifiable ) {
            requiresVerification.addActual(verifiable.toString());
        }

        public void testMethod() {
            // passes
        }
    }

    interface ExampleInterface
    {
        void expectedMethod();
    }

    private SampleMockObjectTestCase testCase;
    ExpectationList requiresVerification;

    public void setUp() {
        requiresVerification = new ExpectationList("registerToVerify #arguments");
        testCase = new SampleMockObjectTestCase()
        {
        };
    }

    public void testCanBeConstructedWithAName() {
        String name = "NAME";

        MockObjectTestCase namedTestCase = new MockObjectTestCase(name)
        {
        };

        assertEquals("name", name, namedTestCase.getName());
    }

    public void testRegistersAllMocksItCreatesForVerification() throws Throwable {
        // setup
        String roleName = "ROLE-NAME";

        // expect
        requiresVerification.addExpected(roleName);

        // execute
        testCase.mock(ExampleInterface.class, roleName);
        testCase.verify();

        // verify
        requiresVerification.verify();
    }
}

⌨️ 快捷键说明

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