diff --git a/libraries/src/test/java/com/baeldung/jcache/CacheLoaderTest.java b/libraries/src/test/java/com/baeldung/jcache/CacheLoaderTest.java index e2167b39ad..e1219e6c49 100644 --- a/libraries/src/test/java/com/baeldung/jcache/CacheLoaderTest.java +++ b/libraries/src/test/java/com/baeldung/jcache/CacheLoaderTest.java @@ -9,11 +9,14 @@ import javax.cache.configuration.FactoryBuilder; import javax.cache.configuration.MutableConfiguration; import javax.cache.spi.CachingProvider; +import org.junit.After; import org.junit.Before; import org.junit.Test; public class CacheLoaderTest { + private static final String CACHE_NAME = "SimpleCache"; + private Cache cache; @Before @@ -25,6 +28,12 @@ public class CacheLoaderTest { this.cache = cacheManager.createCache("SimpleCache", config); } + @After + public void tearDown() { + Caching.getCachingProvider() + .getCacheManager().destroyCache(CACHE_NAME); + } + @Test public void whenReadingFromStorage_thenCorrect() { for (int i = 1; i < 4; i++) { diff --git a/libraries/src/test/java/com/baeldung/jcache/EntryProcessorTest.java b/libraries/src/test/java/com/baeldung/jcache/EntryProcessorTest.java index fba6067885..741bdc7389 100644 --- a/libraries/src/test/java/com/baeldung/jcache/EntryProcessorTest.java +++ b/libraries/src/test/java/com/baeldung/jcache/EntryProcessorTest.java @@ -1,6 +1,8 @@ package com.baeldung.jcache; -import static org.junit.Assert.assertEquals; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import javax.cache.Cache; import javax.cache.CacheManager; @@ -8,22 +10,29 @@ import javax.cache.Caching; import javax.cache.configuration.MutableConfiguration; import javax.cache.spi.CachingProvider; -import org.junit.Before; -import org.junit.Test; +import static org.junit.Assert.assertEquals; public class EntryProcessorTest { + private static final String CACHE_NAME = "MyCache"; + private Cache cache; @Before public void instantiateCache() { CachingProvider cachingProvider = Caching.getCachingProvider(); CacheManager cacheManager = cachingProvider.getCacheManager(); - MutableConfiguration config = new MutableConfiguration(); - this.cache = cacheManager.createCache("MyCache", config); + MutableConfiguration config = new MutableConfiguration<>(); + this.cache = cacheManager.createCache(CACHE_NAME, config); this.cache.put("key", "value"); } + @After + public void tearDown() { + Caching.getCachingProvider() + .getCacheManager().destroyCache(CACHE_NAME); + } + @Test public void whenModifyValue_thenCorrect() { this.cache.invoke("key", new SimpleEntryProcessor()); diff --git a/libraries/src/test/java/com/baeldung/jcache/EventListenerTest.java b/libraries/src/test/java/com/baeldung/jcache/EventListenerTest.java index 5fb0b317e2..b32fe795de 100644 --- a/libraries/src/test/java/com/baeldung/jcache/EventListenerTest.java +++ b/libraries/src/test/java/com/baeldung/jcache/EventListenerTest.java @@ -1,6 +1,8 @@ package com.baeldung.jcache; -import static org.junit.Assert.assertEquals; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import javax.cache.Cache; import javax.cache.CacheManager; @@ -10,14 +12,15 @@ import javax.cache.configuration.MutableCacheEntryListenerConfiguration; import javax.cache.configuration.MutableConfiguration; import javax.cache.spi.CachingProvider; -import org.junit.Before; -import org.junit.Test; +import static org.junit.Assert.assertEquals; public class EventListenerTest { + private static final String CACHE_NAME = "MyCache"; + private Cache cache; private SimpleCacheEntryListener listener; - MutableCacheEntryListenerConfiguration listenerConfiguration; + private MutableCacheEntryListenerConfiguration listenerConfiguration; @Before public void setup() { @@ -28,9 +31,16 @@ public class EventListenerTest { this.listener = new SimpleCacheEntryListener(); } + @After + public void tearDown() { + Caching.getCachingProvider() + .getCacheManager().destroyCache(CACHE_NAME); + } + @Test public void whenRunEvent_thenCorrect() throws InterruptedException { - this.listenerConfiguration = new MutableCacheEntryListenerConfiguration(FactoryBuilder.factoryOf(this.listener), null, false, true); + this.listenerConfiguration = new MutableCacheEntryListenerConfiguration<>(FactoryBuilder + .factoryOf(this.listener), null, false, true); this.cache.registerCacheEntryListener(this.listenerConfiguration); assertEquals(false, this.listener.getCreated()); diff --git a/libraries/src/test/java/com/baeldung/jcache/JCacheTest.java b/libraries/src/test/java/com/baeldung/jcache/JCacheTest.java index 2c86a236b4..faf3ec9597 100644 --- a/libraries/src/test/java/com/baeldung/jcache/JCacheTest.java +++ b/libraries/src/test/java/com/baeldung/jcache/JCacheTest.java @@ -1,6 +1,6 @@ package com.baeldung.jcache; -import static org.junit.Assert.assertEquals; +import org.junit.Test; import javax.cache.Cache; import javax.cache.CacheManager; @@ -8,7 +8,7 @@ import javax.cache.Caching; import javax.cache.configuration.MutableConfiguration; import javax.cache.spi.CachingProvider; -import org.junit.Test; +import static org.junit.Assert.assertEquals; public class JCacheTest {