From 1169f6939093931b96269a2e02f12738a531fd88 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 5 Jan 2017 14:02:31 -0800 Subject: [PATCH] Polish MockitoApi --- .../boot/test/mock/mockito/MockitoApi.java | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoApi.java b/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoApi.java index 073ca7180a..f10428e90d 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoApi.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoApi.java @@ -34,7 +34,6 @@ import org.mockito.stubbing.Answer; import org.mockito.verification.VerificationMode; import org.springframework.beans.BeanUtils; -import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -171,36 +170,17 @@ abstract class MockitoApi { Mockito1Api() { this.mockUtil = BeanUtils.instantiateClass(MockUtil.class); - this.getMockSettingsMethod = findMockSettingsMethod(); + this.getMockSettingsMethod = ReflectionUtils.findMethod(MockUtil.class, + "getMockSettings", Object.class); this.mockingProgress = (MockingProgress) BeanUtils .instantiateClass(ClassUtils.resolveClassName( "org.mockito.internal.progress.ThreadSafeMockingProgress", MockitoApi.class.getClassLoader())); - this.reportMatcherMethod = findReportMatcherMethod(); - this.mockAwareVerificationModeConstructor = findMockAwareVerificationModeConstructor(); - } - - private Method findMockSettingsMethod() { - Method method = ReflectionUtils.findMethod(MockUtil.class, "getMockSettings", - Object.class); - Assert.state(method != null, "Unable to find getMockSettings method"); - return method; - } - - private Method findReportMatcherMethod() { - Method method = ReflectionUtils.findMethod(ArgumentMatcherStorage.class, - "reportMatcher", Matcher.class); - Assert.state(method != null, "Unable to find reportMatcher method"); - return method; - } - - private Constructor findMockAwareVerificationModeConstructor() { - Constructor constructor = ClassUtils + this.reportMatcherMethod = ReflectionUtils.findMethod( + ArgumentMatcherStorage.class, "reportMatcher", Matcher.class); + this.mockAwareVerificationModeConstructor = ClassUtils .getConstructorIfAvailable(MockAwareVerificationMode.class, Object.class, VerificationMode.class); - Assert.state(constructor != null, - "Unable to find MockAwareVerificationMode constructor"); - return constructor; } @Override