Decouple exception messages for sync=true from @Cacheable
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,8 +48,9 @@ public class CacheSyncFailureTests {
|
||||
|
||||
private SimpleService simpleService;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
public void setup() {
|
||||
this.context = new AnnotationConfigApplicationContext(Config.class);
|
||||
this.simpleService = this.context.getBean(SimpleService.class);
|
||||
}
|
||||
@@ -61,39 +62,40 @@ public class CacheSyncFailureTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void unlessSync() {
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
this.simpleService.unlessSync("key"))
|
||||
.withMessageContaining("@Cacheable(sync=true) does not support unless attribute");
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.simpleService.unlessSync("key"))
|
||||
.withMessageContaining("A sync=true operation does not support the unless attribute");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void severalCachesSync() {
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
this.simpleService.severalCachesSync("key"))
|
||||
.withMessageContaining("@Cacheable(sync=true) only allows a single cache");
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.simpleService.severalCachesSync("key"))
|
||||
.withMessageContaining("A sync=true operation is restricted to a single cache");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void severalCachesWithResolvedSync() {
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
this.simpleService.severalCachesWithResolvedSync("key"))
|
||||
.withMessageContaining("@Cacheable(sync=true) only allows a single cache");
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.simpleService.severalCachesWithResolvedSync("key"))
|
||||
.withMessageContaining("A sync=true operation is restricted to a single cache");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void syncWithAnotherOperation() {
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
this.simpleService.syncWithAnotherOperation("key"))
|
||||
.withMessageContaining("@Cacheable(sync=true) cannot be combined with other cache operations");
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.simpleService.syncWithAnotherOperation("key"))
|
||||
.withMessageContaining("A sync=true operation cannot be combined with other cache operations");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void syncWithTwoGetOperations() {
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
this.simpleService.syncWithTwoGetOperations("key"))
|
||||
.withMessageContaining("Only one @Cacheable(sync=true) entry is allowed");
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.simpleService.syncWithTwoGetOperations("key"))
|
||||
.withMessageContaining("Only one sync=true operation is allowed");
|
||||
}
|
||||
|
||||
|
||||
@@ -131,6 +133,7 @@ public class CacheSyncFailureTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class Config implements CachingConfigurer {
|
||||
|
||||
Reference in New Issue
Block a user