Package org.jmock.integration.junit4
Class JUnitRuleMockery
- java.lang.Object
-
- org.jmock.Mockery
-
- org.jmock.integration.junit4.JUnit4Mockery
-
- org.jmock.integration.junit4.JUnitRuleMockery
-
- All Implemented Interfaces:
org.hamcrest.SelfDescribing
,org.junit.rules.MethodRule
public class JUnitRuleMockery extends JUnit4Mockery implements org.junit.rules.MethodRule
AJUnitRuleMockery
is a JUnit Rule that manages JMock expectations and allowances, and asserts that expectations have been met after each test has finished. To use it, add a field to the test class (note that you don't have to specify@RunWith(JMock.class)
any more). For example,public class ATestWithSatisfiedExpectations { @Rule public final JUnitRuleMockery context = new JUnitRuleMockery(); private final Runnable runnable = context.mock(Runnable.class); @Test public void doesSatisfyExpectations() { context.checking(new Expectations() {{ oneOf (runnable).run(); }}); runnable.run(); } }
Note that the Rule field must be declared public and as aJUnitRuleMockery
(not aMockery
) for JUnit to recognise it, as it's checked statically.
-
-
Field Summary
Fields Modifier and Type Field Description private Mockomatic
mockomatic
-
Constructor Summary
Constructors Constructor Description JUnitRuleMockery()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.junit.runners.model.Statement
apply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, java.lang.Object target)
-
Methods inherited from class org.jmock.Mockery
addExpectation, assertIsSatisfied, checking, describeTo, mock, mock, sequence, setDefaultResultForType, setExpectationErrorTranslator, setImposteriser, setNamingScheme, setThreadingPolicy, states
-
-
-
-
Field Detail
-
mockomatic
private final Mockomatic mockomatic
-
-