org.jmock
Class MockObjectTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.jmock.core.VerifyingTestCase
              extended by org.jmock.core.MockObjectSupportTestCase
                  extended by org.jmock.MockObjectTestCase
All Implemented Interfaces:
Test
Direct Known Subclasses:
BadMethodNameAcceptanceTest, CascadedFailuresAcceptanceTest, ClassLoaderAcceptanceTest, CollectionsAcceptanceTest, ConsecutiveCallsAcceptanceTest, DoAllAcceptanceTest, DynamicMockExample, ErrorMessagesAcceptanceTest, ExpectNeverAcceptanceTest, InvokeAtMostOnceAcceptanceTest, InvokedExactCountAcceptanceTest, IsNullAcceptanceTest, MockObjectTestCase, OrderedInvocationsAcceptanceTest, ReturnTypeAcceptanceTest

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
MockObjectTestCase()
           
MockObjectTestCase(String name)
           
 
Method Summary
 InvocationMatcher atLeastOnce()
           
 InvocationMatcher atMostOnce()
           
 String defaultMockNameForType(Class mockedType)
          Calculates
 Stub doAll(Stub[] stubs)
           
 Stub doAll(Stub stub1, Stub stub2)
           
 Stub doAll(Stub stub1, Stub stub2, Stub stub3)
           
 Stub doAll(Stub stub1, Stub stub2, Stub stub3, Stub stub4)
           
 InvocationMatcher exactly(int expectedCount)
           
 Mock mock(Class mockedType)
          Creates a mock object that mocks the given type.
 Mock mock(Class mockedType, String roleName)
          Creates a mock object that mocks the given type and is explicitly given a name.
 InvocationMatcher never()
           
 InvocationMatcher never(String errorMessage)
           
protected  DynamicMock newCoreMock(Class mockedType, String roleName)
           
 Object newDummy(Class dummyType)
           
 Object newDummy(Class type, String name)
           
 Object newDummy(String name)
           
 InvocationMatcher once()
           
 Stub onConsecutiveCalls(Stub[] stubs)
           
 Stub onConsecutiveCalls(Stub stub1, Stub stub2)
           
 Stub onConsecutiveCalls(Stub stub1, Stub stub2, Stub stub3)
           
 Stub onConsecutiveCalls(Stub stub1, Stub stub2, Stub stub3, Stub stub4)
           
 Stub returnIterator(Collection collection)
           
 Stub returnIterator(Object[] array)
           
 Stub returnValue(boolean result)
           
 Stub returnValue(byte result)
           
 Stub returnValue(char result)
           
 Stub returnValue(double result)
           
 Stub returnValue(float result)
           
 Stub returnValue(int result)
           
 Stub returnValue(long result)
           
 Stub returnValue(Object o)
           
 Stub returnValue(short result)
           
 Stub throwException(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
countTestCases, createResult, getName, run, run, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
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, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MockObjectTestCase

public MockObjectTestCase()

MockObjectTestCase

public MockObjectTestCase(String name)
Method Detail

mock

public Mock mock(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(Class mockedType,
                 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(Class mockedType,
                                  String roleName)

newDummy

public Object newDummy(Class dummyType)
Overrides:
newDummy in class MockObjectSupportTestCase

newDummy

public Object newDummy(Class type,
                       String name)
Overrides:
newDummy in class MockObjectSupportTestCase

newDummy

public Object newDummy(String name)
Overrides:
newDummy in class MockObjectSupportTestCase

defaultMockNameForType

public String defaultMockNameForType(Class mockedType)
Calculates

Parameters:
mockedType -
Returns:
mock name

returnValue

public Stub returnValue(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(Collection collection)

returnIterator

public Stub returnIterator(Object[] array)

throwException

public Stub throwException(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(String errorMessage)

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 stub1,
                  Stub stub2,
                  Stub stub3,
                  Stub stub4)
Since:
1.1.0

doAll

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