diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoAopProxyTargetInterceptor.java b/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoAopProxyTargetInterceptor.java index 48748ad1d0..19507b27b8 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoAopProxyTargetInterceptor.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoAopProxyTargetInterceptor.java @@ -17,12 +17,15 @@ package org.springframework.boot.test.mock.mockito; import java.lang.reflect.Field; +import java.util.List; import org.aopalliance.aop.Advice; import org.aopalliance.intercept.Interceptor; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.mockito.internal.InternalMockHandler; +import org.mockito.internal.matchers.LocalizedMatcher; +import org.mockito.internal.progress.ArgumentMatcherStorage; import org.mockito.internal.progress.MockingProgress; import org.mockito.internal.stubbing.InvocationContainer; import org.mockito.internal.util.MockUtil; @@ -107,7 +110,7 @@ class MockitoAopProxyTargetInterceptor implements MethodInterceptor { synchronized (this.monitor) { VerificationMode mode = this.progress.pullVerificationMode(); if (mode != null) { - this.progress.verificationStarted(mode); + resetVerificationStarted(mode); return true; } return false; @@ -124,11 +127,20 @@ class MockitoAopProxyTargetInterceptor implements MethodInterceptor { mode = new MockAwareVerificationMode(target, mockAwareMode); } } - this.progress.verificationStarted(mode); + resetVerificationStarted(mode); } } } + private void resetVerificationStarted(VerificationMode mode) { + ArgumentMatcherStorage storage = this.progress.getArgumentMatcherStorage(); + List matchers = storage.pullLocalizedMatchers(); + this.progress.verificationStarted(mode); + for (LocalizedMatcher matcher : matchers) { + storage.reportMatcher(matcher); + } + } + } } diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockBeanWithAopProxyTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockBeanWithAopProxyTests.java index 548a7af55b..0164440a88 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockBeanWithAopProxyTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockBeanWithAopProxyTests.java @@ -35,6 +35,8 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -52,13 +54,15 @@ public class MockBeanWithAopProxyTests { @Test public void verifyShouldUseProxyTarget() throws Exception { - given(this.dateService.getDate()).willReturn(1L); - Long d1 = this.dateService.getDate(); + given(this.dateService.getDate(false)).willReturn(1L); + Long d1 = this.dateService.getDate(false); assertThat(d1).isEqualTo(1L); - given(this.dateService.getDate()).willReturn(2L); - Long d2 = this.dateService.getDate(); + given(this.dateService.getDate(false)).willReturn(2L); + Long d2 = this.dateService.getDate(false); assertThat(d2).isEqualTo(2L); - verify(this.dateService, times(2)).getDate(); + verify(this.dateService, times(2)).getDate(false); + verify(this.dateService, times(2)).getDate(eq(false)); + verify(this.dateService, times(2)).getDate(anyBoolean()); } @Configuration @@ -86,7 +90,7 @@ public class MockBeanWithAopProxyTests { static class DateService { @Cacheable(cacheNames = "test") - public Long getDate() { + public Long getDate(boolean argument) { return System.nanoTime(); } diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyAndNotProxyTargetAwareTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyAndNotProxyTargetAwareTests.java index f701eeddc7..7bc2f08569 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyAndNotProxyTargetAwareTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyAndNotProxyTargetAwareTests.java @@ -34,6 +34,8 @@ import org.springframework.context.annotation.Import; import org.springframework.stereotype.Service; import org.springframework.test.context.junit4.SpringRunner; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -52,8 +54,10 @@ public class SpyBeanWithAopProxyAndNotProxyTargetAwareTests { @Test(expected = UnfinishedVerificationException.class) public void verifyShouldUseProxyTarget() throws Exception { - this.dateService.getDate(); - verify(this.dateService, times(1)).getDate(); + this.dateService.getDate(false); + verify(this.dateService, times(1)).getDate(false); + verify(this.dateService, times(1)).getDate(eq(false)); + verify(this.dateService, times(1)).getDate(anyBoolean()); reset(this.dateService); } @@ -82,7 +86,7 @@ public class SpyBeanWithAopProxyAndNotProxyTargetAwareTests { static class DateService { @Cacheable(cacheNames = "test") - public Long getDate() { + public Long getDate(boolean arg) { return System.nanoTime(); } diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyTests.java index 49d9572dcd..4761f6e6d8 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyTests.java @@ -34,6 +34,8 @@ import org.springframework.stereotype.Service; import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -51,11 +53,13 @@ public class SpyBeanWithAopProxyTests { @Test public void verifyShouldUseProxyTarget() throws Exception { - Long d1 = this.dateService.getDate(); + Long d1 = this.dateService.getDate(false); Thread.sleep(200); - Long d2 = this.dateService.getDate(); + Long d2 = this.dateService.getDate(false); assertThat(d1).isEqualTo(d2); - verify(this.dateService, times(1)).getDate(); + verify(this.dateService, times(1)).getDate(false); + verify(this.dateService, times(1)).getDate(eq(false)); + verify(this.dateService, times(1)).getDate(anyBoolean()); } @Configuration @@ -83,7 +87,7 @@ public class SpyBeanWithAopProxyTests { static class DateService { @Cacheable(cacheNames = "test") - public Long getDate() { + public Long getDate(boolean arg) { return System.nanoTime(); }