Harmonize NoUniqueBeanDefinitionException message

This commit makes sure that the programmatic exception that is thrown
by the cache abstraction uses the same message structure as a default
message produced by NoUniqueBeanDefinitionException.

Closes gh-33305
This commit is contained in:
Stéphane Nicoll
2024-08-02 16:24:43 +02:00
parent 29dce74fcd
commit 0a2611b22f
4 changed files with 40 additions and 14 deletions

View File

@@ -92,9 +92,12 @@ class EnableCachingTests extends AbstractCacheAnnotationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(MultiCacheManagerConfig.class);
assertThatThrownBy(ctx::refresh)
.isInstanceOf(NoUniqueBeanDefinitionException.class)
.hasMessageContaining("no CacheResolver specified and expected a single CacheManager bean, but found 2: [cm1,cm2]")
.hasNoCause();
.isInstanceOfSatisfying(NoUniqueBeanDefinitionException.class, ex -> {
assertThat(ex.getMessage()).contains(
"no CacheResolver specified and expected single matching CacheManager but found 2: cm1,cm2");
assertThat(ex.getNumberOfBeansFound()).isEqualTo(2);
assertThat(ex.getBeanNamesFound()).containsExactly("cm1", "cm2");
}).hasNoCause();
}
@Test