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 classInvocationExpectation.AnyParametersMatcher
-
Field Summary
Fields Modifier and Type Field Description private Actionactionprivate booleanactionIsDefaultprivate static ParametersMatcherANY_PARAMETERSprivate Cardinalitycardinalityprivate intinvocationCountprivate booleanmethodIsKnownToBeVoidprivate org.hamcrest.Matcher<? super java.lang.reflect.Method>methodMatcherprivate org.hamcrest.Matcher<?>objectMatcherprivate java.util.List<OrderingConstraint>orderingConstraintsprivate ParametersMatcherparametersMatcherprivate java.util.List<SideEffect>sideEffects
-
Constructor Summary
Constructors Constructor Description InvocationExpectation()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddOrderingConstraint(OrderingConstraint orderingConstraint)voidaddSideEffect(SideEffect sideEffect)booleanallowsMoreInvocations()Can moreInvocations expected by this Expectation still occur?private voiddescribeExpectation(org.hamcrest.Description description)private voiddescribeMethod(org.hamcrest.Description description)voiddescribeMismatch(Invocation invocation, org.hamcrest.Description description)private voiddescribeSideEffects(org.hamcrest.Description description)voiddescribeTo(org.hamcrest.Description description)java.lang.Objectinvoke(Invocation invocation)Invokes the expectation: records that the invocation has occurred and fakes some behaviour in response.private booleanisInCorrectOrder()booleanisSatisfied()Have enoughInvocations expected by this Expectation occurred?booleanmatches(Invocation invocation)Can the Expectation be invoked with invocation?private voidperformSideEffects()voidsetAction(Action action)voidsetCardinality(Cardinality cardinality)voidsetDefaultAction(Action action)voidsetMethod(java.lang.reflect.Method method)voidsetMethodMatcher(org.hamcrest.Matcher<? super java.lang.reflect.Method> matcher)voidsetObjectMatcher(org.hamcrest.Matcher<?> objectMatcher)voidsetParametersMatcher(ParametersMatcher parametersMatcher)private booleanshouldSuppressActionDescription()
-
-
-
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:
describeToin interfaceorg.hamcrest.SelfDescribing
-
describeMismatch
public void describeMismatch(Invocation invocation, org.hamcrest.Description description)
- Specified by:
describeMismatchin 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:ExpectationHave enoughInvocations expected by this Expectation occurred?- Specified by:
isSatisfiedin interfaceExpectation- Returns:
trueif the expectation has received enough of its expected invocations,falseotherwise.
-
allowsMoreInvocations
public boolean allowsMoreInvocations()
Description copied from interface:ExpectationCan moreInvocations expected by this Expectation still occur?- Specified by:
allowsMoreInvocationsin interfaceExpectation- Returns:
trueif invocations expected by this expectation can still occur,falseotherwise.
-
matches
public boolean matches(Invocation invocation)
Description copied from interface:ExpectationCan the Expectation be invoked with invocation?- Specified by:
matchesin interfaceExpectation- Parameters:
invocation- to be matched- Returns:
trueif the expectation can be invoked with invocation,falseotherwise.
-
isInCorrectOrder
private boolean isInCorrectOrder()
-
invoke
public java.lang.Object invoke(Invocation invocation) throws java.lang.Throwable
Description copied from interface:ExpectationInvokes the expectation: records that the invocation has occurred and fakes some behaviour in response.- Specified by:
invokein 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()
-
-