Skip to content

Commit

Permalink
Failing test for spring-projectsgh-13945
Browse files Browse the repository at this point in the history
Failing testcase to show the issue. When Spring AOP need method
arguments to build a cache key (but probably also on other annotations
that require method arguments) the AOP part will fail.

Creating a Mockito mock results in the loss of the debug information
needed to read the correct method parameter.

issue: spring-projectsgh-13945
  • Loading branch information
mdeinum committed Aug 1, 2018
1 parent 143e4f0 commit 2335669
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -64,6 +65,16 @@ public void verifyShouldUseProxyTarget() throws Exception {
verify(this.dateService, times(1)).getDate(matchesAnyBoolean());
}

@Test
public void verifyShouldUseProxyTargetWithMethodArguments() throws Exception {
Long d1 = this.dateService.getRandomDate(1234L);
Thread.sleep(200);
Long d2 = this.dateService.getRandomDate(1234L);
assertThat(d1).isEqualTo(d2);
verify(this.dateService, times(1)).getRandomDate(1234L);
}


private boolean matchesFalse() {
if (isTestingMockito1()) {
Method method = ReflectionUtils.findMethod(
Expand Down Expand Up @@ -103,7 +114,7 @@ public CacheResolver cacheResolver(CacheManager cacheManager) {
@Bean
public ConcurrentMapCacheManager cacheManager() {
ConcurrentMapCacheManager cacheManager = new ConcurrentMapCacheManager();
cacheManager.setCacheNames(Arrays.asList("test"));
cacheManager.setCacheNames(Arrays.asList("test", "test2"));
return cacheManager;
}

Expand All @@ -117,6 +128,11 @@ public Long getDate(boolean arg) {
return System.nanoTime();
}

@Cacheable(cacheNames = "test2", key = "#seed")
public Long getRandomDate(Long seed) {
return ThreadLocalRandom.current().nextLong(seed);
}

}

}

0 comments on commit 2335669

Please sign in to comment.