Refactor jcache examples (#2620)
This commit is contained in:
parent
8e7fc431a0
commit
556e8fa90b
|
@ -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<Integer, String> 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++) {
|
||||
|
|
|
@ -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<String, String> cache;
|
||||
|
||||
@Before
|
||||
public void instantiateCache() {
|
||||
CachingProvider cachingProvider = Caching.getCachingProvider();
|
||||
CacheManager cacheManager = cachingProvider.getCacheManager();
|
||||
MutableConfiguration<String, String> config = new MutableConfiguration<String, String>();
|
||||
this.cache = cacheManager.createCache("MyCache", config);
|
||||
MutableConfiguration<String, String> 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());
|
||||
|
|
|
@ -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<String, String> cache;
|
||||
private SimpleCacheEntryListener listener;
|
||||
MutableCacheEntryListenerConfiguration<String, String> listenerConfiguration;
|
||||
private MutableCacheEntryListenerConfiguration<String, String> 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<String, String>(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());
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
Loading…
Reference in New Issue