Polishing

This commit is contained in:
Juergen Hoeller
2023-11-20 21:01:40 +01:00
parent 695559879e
commit fff50657d2
6 changed files with 39 additions and 35 deletions

View File

@@ -54,7 +54,7 @@ class EnableCachingIntegrationTests {
@AfterEach
public void closeContext() {
void closeContext() {
if (this.context != null) {
this.context.close();
}

View File

@@ -60,6 +60,7 @@ class CacheErrorHandlerTests {
private SimpleService simpleService;
@BeforeEach
void setup() {
this.context = new AnnotationConfigApplicationContext(Config.class);
@@ -69,11 +70,13 @@ class CacheErrorHandlerTests {
this.simpleService = context.getBean(SimpleService.class);
}
@AfterEach
void tearDown() {
void closeContext() {
this.context.close();
}
@Test
void getFail() {
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
@@ -107,9 +110,9 @@ class CacheErrorHandlerTests {
this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
this.simpleService.get(0L))
.withMessage("Test exception on get");
assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() -> this.simpleService.get(0L))
.withMessage("Test exception on get");
}
@Test
@@ -128,9 +131,9 @@ class CacheErrorHandlerTests {
this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
this.simpleService.put(0L))
.withMessage("Test exception on put");
assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() -> this.simpleService.put(0L))
.withMessage("Test exception on put");
}
@Test
@@ -149,9 +152,9 @@ class CacheErrorHandlerTests {
this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
this.simpleService.evict(0L))
.withMessage("Test exception on evict");
assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() -> this.simpleService.evict(0L))
.withMessage("Test exception on evict");
}
@Test
@@ -170,9 +173,9 @@ class CacheErrorHandlerTests {
this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
this.simpleService.clear())
.withMessage("Test exception on clear");
assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() -> this.simpleService.clear())
.withMessage("Test exception on clear");
}

View File

@@ -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.
@@ -51,6 +51,7 @@ public class CachePutEvaluationTests {
private SimpleService service;
@BeforeEach
public void setup() {
this.context = new AnnotationConfigApplicationContext(Config.class);
@@ -59,12 +60,11 @@ public class CachePutEvaluationTests {
}
@AfterEach
public void close() {
if (this.context != null) {
this.context.close();
}
public void closeContext() {
this.context.close();
}
@Test
public void mutualGetPutExclusion() {
String key = "1";

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 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.
@@ -72,7 +72,7 @@ class CacheResolverCustomizationTests {
}
@AfterEach
void tearDown() {
void closeContext() {
this.context.close();
}
@@ -142,16 +142,17 @@ class CacheResolverCustomizationTests {
@Test
void noCacheResolved() {
Method method = ReflectionUtils.findMethod(SimpleService.class, "noCacheResolved", Object.class);
assertThatIllegalStateException().isThrownBy(() ->
this.simpleService.noCacheResolved(new Object()))
.withMessageContaining(method.toString());
assertThatIllegalStateException()
.isThrownBy(() -> this.simpleService.noCacheResolved(new Object()))
.withMessageContaining(method.toString());
}
@Test
void unknownCacheResolver() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
this.simpleService.unknownCacheResolver(new Object()))
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("unknownCacheResolver"));
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.simpleService.unknownCacheResolver(new Object()))
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("unknownCacheResolver"));
}