public class Mockery
extends java.lang.Object
implements org.hamcrest.SelfDescribing
Modifier and Type | Class and Description |
---|---|
private class |
Mockery.MockObject |
Modifier and Type | Field and Description |
---|---|
private java.util.List<Invocation> |
actualInvocations |
private ReturnDefaultValueAction |
defaultAction |
private InvocationDispatcher |
dispatcher |
private ExpectationErrorTranslator |
expectationErrorTranslator |
private java.lang.Error |
firstError |
private Imposteriser |
imposteriser |
private java.util.Set<java.lang.String> |
mockNames |
private MockObjectNamingScheme |
namingScheme |
private ThreadingPolicy |
threadingPolicy |
Constructor and Description |
---|
Mockery() |
Modifier and Type | Method and Description |
---|---|
void |
addExpectation(Expectation expectation)
Adds an expected invocation that the object under test will perform upon
objects in its context during the test.
|
void |
assertIsSatisfied()
Fails the test if there are any expectations that have not been met.
|
void |
checking(ExpectationBuilder expectations)
Specifies the expected invocations that the object under test will perform upon
objects in its context during the test.
|
private void |
describeHistory(org.hamcrest.Description description) |
private void |
describeMismatch(Invocation invocation,
org.hamcrest.Description description) |
void |
describeTo(org.hamcrest.Description description) |
private java.lang.Object |
dispatch(Invocation invocation) |
private ExpectationError |
mismatchDescribing(ExpectationError e) |
<T> T |
mock(java.lang.Class<T> typeToMock)
Creates a mock object of type typeToMock and generates a name for it.
|
<T> T |
mock(java.lang.Class<T> typeToMock,
java.lang.String name)
Creates a mock object of type typeToMock with the given name.
|
Sequence |
sequence(java.lang.String name)
Returns a new sequence that is used to constrain the order in which
expectations can occur.
|
void |
setDefaultResultForType(java.lang.Class<?> type,
java.lang.Object result)
Sets the result returned for the given type when no return value has been explicitly
specified in the expectation.
|
void |
setExpectationErrorTranslator(ExpectationErrorTranslator expectationErrorTranslator)
Changes the expectation error translator used to translate expectation
errors into errors that report test failures.
|
void |
setImposteriser(Imposteriser imposteriser)
Changes the imposteriser used to adapt mock objects to the mocked type.
|
void |
setNamingScheme(MockObjectNamingScheme namingScheme)
Changes the naming scheme used to generate names for mock objects that
have not been explicitly named in the test.
|
void |
setThreadingPolicy(ThreadingPolicy threadingPolicy)
Changes the policy by which the Mockery copes with multiple threads.
|
States |
states(java.lang.String name)
Returns a new state machine that is used to constrain the order in which
expectations can occur.
|
private Imposteriser imposteriser
private ExpectationErrorTranslator expectationErrorTranslator
private MockObjectNamingScheme namingScheme
private ThreadingPolicy threadingPolicy
private final java.util.Set<java.lang.String> mockNames
private final ReturnDefaultValueAction defaultAction
private final java.util.List<Invocation> actualInvocations
private final InvocationDispatcher dispatcher
private java.lang.Error firstError
public void setDefaultResultForType(java.lang.Class<?> type, java.lang.Object result)
type
- The type for which to return result.result
- The value to return when a method of return type type
is invoked for which an explicit return value has has not been specified.public void setImposteriser(Imposteriser imposteriser)
imposteriser
- makes mockspublic void setNamingScheme(MockObjectNamingScheme namingScheme)
namingScheme
- names mocks for failure reportspublic void setExpectationErrorTranslator(ExpectationErrorTranslator expectationErrorTranslator)
ExpectationError
. Plug in a new expectation error
translator if you want your favourite test framework to report expectation
failures using its own error type.expectationErrorTranslator
- translator for your test frameworkpublic void setThreadingPolicy(ThreadingPolicy threadingPolicy)
threadingPolicy
- how to handle different threads.Synchroniser
public <T> T mock(java.lang.Class<T> typeToMock)
T
- is the class of the mocktypeToMock
- is the class of the mockpublic <T> T mock(java.lang.Class<T> typeToMock, java.lang.String name)
T
- is the class of the mocktypeToMock
- is the class of the mockname
- is the name of the mock object that will appear in failurespublic Sequence sequence(java.lang.String name)
name
- The name of the sequence.public States states(java.lang.String name)
name
- The name of the state machine.public void checking(ExpectationBuilder expectations)
expectations
- that will be checkedpublic void addExpectation(Expectation expectation)
expectation
- to checkpublic void assertIsSatisfied()
public void describeTo(org.hamcrest.Description description)
describeTo
in interface org.hamcrest.SelfDescribing
private void describeMismatch(Invocation invocation, org.hamcrest.Description description)
private void describeHistory(org.hamcrest.Description description)
private java.lang.Object dispatch(Invocation invocation) throws java.lang.Throwable
java.lang.Throwable
private ExpectationError mismatchDescribing(ExpectationError e)