Package org.jmock
Class MockObjectTestCase
- java.lang.Object
-
- junit.framework.Assert
-
- junit.framework.TestCase
-
- org.jmock.core.VerifyingTestCase
-
- org.jmock.core.MockObjectSupportTestCase
-
- org.jmock.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
-
-
Field Summary
-
Fields inherited from class org.jmock.core.MockObjectSupportTestCase
ANYTHING, NOT_NULL, NULL
-
-
Constructor Summary
Constructors Constructor Description MockObjectTestCase()MockObjectTestCase(java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InvocationMatcheratLeastOnce()InvocationMatcheratMostOnce()java.lang.StringdefaultMockNameForType(java.lang.Class mockedType)CalculatesStubdoAll(Stub[] stubs)StubdoAll(Stub stub1, Stub stub2)StubdoAll(Stub stub1, Stub stub2, Stub stub3)StubdoAll(Stub stub1, Stub stub2, Stub stub3, Stub stub4)InvocationMatcherexactly(int expectedCount)Mockmock(java.lang.Class mockedType)Creates a mock object that mocks the given type.Mockmock(java.lang.Class mockedType, java.lang.String roleName)Creates a mock object that mocks the given type and is explicitly given a name.InvocationMatchernever()InvocationMatchernever(java.lang.String errorMessage)protected DynamicMocknewCoreMock(java.lang.Class mockedType, java.lang.String roleName)java.lang.ObjectnewDummy(java.lang.Class dummyType)java.lang.ObjectnewDummy(java.lang.Class type, java.lang.String name)java.lang.ObjectnewDummy(java.lang.String name)InvocationMatcheronce()StubonConsecutiveCalls(Stub[] stubs)StubonConsecutiveCalls(Stub stub1, Stub stub2)StubonConsecutiveCalls(Stub stub1, Stub stub2, Stub stub3)StubonConsecutiveCalls(Stub stub1, Stub stub2, Stub stub3, Stub stub4)StubreturnIterator(java.lang.Object[] array)StubreturnIterator(java.util.Collection collection)StubreturnValue(boolean result)StubreturnValue(byte result)StubreturnValue(char result)StubreturnValue(double result)StubreturnValue(float result)StubreturnValue(int result)StubreturnValue(long result)StubreturnValue(short result)StubreturnValue(java.lang.Object o)StubthrowException(java.lang.Throwable throwable)-
Methods inherited from class org.jmock.core.MockObjectSupportTestCase
and, arrayContaining, arrayContaining, arrayContaining, arrayContaining, arrayContaining, arrayContaining, arrayContaining, arrayContaining, arrayContaining, arrayContaining, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, collectionContaining, collectionContaining, compatibleType, contains, endsWith, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq, hasProperty, hasProperty, isA, isIn, isIn, mapContaining, mapContaining, mapWithKey, mapWithKey, mapWithValue, mapWithValue, not, or, same, startsWith, stringContains, toString
-
Methods inherited from class org.jmock.core.VerifyingTestCase
registerToVerify, runBare, unregisterToVerify, verify
-
Methods inherited from class junit.framework.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runTest, setName, setUp, tearDown, toString
-
-
-
-
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 bydefaultMockNameForType(java.lang.Class).- Parameters:
mockedType- The type to be mocked.- Returns:
- A
Mockobject 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 bydefaultMockNameForType(java.lang.Class).- Parameters:
mockedType- The type to be mocked.roleName- The name of the mock object- Returns:
- A
Mockobject that mocks mockedType.
-
newCoreMock
protected DynamicMock newCoreMock(java.lang.Class mockedType, java.lang.String roleName)
-
newDummy
public java.lang.Object newDummy(java.lang.Class dummyType)
- Overrides:
newDummyin classMockObjectSupportTestCase
-
newDummy
public java.lang.Object newDummy(java.lang.Class type, java.lang.String name)- Overrides:
newDummyin classMockObjectSupportTestCase
-
newDummy
public java.lang.Object newDummy(java.lang.String name)
- Overrides:
newDummyin classMockObjectSupportTestCase
-
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)
-
once
public InvocationMatcher once()
-
atLeastOnce
public InvocationMatcher atLeastOnce()
-
atMostOnce
public InvocationMatcher atMostOnce()
-
exactly
public InvocationMatcher exactly(int expectedCount)
-
never
public InvocationMatcher never()
-
never
public InvocationMatcher never(java.lang.String errorMessage)
-
onConsecutiveCalls
public Stub onConsecutiveCalls(Stub stub1, Stub stub2, Stub stub3, Stub stub4)
- Since:
- 1.0.1
-
-