@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2002 - 2020 the original author or authors .
* Copyright 2002 - 2022 the original author or authors .
*
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -31,10 +31,13 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.testfixture.cache.beans.AnnotatedClassCacheableService ;
import org.springframework.context.testfixture.cache.beans.AnnotatedClassCacheableService ;
import org.springframework.context.testfixture.cache.beans.CacheableService ;
import org.springframework.context.testfixture.cache.beans.CacheableService ;
import org.springframework.context.testfixture.cache.beans.TestEntity ;
import org.springframework.context.testfixture.cache.beans.TestEntity ;
import org.springframework.expression.spel.SpelEvaluationException ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType ;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType ;
import static org.assertj.core.api.Assertions.assertThatIOException ;
import static org.assertj.core.api.Assertions.assertThatIOException ;
import static org.junit.jupiter.api.Assertions.assertEquals ;
import static org.junit.jupiter.api.Assertions.assertNull ;
/ * *
/ * *
* Abstract cache annotation tests ( containing several reusable methods ) .
* Abstract cache annotation tests ( containing several reusable methods ) .
@ -504,6 +507,29 @@ public abstract class AbstractCacheAnnotationTests {
assertThat ( primary . get ( id ) . get ( ) ) . isSameAs ( entity ) ;
assertThat ( primary . get ( id ) . get ( ) ) . isSameAs ( entity ) ;
}
}
public void testPutRefersToNullResult ( CacheableService < ? > service ) {
Long id = Long . MIN_VALUE ;
TestEntity entity = new TestEntity ( ) ;
Cache primary = this . cm . getCache ( "primary" ) ;
assertNull ( primary . get ( id ) ) ;
try {
service . putRefersToNullResult ( entity ) ;
} catch ( Exception e ) {
assertEquals ( SpelEvaluationException . class , e . getClass ( ) ) ;
assertEquals ( "EL1007E: Property or field 'id' cannot be found on null" , e . getMessage ( ) ) ;
}
assertNull ( primary . get ( id ) ) ;
}
public void testPutRefersToNullResultWithUnless ( CacheableService < ? > service ) {
Long id = Long . MIN_VALUE ;
TestEntity entity = new TestEntity ( ) ;
Cache primary = this . cm . getCache ( "primary" ) ;
assertNull ( primary . get ( id ) ) ;
service . putRefersToNullResultWithUnless ( entity ) ;
assertNull ( primary . get ( id ) ) ;
}
protected void testMultiCacheAndEvict ( CacheableService < ? > service ) {
protected void testMultiCacheAndEvict ( CacheableService < ? > service ) {
String methodName = "multiCacheAndEvict" ;
String methodName = "multiCacheAndEvict" ;
@ -854,6 +880,26 @@ public abstract class AbstractCacheAnnotationTests {
testPutRefersToResult ( this . ccs ) ;
testPutRefersToResult ( this . ccs ) ;
}
}
@Test
public void testPutRefersToNullResult ( ) throws Exception {
testPutRefersToNullResult ( this . cs ) ;
}
@Test
public void testClassPutRefersToNullResult ( ) throws Exception {
testPutRefersToNullResult ( this . ccs ) ;
}
@Test
public void testPutRefersToNullResultWithUnless ( ) throws Exception {
testPutRefersToNullResultWithUnless ( this . cs ) ;
}
@Test
public void testClassPutRefersToNullResultWithUnless ( ) throws Exception {
testPutRefersToNullResultWithUnless ( this . ccs ) ;
}
@Test
@Test
public void testMultiCacheAndEvict ( ) {
public void testMultiCacheAndEvict ( ) {
testMultiCacheAndEvict ( this . cs ) ;
testMultiCacheAndEvict ( this . cs ) ;