Package org.jmock

Class MockObjectTestCase

  • All Implemented Interfaces:
    junit.framework.Test
    Direct Known Subclasses:
    MockObjectTestCase

    public abstract class MockObjectTestCase
    extends MockObjectSupportTestCase
    A base class for tests that use Mock Objects. This class provides methods for creating mock objects and expectations and automatically verifying mock objects after the test has run but before the test fixture has been torn down.
    Since:
    1.0.0
    • Constructor Detail

      • MockObjectTestCase

        public MockObjectTestCase()
      • MockObjectTestCase

        public MockObjectTestCase​(java.lang.String name)
    • Method Detail

      • mock

        public Mock mock​(java.lang.Class mockedType)
        Creates a mock object that mocks the given type. The mock object is named after the type; the exact name is calculated by defaultMockNameForType(java.lang.Class).
        Parameters:
        mockedType - The type to be mocked.
        Returns:
        A Mock object that mocks mockedType.
      • mock

        public Mock mock​(java.lang.Class mockedType,
                         java.lang.String roleName)
        Creates a mock object that mocks the given type and is explicitly given a name. The mock object is named after the type; the exact name is calculated by defaultMockNameForType(java.lang.Class).
        Parameters:
        mockedType - The type to be mocked.
        roleName - The name of the mock object
        Returns:
        A Mock object that mocks mockedType.
      • newCoreMock

        protected DynamicMock newCoreMock​(java.lang.Class mockedType,
                                          java.lang.String roleName)
      • defaultMockNameForType

        public java.lang.String defaultMockNameForType​(java.lang.Class mockedType)
        Calculates
        Parameters:
        mockedType -
        Returns:
        mock name
      • returnValue

        public Stub returnValue​(java.lang.Object o)
      • returnValue

        public Stub returnValue​(boolean result)
      • returnValue

        public Stub returnValue​(byte result)
      • returnValue

        public Stub returnValue​(char result)
      • returnValue

        public Stub returnValue​(short result)
      • returnValue

        public Stub returnValue​(int result)
      • returnValue

        public Stub returnValue​(long result)
      • returnValue

        public Stub returnValue​(float result)
      • returnValue

        public Stub returnValue​(double result)
      • returnIterator

        public Stub returnIterator​(java.util.Collection collection)
      • returnIterator

        public Stub returnIterator​(java.lang.Object[] array)
      • throwException

        public Stub throwException​(java.lang.Throwable throwable)
      • onConsecutiveCalls

        public Stub onConsecutiveCalls​(Stub stub1,
                                       Stub stub2)
        Since:
        1.0.1
      • onConsecutiveCalls

        public Stub onConsecutiveCalls​(Stub stub1,
                                       Stub stub2,
                                       Stub stub3)
        Since:
        1.0.1
      • onConsecutiveCalls

        public Stub onConsecutiveCalls​(Stub stub1,
                                       Stub stub2,
                                       Stub stub3,
                                       Stub stub4)
        Since:
        1.0.1
      • onConsecutiveCalls

        public Stub onConsecutiveCalls​(Stub[] stubs)
        Since:
        1.1.0
      • doAll

        public Stub doAll​(Stub stub1,
                          Stub stub2)
        Since:
        1.1.0
      • doAll

        public Stub doAll​(Stub stub1,
                          Stub stub2,
                          Stub stub3)
        Since:
        1.1.0
      • doAll

        public Stub doAll​(Stub[] stubs)
        Since:
        1.1.0