= JUnitRuleMockery2
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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

[source,java]
.JUnitRuleMockery2.java
----
class JUnitRuleMockery2 {
  JUnitRuleMockery2 createFor(Mode mode)     // <.>
  Statement apply(Statement base, FrameworkMethod method, Object target)
  T getClassUnderTest()
  T ignoring(T mock)     // <.>
  T allowing(T mock)     // <.>
  T never(T mock)     // <.>
  void ignoring(Object... mocks)     // <.>
  Object oneOf(Object mock)     // <.>
  T checking(T mock, Class<? extends ExpectationsOn> expectationsClass)
  Expectations expectationsWith(Consumer<Expectations> initializer)
}
----

<.> xref:#createFor_Mode[createFor(Mode)]
+
--
Factory method.
--
<.> xref:#ignoring_T[ignoring(T)]
+
--
Ignoring any interaction with the mock; an allowing/ignoring mock will be returned in turn.
--
<.> xref:#allowing_T[allowing(T)]
+
--
Allow any interaction with the mock; an allowing mock will be returned in turn.
--
<.> xref:#never_T[never(T)]
+
--
Prohibit any interaction with the mock.
--
<.> xref:#ignoring_Object[ignoring(Object)]
+
--
Ignore a set of mocks.
--
<.> xref:#oneOf_Object[oneOf(Object)]
+
--
Require one interaction
--

== Members

[#createFor_Mode]
=== createFor(Mode)

Factory method.

[#ignoring_T]
=== ignoring(T)

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

[#allowing_T]
=== allowing(T)

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

[#never_T]
=== never(T)

Prohibit any interaction with the mock.

[#ignoring_Object]
=== ignoring(Object)

Ignore a set of mocks.

[#oneOf_Object]
=== oneOf(Object)

Require one interaction
