JUnitRuleMockery2

Use as a @Rule , meaning that the @RunWith(JMock.class) can be ignored.

public class MyTest {

    @Rule
    public final Junit4Mockery2 context = Junit4Mockery2.createFor(Mode.INTERFACES);

}

The class also adds some convenience methods, and uses a factory method to make it explicit whether the context can mock only interfaces or interfaces and classes.

API

JUnitRuleMockery2.java
class JUnitRuleMockery2 {
  JUnitRuleMockery2 createFor(Mode mode)     (1)
  Statement apply(Statement base, FrameworkMethod method, Object target)
  T getClassUnderTest()
  T ignoring(T mock)     (2)
  T allowing(T mock)     (3)
  T never(T mock)     (4)
  void ignoring(Object... mocks)     (5)
  Object oneOf(Object mock)     (6)
  T checking(T mock, Class<? extends ExpectationsOn> expectationsClass)
  Expectations expectationsWith(Consumer<Expectations> initializer)
}
1 createFor(Mode)

Factory method.

2 ignoring(T)

Ignoring any interaction with the mock; an allowing/ignoring mock will be returned in turn.

3 allowing(T)

Allow any interaction with the mock; an allowing mock will be returned in turn.

4 never(T)

Prohibit any interaction with the mock.

5 ignoring(Object)

Ignore a set of mocks.

6 oneOf(Object)

Require one interaction

Members

createFor(Mode)

Factory method.

ignoring(T)

Ignoring any interaction with the mock; an allowing/ignoring mock will be returned in turn.

allowing(T)

Allow any interaction with the mock; an allowing mock will be returned in turn.

never(T)

Prohibit any interaction with the mock.

ignoring(Object)

Ignore a set of mocks.

oneOf(Object)

Require one interaction