Package org.jmock.junit5
Class JUnit5Mockery
- java.lang.Object
-
- org.jmock.Mockery
-
- org.jmock.junit5.JUnit5Mockery
-
- All Implemented Interfaces:
org.hamcrest.SelfDescribing
,org.junit.jupiter.api.extension.AfterEachCallback
,org.junit.jupiter.api.extension.BeforeEachCallback
,org.junit.jupiter.api.extension.Extension
@AutoService(org.junit.jupiter.api.extension.Extension.class) public class JUnit5Mockery extends Mockery implements org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback
AJUnit5Mockery
is a JUnit Extension that manages JMock expectations and allowances, and asserts that expectations have been met after each test has finished. To use it, add a (non-private) field to the test class For example,public class ATestWithSatisfiedExpectations { @RegisterExtension final JUnitRuleMockery context = new JUnitRuleMockery(); @Mock private final Runnable runnable; @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 JUnit5Mockery()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
void
beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
private static void
checkMockery(org.junit.jupiter.api.extension.ExtensionContext context, java.lang.Class<?> testCaseClass)
private void
fillInAutoMocks(java.lang.Object target, java.util.List<java.lang.reflect.Field> allFields)
private static java.lang.reflect.Field
findMockeryField(java.lang.Class<?> testClass, org.junit.jupiter.api.extension.ExtensionContext context)
-
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
-
-
Method Detail
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.Exception
- Specified by:
beforeEach
in interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
- Throws:
java.lang.Exception
-
afterEach
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.Exception
- Specified by:
afterEach
in interfaceorg.junit.jupiter.api.extension.AfterEachCallback
- Throws:
java.lang.Exception
-
fillInAutoMocks
private void fillInAutoMocks(java.lang.Object target, java.util.List<java.lang.reflect.Field> allFields)
-
checkMockery
private static void checkMockery(org.junit.jupiter.api.extension.ExtensionContext context, java.lang.Class<?> testCaseClass)
-
findMockeryField
private static java.lang.reflect.Field findMockeryField(java.lang.Class<?> testClass, org.junit.jupiter.api.extension.ExtensionContext context)
-
-