diff --git a/src/main/java/org/mockito/Captor.java b/src/main/java/org/mockito/Captor.java index 225bf700f2..c0a042c8cd 100644 --- a/src/main/java/org/mockito/Captor.java +++ b/src/main/java/org/mockito/Captor.java @@ -15,9 +15,16 @@ * * @Captor ArgumentCaptor<AsyncCallback<Foo>> captor; * + * private AutoCloseable closeable; + * * @Before - * public void init(){ - * MockitoAnnotations.initMocks(this); + * public void open() { + * closeable = MockitoAnnotations.openMocks(this); + * } + * + * @After + * public void release() throws Exception { + * closeable.close(); * } * * @Test public void shouldDoSomethingUseful() { diff --git a/src/main/java/org/mockito/InjectMocks.java b/src/main/java/org/mockito/InjectMocks.java index 375c35514d..3327f9dc33 100644 --- a/src/main/java/org/mockito/InjectMocks.java +++ b/src/main/java/org/mockito/InjectMocks.java @@ -71,8 +71,14 @@ * * public class SampleBaseTestCase { * - * @Before public void initMocks() { - * MockitoAnnotations.initMocks(this); + * private AutoCloseable closeable; + * + * @Before public void openMocks() { + * closeable = MockitoAnnotations.openMocks(this); + * } + * + * @After public void releaseMocks() throws Exception { + * closeable.close(); * } * } * @@ -141,11 +147,11 @@ *
* *
- * MockitoAnnotations.initMocks(this)
method has to be called to initialize annotated objects.
- * In above example, initMocks()
is called in @Before (JUnit4) method of test's base class.
- * For JUnit3 initMocks()
can go to setup()
method of a base class.
- * Instead you can also put initMocks() in your JUnit runner (@RunWith) or use the built-in
- * {@link MockitoJUnitRunner}.
+ * MockitoAnnotations.openMocks(this)
method has to be called to initialize annotated objects.
+ * In above example, openMocks()
is called in @Before (JUnit4) method of test's base class.
+ * For JUnit3 openMocks()
can go to setup()
method of a base class.
+ * Instead you can also put openMocks() in your JUnit runner (@RunWith) or use the built-in
+ * {@link MockitoJUnitRunner}. Also, make sure to release any mocks after disposing your test class with a corresponding hook.
*
@@ -155,7 +161,7 @@ * * @see Mock * @see Spy - * @see MockitoAnnotations#initMocks(Object) + * @see MockitoAnnotations#openMocks(Object) * @see MockitoJUnitRunner * @since 1.8.3 */ diff --git a/src/main/java/org/mockito/Mock.java b/src/main/java/org/mockito/Mock.java index 2473557e56..cb5bfba157 100644 --- a/src/main/java/org/mockito/Mock.java +++ b/src/main/java/org/mockito/Mock.java @@ -23,6 +23,7 @@ *
@@ -43,24 +44,30 @@
*
* public class SampleBaseTestCase {
*
- * @Before public void initMocks() {
- * MockitoAnnotations.initMocks(this);
+ * private AutoCloseable closeable;
+ *
+ * @Before public void openMocks() {
+ * closeable = MockitoAnnotations.openMocks(this);
+ * }
+ *
+ * @After public void releaseMocks() throws Exception {
+ * closeable.close();
* }
* }
*
*
*
- * MockitoAnnotations.initMocks(this)
method has to be called to initialize annotated objects.
- * In above example, initMocks()
is called in @Before (JUnit4) method of test's base class.
- * For JUnit3 initMocks()
can go to setup()
method of a base class.
- * Instead you can also put initMocks() in your JUnit runner (@RunWith) or use the built-in
- * {@link MockitoJUnitRunner}.
+ * MockitoAnnotations.openMocks(this)
method has to be called to initialize annotated objects.
+ * In above example, openMocks()
is called in @Before (JUnit4) method of test's base class.
+ * For JUnit3 openMocks()
can go to setup()
method of a base class.
+ * Instead you can also put openMocks() in your JUnit runner (@RunWith) or use the built-in
+ * {@link MockitoJUnitRunner}. Also, make sure to release any mocks after disposing your test class with a corresponding hook.
*
+ * If the {@link Mock} annotation is used on fields or method parameters of this type, a static mock
+ * is created instead of a regular mock. The static mock is activated and released upon completing any
+ * relevant test.
+ *
+ * @param
- * All new annotations are *only* processed on {@link MockitoAnnotations#initMocks(Object)}.
+ * All new annotations are *only* processed on {@link MockitoAnnotations#openMocks(Object)}.
* Just like for @{@link Mock} annotation you can use the built-in runner: {@link MockitoJUnitRunner} or rule:
* {@link MockitoRule}.
*
@@ -910,7 +911,7 @@
* Mockito will now try to instantiate @{@link Spy} and will instantiate @{@link InjectMocks} fields
* using constructor injection, setter injection, or field injection.
*
- * To take advantage of this feature you need to use {@link MockitoAnnotations#initMocks(Object)}, {@link MockitoJUnitRunner}
+ * To take advantage of this feature you need to use {@link MockitoAnnotations#openMocks(Object)}, {@link MockitoJUnitRunner}
* or {@link MockitoRule}.
*
* Read more about available tricks and the rules of injection in the javadoc for {@link InjectMocks}
@@ -1147,7 +1148,7 @@
*
*
*/
@SuppressWarnings("unchecked")
public class Mockito extends ArgumentMatchers {
@@ -2029,6 +2053,73 @@ public static
+ * See examples in javadoc for {@link Mockito} class
+ *
+ * @param classToMock class or interface of which static mocks should be mocked.
+ * @return mock controller
+ */
+ @Incubating
+ @CheckReturnValue
+ public static
+ * See examples in javadoc for {@link Mockito} class
+ *
+ * @param classToMock class or interface of which static mocks should be mocked.
+ * @param defaultAnswer the default answer when invoking static methods.
+ * @return mock controller
+ */
+ @Incubating
+ @CheckReturnValue
+ public static
+ * See examples in javadoc for {@link Mockito} class
+ *
+ * @param classToMock class or interface of which static mocks should be mocked.
+ * @param name the name of the mock to use in error messages.
+ * @return mock controller
+ */
+ @Incubating
+ @CheckReturnValue
+ public static
+ * See examples in javadoc for {@link Mockito} class
+ *
+ * @param classToMock class or interface of which static mocks should be mocked.
+ * @param mockSettings the settings to use where only name and default answer are considered.
+ * @return mock controller
+ */
+ @Incubating
+ @CheckReturnValue
+ public static
diff --git a/src/main/java/org/mockito/MockitoAnnotations.java b/src/main/java/org/mockito/MockitoAnnotations.java
index ba355e702f..effddcea17 100644
--- a/src/main/java/org/mockito/MockitoAnnotations.java
+++ b/src/main/java/org/mockito/MockitoAnnotations.java
@@ -9,8 +9,10 @@
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.plugins.AnnotationEngine;
+import static org.mockito.internal.util.StringUtil.*;
+
/**
- * MockitoAnnotations.initMocks(this); initializes fields annotated with Mockito annotations.
+ * MockitoAnnotations.openMocks(this); initializes fields annotated with Mockito annotations.
* See also {@link MockitoSession} which not only initializes mocks
* but also adds extra validation for cleaner tests!
*
@@ -37,19 +39,27 @@
*
* public class SampleBaseTestCase {
*
- * @Before public void initMocks() {
- * MockitoAnnotations.initMocks(this);
+ * private AutoCloseable closeable;
+ *
+ * @Before public void openMocks() {
+ * closeable = MockitoAnnotations.openMocks(this);
+ * }
+ *
+ * @After public void releaseMocks() throws Exception {
+ * closeable.close();
* }
* }
*
*
* Read also about other annotations @{@link Spy}, @{@link Captor}, @{@link InjectMocks}
*
- *
- * In above example,
* See examples in javadoc for {@link MockitoAnnotations} class.
+ *
+ * @return A closable to close when completing any tests in {@code testClass}.
*/
- public static void initMocks(Object testClass) {
+ public static AutoCloseable openMocks(Object testClass) {
if (testClass == null) {
throw new MockitoException(
"testClass cannot be null. For info how to use @Mock annotations see examples in javadoc for MockitoAnnotations class");
@@ -67,6 +79,32 @@ public static void initMocks(Object testClass) {
AnnotationEngine annotationEngine =
new GlobalConfiguration().tryGetPluginAnnotationEngine();
- annotationEngine.process(testClass.getClass(), testClass);
+ return annotationEngine.process(testClass.getClass(), testClass);
+ }
+
+ /**
+ * Initializes objects annotated with Mockito annotations for given testClass:
+ * @{@link org.mockito.Mock}, @{@link Spy}, @{@link Captor}, @{@link InjectMocks}
+ *
+ * See examples in javadoc for {@link MockitoAnnotations} class.
+ *
+ * @deprecated Use {@link MockitoAnnotations#openMocks(Object)} instead.
+ * This method is equivalent to {@code openMocks(testClass).close()}.
+ * The close method should however only be called after completed usage of {@code testClass}.
+ * If using static-mocks or custom {@link org.mockito.plugins.MockMaker}s, using this method might
+ * cause misbehavior of mocks injected into the test class.
+ */
+ @Deprecated
+ public static void initMocks(Object testClass) {
+ try {
+ openMocks(testClass).close();
+ } catch (Exception e) {
+ throw new MockitoException(
+ join(
+ "Failed to release mocks",
+ "",
+ "This should not happen unless you are using a third-part mock maker"),
+ e);
+ }
}
}
diff --git a/src/main/java/org/mockito/MockitoSession.java b/src/main/java/org/mockito/MockitoSession.java
index 6a529fde43..903fd0fdd0 100644
--- a/src/main/java/org/mockito/MockitoSession.java
+++ b/src/main/java/org/mockito/MockitoSession.java
@@ -67,7 +67,7 @@
*
* Why to use {@code MockitoSession}?
* What's the difference between {@code MockitoSession}, {@link MockitoJUnitRunner}, {@link MockitoRule}
- * and traditional {@link MockitoAnnotations#initMocks(Object)}?
+ * and traditional {@link MockitoAnnotations#openMocks(Object)}?
*
* Great questions!
* There is no need to use {@code MockitoSession} if you already use {@link MockitoJUnitRunner} or {@link MockitoRule}.
@@ -78,7 +78,7 @@
* You can automatically take advantage of strict stubbing ({@link Strictness}),
* automatic initialization of annotated mocks ({@link MockitoAnnotations}),
* and extra validation ({@link Mockito#validateMockitoUsage()}).
- * If you use Mockito annotations with {@link MockitoAnnotations#initMocks(Object)}
+ * If you use Mockito annotations with {@link MockitoAnnotations#openMocks(Object)}
* but not Mockito runner/rule please try out Mockito's JUnit support (runner or rule) or
* start using {@code MockitoSession}. You'll get cleaner tests and better productivity.
*
diff --git a/src/main/java/org/mockito/Spy.java b/src/main/java/org/mockito/Spy.java
index b164c8f590..aa485a355d 100644
--- a/src/main/java/org/mockito/Spy.java
+++ b/src/main/java/org/mockito/Spy.java
@@ -25,9 +25,14 @@
* @Spy Foo spyOnFoo = new Foo("argument");
* //Instance for spying is created by mockito via reflection (only default constructors supported):
* @Spy Bar spyOnBar;
+ * private AutoCloseable closeable;
* @Before
- * public void init(){
- * MockitoAnnotations.initMocks(this);
+ * public void init() {
+ * closeable = MockitoAnnotations.openMocks(this);
+ * }
+ * @After
+ * public void release() throws Exception {
+ * closeable.close();
* }
* ...
* }
@@ -84,12 +89,13 @@
*
*
*
- * One last warning : if you call Note that the spy won't have any annotations of the spied type, because CGLIB won't rewrite them.
@@ -98,7 +104,7 @@
* @see Mockito#spy(Object)
* @see Mock
* @see InjectMocks
- * @see MockitoAnnotations#initMocks(Object)
+ * @see MockitoAnnotations#openMocks(Object)
* @see MockitoJUnitRunner
* @since 1.8.3
*/
diff --git a/src/main/java/org/mockito/configuration/AnnotationEngine.java b/src/main/java/org/mockito/configuration/AnnotationEngine.java
index d4f8fb0b1f..897878169a 100644
--- a/src/main/java/org/mockito/configuration/AnnotationEngine.java
+++ b/src/main/java/org/mockito/configuration/AnnotationEngine.java
@@ -9,7 +9,7 @@
/**
* Configures mock creation logic behind @Mock, @Captor and @Spy annotations
*
- * If you are interested then see implementations or source code of {@link MockitoAnnotations#initMocks(Object)}
+ * If you are interested then see implementations or source code of {@link MockitoAnnotations#openMocks(Object)}
*
* This interface can be used to configure a different annotation engine through
* {@link org.mockito.configuration.IMockitoConfiguration}, however this mechanism is being superseded by the new
diff --git a/src/main/java/org/mockito/internal/MockedStaticImpl.java b/src/main/java/org/mockito/internal/MockedStaticImpl.java
new file mode 100644
index 0000000000..908b810be0
--- /dev/null
+++ b/src/main/java/org/mockito/internal/MockedStaticImpl.java
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2007 Mockito contributors
+ * This program is made available under the terms of the MIT License.
+ */
+package org.mockito.internal;
+
+import org.mockito.Incubating;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.MockingDetails;
+import org.mockito.Mockito;
+import org.mockito.exceptions.base.MockitoAssertionError;
+import org.mockito.exceptions.base.MockitoException;
+import org.mockito.internal.debugging.LocationImpl;
+import org.mockito.internal.listeners.VerificationStartedNotifier;
+import org.mockito.internal.progress.MockingProgress;
+import org.mockito.internal.stubbing.InvocationContainerImpl;
+import org.mockito.internal.verification.MockAwareVerificationMode;
+import org.mockito.internal.verification.VerificationDataImpl;
+import org.mockito.invocation.Location;
+import org.mockito.invocation.MockHandler;
+import org.mockito.plugins.MockMaker;
+import org.mockito.stubbing.OngoingStubbing;
+import org.mockito.verification.VerificationMode;
+
+import static org.mockito.internal.exceptions.Reporter.*;
+import static org.mockito.internal.progress.ThreadSafeMockingProgress.*;
+import static org.mockito.internal.util.MockUtil.*;
+import static org.mockito.internal.util.StringUtil.*;
+import static org.mockito.internal.verification.VerificationModeFactory.*;
+
+/**
+ * Represents an active mock of a type's static methods. The mocking only affects the thread
+ * on which this static mock was created and it is not safe to use this object from another
+ * thread. The static mock is released when this object's {@link MockedStaticImpl#close()} method
+ * is invoked. If this object is never closed, the static mock will remain active on the
+ * initiating thread. It is therefore recommended to create this object within a try-with-resources
+ * statement unless when managed explicitly, for example by using a JUnit rule or extension.
+ *
+ * If the {@link Mock} annotation is used on fields or method parameters of this type, a static mock
+ * is created instead of a regular mock. The static mock is activated and released upon completing any
+ * relevant test.
+ *
+ * @param OngoingStubbing when(Verification verification);
+
+ /**
+ * See {@link Mockito#verify(Object)}.
+ */
+ default void verify(Verification verification) {
+ verify(times(1), verification);
+ }
+
+ /**
+ * See {@link Mockito#verify(Object, VerificationMode)}.
+ */
+ void verify(VerificationMode mode, Verification verification);
+
+ /**
+ * See {@link Mockito#reset(Object[])}.
+ */
+ void reset();
+
+ /**
+ * See {@link Mockito#clearInvocations(Object[])}.
+ */
+ void clearInvocations();
+
+ /**
+ * {@link Mockito#verifyNoMoreInteractions(Object...)}.
+ */
+ void verifyNoMoreInteractions();
+
+ /**
+ * See {@link Mockito#verifyNoInteractions(Object...)}.
+ */
+ void verifyNoInteractions();
+
+ @Override
+ void close();
+
+ /**
+ * Releases this static mock and is non-operational if already released.
+ */
+ void closeOnDemand();
+
+ interface Verification {
+
+ void apply() throws Throwable;
+ }
+}
diff --git a/src/main/java/org/mockito/Mockito.java b/src/main/java/org/mockito/Mockito.java
index f6d0870001..6ec7a81be9 100644
--- a/src/main/java/org/mockito/Mockito.java
+++ b/src/main/java/org/mockito/Mockito.java
@@ -105,6 +105,7 @@
* 45. New JUnit Jupiter (JUnit5+) extension
* 46. New Mockito.lenient()
and MockSettings.lenient()
methods (Since 2.20.0)
* 47. New API for clearing mock state in inline mocking (Since 2.25.0)
+ * 48. New API for mocking static methods (Since 3.4.0)
*
*
* 0. Migrating to Mockito 2
@@ -464,7 +465,7 @@
* runner:
*
*
*
* You can use built-in runner: {@link MockitoJUnitRunner} or a rule: {@link MockitoRule}.
@@ -866,7 +867,7 @@
* should only use partial mocks as a last resort. See point 16 about partial mocks.
*
*
- * MockitoAnnotations.initMocks(testClass);
+ * MockitoAnnotations.openMocks(testClass);
*
*
*
* Now you can choose to use a rule :
@@ -1544,6 +1545,29 @@
* Hence, we introduced a new API to explicitly clear mock state (only make sense in inline mocking!).
* See example usage in {@link MockitoFramework#clearInlineMocks()}.
* If you have feedback or a better idea how to solve the problem please reach out.
+ *
+ *
+ * @{@link org.junit.runner.RunWith}({@link MockitoJUnitRunner}.class)
{@link MockitoAnnotations#initMocks(Object)}
in the @{@link org.junit.Before}
method{@link MockitoAnnotations#openMocks(Object)}
in the @{@link org.junit.Before}
method48. Mocking static methods (since 3.4.0)
+ *
+ * When using the inline mock maker, it is possible to mock static method invocations within the current
+ * thread and a user-defined scope. This way, Mockito assures that concurrently and sequentially running tests do not interfere.
+ *
+ * To make sure a static mock remains temporary, it is recommended to define the scope within a try-with-resources construct.
+ * In the following example, the Foo
type's static method would return foo
unless mocked:
+ *
+ *
+ *
+ * Due to the defined scope of the static mock, it returns to its original behvior once the scope is released. To define mock
+ * behavior and to verify static method invocations, use the
+ * assertEquals("foo", Foo.method());
+ * try (MockedStatic
MockedStatic
that is returned.
+ * MockitoAnnotations.initMocks(this)
method has to be called to initialize annotated fields.
+ * MockitoAnnotations.openMocks(this)
method has to be called to initialize annotated fields.
* initMocks()
is called in @Before (JUnit4) method of test's base class.
- * For JUnit3 initMocks()
can go to setup()
method of a base class.
- * You can also put initMocks() in your JUnit runner (@RunWith) or use built-in runner: {@link MockitoJUnitRunner}
+ * In above example, openMocks()
is called in @Before (JUnit4) method of test's base class.
+ * For JUnit3 openMocks()
can go to setup()
method of a base class.
+ * You can also put openMocks() in your JUnit runner (@RunWith) or use built-in runner: {@link MockitoJUnitRunner}.
+ * If static method mocks are used, it is required to close the initialization. Additionally, if using third-party
+ * mock-makers, other life-cycles might be handled by the open-release routine.
*/
public class MockitoAnnotations {
@@ -58,8 +68,10 @@ public class MockitoAnnotations {
* @{@link org.mockito.Mock}, @{@link Spy}, @{@link Captor}, @{@link InjectMocks}
* MockitoAnnotations.initMocks(this)
in a
+ * One last warning : if you call MockitoAnnotations.openMocks(this)
in a
* super class constructor then this will not work. It is because fields
* in subclass are only instantiated after super class constructor has returned.
* It's better to use @Before.
- * Instead you can also put initMocks() in your JUnit runner (@RunWith) or use the built-in
- * {@link MockitoJUnitRunner}.
+ * Instead you can also put openMocks() in your JUnit runner (@RunWith) or use the built-in
+ * {@link MockitoJUnitRunner}. Also, make sure to release any mocks after disposing your test class with a
+ * corresponding hook.
* OngoingStubbing when(Verification verification) {
+ assertNotClosed();
+
+ try {
+ verification.apply();
+ } catch (Throwable ignored) {
+ }
+
+ MockingProgress mockingProgress = mockingProgress();
+ mockingProgress.stubbingStarted();
+ @SuppressWarnings("unchecked")
+ OngoingStubbing stubbing = (OngoingStubbing) mockingProgress.pullOngoingStubbing();
+ if (stubbing == null) {
+ mockingProgress.reset();
+ throw missingMethodInvocation();
+ }
+ return stubbing;
+ }
+
+ @Override
+ public void verify(VerificationMode mode, Verification verification) {
+ assertNotClosed();
+
+ MockingDetails mockingDetails = Mockito.mockingDetails(control.getType());
+ MockHandler handler = mockingDetails.getMockHandler();
+
+ VerificationStartedNotifier.notifyVerificationStarted(
+ handler.getMockSettings().getVerificationStartedListeners(), mockingDetails);
+
+ MockingProgress mockingProgress = mockingProgress();
+ VerificationMode actualMode = mockingProgress.maybeVerifyLazily(mode);
+ mockingProgress.verificationStarted(
+ new MockAwareVerificationMode(
+ control.getType(), actualMode, mockingProgress.verificationListeners()));
+
+ try {
+ verification.apply();
+ } catch (MockitoException | MockitoAssertionError e) {
+ throw e;
+ } catch (Throwable t) {
+ throw new MockitoException(
+ join(
+ "An unexpected error occurred while verifying a static stub",
+ "",
+ "To correctly verify a stub, invoke a single static method of "
+ + control.getType().getName()
+ + " in the provided lambda.",
+ "For example, if a method 'sample' was defined, provide a lambda or anonymous class containing the code",
+ "",
+ "() -> " + control.getType().getSimpleName() + ".sample()",
+ "or",
+ control.getType().getSimpleName() + "::sample"),
+ t);
+ }
+ }
+
+ @Override
+ public void reset() {
+ assertNotClosed();
+
+ MockingProgress mockingProgress = mockingProgress();
+ mockingProgress.validateState();
+ mockingProgress.reset();
+ mockingProgress.resetOngoingStubbing();
+
+ resetMock(control.getType());
+ }
+
+ @Override
+ public void clearInvocations() {
+ assertNotClosed();
+
+ MockingProgress mockingProgress = mockingProgress();
+ mockingProgress.validateState();
+ mockingProgress.reset();
+ mockingProgress.resetOngoingStubbing();
+
+ getInvocationContainer(control.getType()).clearInvocations();
+ }
+
+ @Override
+ public void verifyNoMoreInteractions() {
+ assertNotClosed();
+
+ mockingProgress().validateState();
+ InvocationContainerImpl invocations = getInvocationContainer(control.getType());
+ VerificationDataImpl data = new VerificationDataImpl(invocations, null);
+ noMoreInteractions().verify(data);
+ }
+
+ @Override
+ public void verifyNoInteractions() {
+ assertNotClosed();
+
+ mockingProgress().validateState();
+ InvocationContainerImpl invocations = getInvocationContainer(control.getType());
+ VerificationDataImpl data = new VerificationDataImpl(invocations, null);
+ noInteractions().verify(data);
+ }
+
+ @Override
+ public void close() {
+ assertNotClosed();
+
+ closed = true;
+ control.disable();
+ }
+
+ @Override
+ public void closeOnDemand() {
+ if (!closed) {
+ close();
+ }
+ }
+
+ private void assertNotClosed() {
+ if (closed) {
+ throw new MockitoException(
+ join(
+ "The static mock created at",
+ location.toString(),
+ "is already resolved and cannot longer be used"));
+ }
+ }
+}
diff --git a/src/main/java/org/mockito/internal/MockitoCore.java b/src/main/java/org/mockito/internal/MockitoCore.java
index 4353e0fbda..bccb045fe1 100644
--- a/src/main/java/org/mockito/internal/MockitoCore.java
+++ b/src/main/java/org/mockito/internal/MockitoCore.java
@@ -7,6 +7,7 @@
import static org.mockito.internal.exceptions.Reporter.*;
import static org.mockito.internal.progress.ThreadSafeMockingProgress.mockingProgress;
import static org.mockito.internal.util.MockUtil.createMock;
+import static org.mockito.internal.util.MockUtil.createStaticMock;
import static org.mockito.internal.util.MockUtil.getInvocationContainer;
import static org.mockito.internal.util.MockUtil.getMockHandler;
import static org.mockito.internal.util.MockUtil.isMock;
@@ -20,6 +21,7 @@
import org.mockito.InOrder;
import org.mockito.MockSettings;
+import org.mockito.MockedStatic;
import org.mockito.MockingDetails;
import org.mockito.exceptions.misusing.NotAMockException;
import org.mockito.internal.creation.MockSettingsImpl;
@@ -40,6 +42,7 @@
import org.mockito.invocation.Invocation;
import org.mockito.invocation.MockHandler;
import org.mockito.mock.MockCreationSettings;
+import org.mockito.plugins.MockMaker;
import org.mockito.quality.Strictness;
import org.mockito.stubbing.LenientStubber;
import org.mockito.stubbing.OngoingStubbing;
@@ -68,6 +71,22 @@ public this
*/
- public void injectMocks(final Object testClassInstance) {
+ private AutoCloseable injectMocks(final Object testClassInstance) {
Class> clazz = testClassInstance.getClass();
Set