Commit a9e8116a authored by Phillip Webb's avatar Phillip Webb

Only check for Mockito once

Update `MockReset` so that checking for Mockito only happens once.

Closes gh-14260
parent 02f2f62a
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -53,6 +53,9 @@ public enum MockReset { ...@@ -53,6 +53,9 @@ public enum MockReset {
*/ */
NONE; NONE;
private static final boolean MOCKITO_PRESENT = ClassUtils
.isPresent("org.mockito.internal.util.MockUtil", null);
/** /**
* Create {@link MockSettings settings} to be used with mocks where reset should occur * Create {@link MockSettings settings} to be used with mocks where reset should occur
* before each test method runs. * before each test method runs.
...@@ -103,7 +106,7 @@ public enum MockReset { ...@@ -103,7 +106,7 @@ public enum MockReset {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
static MockReset get(Object mock) { static MockReset get(Object mock) {
MockReset reset = MockReset.NONE; MockReset reset = MockReset.NONE;
if (ClassUtils.isPresent("org.mockito.internal.util.MockUtil", null)) { if (MOCKITO_PRESENT) {
if (Mockito.mockingDetails(mock).isMock()) { if (Mockito.mockingDetails(mock).isMock()) {
MockCreationSettings settings = MockitoApi.get().getMockSettings(mock); MockCreationSettings settings = MockitoApi.get().getMockSettings(mock);
List listeners = settings.getInvocationListeners(); List listeners = settings.getInvocationListeners();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment