Package org.jmock.internal
Class InvocationExpectation
- java.lang.Object
-
- org.jmock.internal.InvocationExpectation
-
- All Implemented Interfaces:
org.hamcrest.SelfDescribing
,Expectation
public class InvocationExpectation extends java.lang.Object implements Expectation
An expectation of zero or more matching invocations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
InvocationExpectation.AnyParametersMatcher
-
Field Summary
Fields Modifier and Type Field Description private Action
action
private boolean
actionIsDefault
private static ParametersMatcher
ANY_PARAMETERS
private Cardinality
cardinality
private int
invocationCount
private boolean
methodIsKnownToBeVoid
private org.hamcrest.Matcher<? super java.lang.reflect.Method>
methodMatcher
private org.hamcrest.Matcher<?>
objectMatcher
private java.util.List<OrderingConstraint>
orderingConstraints
private ParametersMatcher
parametersMatcher
private java.util.List<SideEffect>
sideEffects
-
Constructor Summary
Constructors Constructor Description InvocationExpectation()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOrderingConstraint(OrderingConstraint orderingConstraint)
void
addSideEffect(SideEffect sideEffect)
boolean
allowsMoreInvocations()
Can moreInvocation
s expected by this Expectation still occur?private void
describeExpectation(org.hamcrest.Description description)
private void
describeMethod(org.hamcrest.Description description)
void
describeMismatch(Invocation invocation, org.hamcrest.Description description)
private void
describeSideEffects(org.hamcrest.Description description)
void
describeTo(org.hamcrest.Description description)
java.lang.Object
invoke(Invocation invocation)
Invokes the expectation: records that the invocation has occurred and fakes some behaviour in response.private boolean
isInCorrectOrder()
boolean
isSatisfied()
Have enoughInvocation
s expected by this Expectation occurred?boolean
matches(Invocation invocation)
Can the Expectation be invoked with invocation?private void
performSideEffects()
void
setAction(Action action)
void
setCardinality(Cardinality cardinality)
void
setDefaultAction(Action action)
void
setMethod(java.lang.reflect.Method method)
void
setMethodMatcher(org.hamcrest.Matcher<? super java.lang.reflect.Method> matcher)
void
setObjectMatcher(org.hamcrest.Matcher<?> objectMatcher)
void
setParametersMatcher(ParametersMatcher parametersMatcher)
private boolean
shouldSuppressActionDescription()
-
-
-
Field Detail
-
ANY_PARAMETERS
private static ParametersMatcher ANY_PARAMETERS
-
cardinality
private Cardinality cardinality
-
objectMatcher
private org.hamcrest.Matcher<?> objectMatcher
-
methodMatcher
private org.hamcrest.Matcher<? super java.lang.reflect.Method> methodMatcher
-
methodIsKnownToBeVoid
private boolean methodIsKnownToBeVoid
-
parametersMatcher
private ParametersMatcher parametersMatcher
-
action
private Action action
-
actionIsDefault
private boolean actionIsDefault
-
orderingConstraints
private java.util.List<OrderingConstraint> orderingConstraints
-
sideEffects
private java.util.List<SideEffect> sideEffects
-
invocationCount
private int invocationCount
-
-
Method Detail
-
setCardinality
public void setCardinality(Cardinality cardinality)
-
setObjectMatcher
public void setObjectMatcher(org.hamcrest.Matcher<?> objectMatcher)
-
setMethod
public void setMethod(java.lang.reflect.Method method)
-
setMethodMatcher
public void setMethodMatcher(org.hamcrest.Matcher<? super java.lang.reflect.Method> matcher)
-
setParametersMatcher
public void setParametersMatcher(ParametersMatcher parametersMatcher)
-
addOrderingConstraint
public void addOrderingConstraint(OrderingConstraint orderingConstraint)
-
addSideEffect
public void addSideEffect(SideEffect sideEffect)
-
setAction
public void setAction(Action action)
-
setDefaultAction
public void setDefaultAction(Action action)
-
describeTo
public void describeTo(org.hamcrest.Description description)
- Specified by:
describeTo
in interfaceorg.hamcrest.SelfDescribing
-
describeMismatch
public void describeMismatch(Invocation invocation, org.hamcrest.Description description)
- Specified by:
describeMismatch
in interfaceExpectation
-
describeExpectation
private void describeExpectation(org.hamcrest.Description description)
-
describeMethod
private void describeMethod(org.hamcrest.Description description)
-
describeSideEffects
private void describeSideEffects(org.hamcrest.Description description)
-
shouldSuppressActionDescription
private boolean shouldSuppressActionDescription()
-
isSatisfied
public boolean isSatisfied()
Description copied from interface:Expectation
Have enoughInvocation
s expected by this Expectation occurred?- Specified by:
isSatisfied
in interfaceExpectation
- Returns:
true
if the expectation has received enough of its expected invocations,false
otherwise.
-
allowsMoreInvocations
public boolean allowsMoreInvocations()
Description copied from interface:Expectation
Can moreInvocation
s expected by this Expectation still occur?- Specified by:
allowsMoreInvocations
in interfaceExpectation
- Returns:
true
if invocations expected by this expectation can still occur,false
otherwise.
-
matches
public boolean matches(Invocation invocation)
Description copied from interface:Expectation
Can the Expectation be invoked with invocation?- Specified by:
matches
in interfaceExpectation
- Parameters:
invocation
- to be matched- Returns:
true
if the expectation can be invoked with invocation,false
otherwise.
-
isInCorrectOrder
private boolean isInCorrectOrder()
-
invoke
public java.lang.Object invoke(Invocation invocation) throws java.lang.Throwable
Description copied from interface:Expectation
Invokes the expectation: records that the invocation has occurred and fakes some behaviour in response.- Specified by:
invoke
in interfaceExpectation
- Parameters:
invocation
- The invocation to record and fake.- Returns:
- A result that is eventually returned from the method call that caused the invocation.
- Throws:
java.lang.Throwable
- An exception that is eventually thrown from the method call that caused the invocation.java.lang.IllegalStateException
- The expectation has been invoked with a method that it doesn't match or the faked behaviour has been set up incorrectly. For example, IllegalStateException is thrown when trying to return a value or throw a checked exception that is incompatible with the return type of the method being mocked
-
performSideEffects
private void performSideEffects()
-
-