From 03f52e6329af6196b9272f56b39528ea06451d55 Mon Sep 17 00:00:00 2001 From: saikat Date: Fri, 1 Mar 2024 16:03:55 +0530 Subject: [PATCH] refactor code --- .../multicache/MultipleCachingApplication.java | 12 ------------ .../{multicache => twolevelcache}/CacheConfig.java | 5 ++--- .../{multicache => twolevelcache}/Customer.java | 2 +- .../CustomerCacheInterceptor.java | 2 +- .../CustomerRepository.java | 3 +-- .../CustomerService.java | 2 +- .../redis/ItemServiceCachingIntegrationTest.java | 10 +++++----- .../CustomerServiceCachingIntegrationTest.java | 12 ++++++------ 8 files changed, 17 insertions(+), 31 deletions(-) delete mode 100644 spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/MultipleCachingApplication.java rename spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/{multicache => twolevelcache}/CacheConfig.java (95%) rename spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/{multicache => twolevelcache}/Customer.java (87%) rename spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/{multicache => twolevelcache}/CustomerCacheInterceptor.java (95%) rename spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/{multicache => twolevelcache}/CustomerRepository.java (76%) rename spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/{multicache => twolevelcache}/CustomerService.java (94%) rename spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/{multicache => twolevelcache}/CustomerServiceCachingIntegrationTest.java (99%) diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/MultipleCachingApplication.java b/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/MultipleCachingApplication.java deleted file mode 100644 index 862a2993a0..0000000000 --- a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/MultipleCachingApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.caching.multicache; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class MultipleCachingApplication { - - public static void main(String[] args) { - SpringApplication.run(MultipleCachingApplication.class, args); - } -} \ No newline at end of file diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/CacheConfig.java b/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CacheConfig.java similarity index 95% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/CacheConfig.java rename to spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CacheConfig.java index a911bdf161..2072f5806a 100644 --- a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/CacheConfig.java +++ b/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CacheConfig.java @@ -1,4 +1,4 @@ -package com.baeldung.caching.multicache; +package com.baeldung.caching.twolevelcache; import com.github.benmanes.caffeine.cache.Caffeine; import org.springframework.cache.CacheManager; @@ -28,8 +28,7 @@ public class CacheConfig { @Primary public CacheManager caffeineCacheManager() { SimpleCacheManager manager = new SimpleCacheManager(); - manager.setCaches(Arrays.asList( - caffeineCacheConfig())); + manager.setCaches(Arrays.asList(caffeineCacheConfig())); return manager; } diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/Customer.java b/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/Customer.java similarity index 87% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/Customer.java rename to spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/Customer.java index 4632799a1c..a2d1a14ea3 100644 --- a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/Customer.java +++ b/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/Customer.java @@ -1,4 +1,4 @@ -package com.baeldung.caching.multicache; +package com.baeldung.caching.twolevelcache; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/CustomerCacheInterceptor.java b/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerCacheInterceptor.java similarity index 95% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/CustomerCacheInterceptor.java rename to spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerCacheInterceptor.java index 4c9a981489..f1a8dca0db 100644 --- a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/CustomerCacheInterceptor.java +++ b/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerCacheInterceptor.java @@ -1,4 +1,4 @@ -package com.baeldung.caching.multicache; +package com.baeldung.caching.twolevelcache; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/CustomerRepository.java b/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerRepository.java similarity index 76% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/CustomerRepository.java rename to spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerRepository.java index 3281e35c76..098112f152 100644 --- a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/CustomerRepository.java +++ b/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerRepository.java @@ -1,7 +1,6 @@ -package com.baeldung.caching.multicache; +package com.baeldung.caching.twolevelcache; import org.springframework.data.repository.CrudRepository; - public interface CustomerRepository extends CrudRepository { } diff --git a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/CustomerService.java b/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerService.java similarity index 94% rename from spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/CustomerService.java rename to spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerService.java index 14a7f293c8..68e78c9fdb 100644 --- a/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/multicache/CustomerService.java +++ b/spring-boot-modules/spring-caching-2/src/main/java/com/baeldung/caching/twolevelcache/CustomerService.java @@ -1,4 +1,4 @@ -package com.baeldung.caching.multicache; +package com.baeldung.caching.twolevelcache; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; diff --git a/spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/redis/ItemServiceCachingIntegrationTest.java b/spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/redis/ItemServiceCachingIntegrationTest.java index b070528bf6..e25773305a 100644 --- a/spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/redis/ItemServiceCachingIntegrationTest.java +++ b/spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/redis/ItemServiceCachingIntegrationTest.java @@ -1,5 +1,10 @@ package com.baeldung.caching.redis; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -19,11 +24,6 @@ import javax.annotation.PreDestroy; import java.io.IOException; import java.util.Optional; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - @Import({ CacheConfig.class, ItemService.class }) @ExtendWith(SpringExtension.class) @ImportAutoConfiguration(classes = { CacheAutoConfiguration.class, RedisAutoConfiguration.class }) diff --git a/spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/multicache/CustomerServiceCachingIntegrationTest.java b/spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/twolevelcache/CustomerServiceCachingIntegrationTest.java similarity index 99% rename from spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/multicache/CustomerServiceCachingIntegrationTest.java rename to spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/twolevelcache/CustomerServiceCachingIntegrationTest.java index df53eb2833..6aa3242c95 100644 --- a/spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/multicache/CustomerServiceCachingIntegrationTest.java +++ b/spring-boot-modules/spring-caching-2/src/test/java/com/baeldung/caching/twolevelcache/CustomerServiceCachingIntegrationTest.java @@ -1,4 +1,9 @@ -package com.baeldung.caching.multicache; +package com.baeldung.caching.twolevelcache; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -21,11 +26,6 @@ import java.io.IOException; import java.util.Optional; import java.util.concurrent.TimeUnit; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - @Import({ CacheConfig.class,CustomerService.class }) @ExtendWith(SpringExtension.class) @ImportAutoConfiguration(classes = { CacheAutoConfiguration.class, RedisAutoConfiguration.class })