Package org.jmock

Class AbstractExpectations

java.lang.Object
org.jmock.AbstractExpectations
All Implemented Interfaces:
ExpectationBuilder, ActionClause, ArgumentConstraintPhrases, CardinalityClause
Direct Known Subclasses:
Expectations

public abstract class AbstractExpectations extends Object implements ExpectationBuilder, CardinalityClause, ArgumentConstraintPhrases, ActionClause
Provides most of the syntax of jMock's "domain-specific language" API. The methods of this class don't make any sense on their own, so the Javadoc is rather sparse. Consult the documentation on the jMock website for information on how to use this API.
  • Field Details

  • Constructor Details

    • AbstractExpectations

      public AbstractExpectations()
  • Method Details

    • initialiseExpectationCapture

      private void initialiseExpectationCapture(Cardinality cardinality)
    • buildExpectations

      public void buildExpectations(Action defaultAction, ExpectationCollector collector)
      Specified by:
      buildExpectations in interface ExpectationBuilder
    • currentBuilder

      protected InvocationExpectationBuilder currentBuilder()
    • checkLastExpectationWasFullySpecified

      private void checkLastExpectationWasFullySpecified()
    • exactly

      public ReceiverClause exactly(int count)
      Specified by:
      exactly in interface CardinalityClause
    • oneOf

      public <T> T oneOf(T mockObject)
      Specified by:
      oneOf in interface CardinalityClause
    • one

      public <T> T one(T mockObject)
      Deprecated.
      Use oneOf instead.
      Specified by:
      one in interface CardinalityClause
    • atLeast

      public ReceiverClause atLeast(int count)
      Specified by:
      atLeast in interface CardinalityClause
    • between

      public ReceiverClause between(int minCount, int maxCount)
      Specified by:
      between in interface CardinalityClause
    • atMost

      public ReceiverClause atMost(int count)
      Specified by:
      atMost in interface CardinalityClause
    • allowing

      public MethodClause allowing(org.hamcrest.Matcher<?> mockObjectMatcher)
      Specified by:
      allowing in interface CardinalityClause
    • allowing

      public <T> T allowing(T mockObject)
      Specified by:
      allowing in interface CardinalityClause
    • ignoring

      public <T> T ignoring(T mockObject)
      Specified by:
      ignoring in interface CardinalityClause
    • ignoring

      public MethodClause ignoring(org.hamcrest.Matcher<?> mockObjectMatcher)
      Specified by:
      ignoring in interface CardinalityClause
    • never

      public <T> T never(T mockObject)
      Specified by:
      never in interface CardinalityClause
    • addParameterMatcher

      protected void addParameterMatcher(org.hamcrest.Matcher<?> matcher)
    • with

      public <T> T with(org.hamcrest.Matcher<T> matcher)
      For Matchers with primitive types use the with field, for example:
      with.intIs(equalTo(34));
      For untyped matchers use:
      with.<T>is(equalTo(anObject));
      Specified by:
      with in interface ArgumentConstraintPhrases
    • with

      public boolean with(boolean value)
    • with

      public byte with(byte value)
    • with

      public short with(short value)
    • with

      public char with(char value)
    • with

      public int with(int value)
    • with

      public long with(long value)
    • with

      public float with(float value)
    • with

      public double with(double value)
    • with

      public <T> T with(T value)
    • will

      public void will(Action action)
      Specified by:
      will in interface ActionClause
    • equal

      public static <T> org.hamcrest.Matcher<T> equal(T value)
    • same

      public static <T> org.hamcrest.Matcher<T> same(T value)
    • any

      public static <T> org.hamcrest.Matcher<T> any(Class<T> type)
    • anything

      public static <T> org.hamcrest.Matcher<T> anything()
    • a

      @Deprecated public static org.hamcrest.Matcher<Object> a(Class<?> type)
      Deprecated.
      use aNonNull(java.lang.Class<T>) or any(java.lang.Class<T>) until type inference actually works in a future version of Java
      Parameters:
      type - Class to match. Do not use for native parameters.
      Returns:
      an IsInstanceOf matcher
    • an

      @Deprecated public static org.hamcrest.Matcher<Object> an(Class<?> type)
      Deprecated.
      use aNonNull(java.lang.Class<T>) or any(java.lang.Class<T>) until type inference actually works in a future version of Java
      Parameters:
      type - Class to match. Do not use for native parameters.
      Returns:
      an IsInstanceOf matcher
    • aNull

      public static <T> org.hamcrest.Matcher<T> aNull(Class<T> type)
    • aNonNull

      public static <T> org.hamcrest.Matcher<T> aNonNull(Class<T> type)
    • returnValue

      public static Action returnValue(Object result)
    • throwException

      public static Action throwException(Throwable throwable)
    • returnIterator

      public static Action returnIterator(Collection<?> collection)
    • returnIterator

      public static <T> Action returnIterator(T... items)
    • returnEnumeration

      public static Action returnEnumeration(Collection<?> collection)
    • returnEnumeration

      public static <T> Action returnEnumeration(T... items)
    • doAll

      public static Action doAll(Action... actions)
    • onConsecutiveCalls

      public static Action onConsecutiveCalls(Action... actions)
    • when

      public void when(StatePredicate predicate)
    • then

      public void then(State state)
    • inSequence

      public void inSequence(Sequence sequence)
    • inSequences

      public void inSequences(Sequence... sequences)