diff --git a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java index c5c9f0978f..44ca01b25e 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java +++ b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -24,7 +24,6 @@ import net.sf.ehcache.Status; import org.springframework.cache.Cache; import org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager; -import org.springframework.util.Assert; /** * CacheManager backed by an EhCache {@link net.sf.ehcache.CacheManager}. @@ -81,8 +80,10 @@ public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManag @Override protected Collection loadCaches() { Status status = getCacheManager().getStatus(); - Assert.isTrue(Status.STATUS_ALIVE.equals(status), - "An 'alive' EhCache CacheManager is required - current cache is " + status.toString()); + if (!Status.STATUS_ALIVE.equals(status)) { + throw new IllegalStateException( + "An 'alive' EhCache CacheManager is required - current cache is " + status.toString()); + } String[] names = getCacheManager().getCacheNames(); Collection caches = new LinkedHashSet(names.length); @@ -94,8 +95,7 @@ public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManag @Override protected Cache getMissingCache(String name) { - // check the EhCache cache again - // (in case the cache was added at runtime) + // Check the EhCache cache again (in case the cache was added at runtime) Ehcache ehcache = getCacheManager().getEhcache(name); if (ehcache != null) { return new EhCacheCache(ehcache); diff --git a/spring-context-support/src/test/java/org/springframework/cache/ehcache/EhCacheCacheManagerTests.java b/spring-context-support/src/test/java/org/springframework/cache/ehcache/EhCacheCacheManagerTests.java index 4c3e41722b..e0f7db5f1e 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/ehcache/EhCacheCacheManagerTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/ehcache/EhCacheCacheManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -30,9 +30,12 @@ import org.springframework.cache.transaction.AbstractTransactionSupportingCacheM public class EhCacheCacheManagerTests extends AbstractTransactionSupportingCacheManagerTests { private CacheManager nativeCacheManager; + private EhCacheCacheManager cacheManager; + private EhCacheCacheManager transactionalCacheManager; + @Before public void setup() { nativeCacheManager = new CacheManager(new Configuration().name("EhCacheCacheManagerTests") @@ -58,7 +61,8 @@ public class EhCacheCacheManagerTests extends AbstractTransactionSupportingCache protected EhCacheCacheManager getCacheManager(boolean transactionAware) { if (transactionAware) { return transactionalCacheManager; - } else { + } + else { return cacheManager; } } @@ -77,4 +81,5 @@ public class EhCacheCacheManagerTests extends AbstractTransactionSupportingCache protected void removeNativeCache(String cacheName) { nativeCacheManager.removeCache(cacheName); } + } diff --git a/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheCacheManagerTests.java b/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheCacheManagerTests.java index b8f201e104..734622672f 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheCacheManagerTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheCacheManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -33,9 +33,12 @@ import static org.mockito.BDDMockito.*; public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheManagerTests { private CacheManagerMock cacheManagerMock; + private JCacheCacheManager cacheManager; + private JCacheCacheManager transactionalCacheManager; + @Before public void setupOnce() { cacheManagerMock = new CacheManagerMock(); @@ -55,7 +58,8 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM protected JCacheCacheManager getCacheManager(boolean transactionAware) { if (transactionAware) { return transactionalCacheManager; - } else { + } + else { return cacheManager; } } @@ -75,9 +79,11 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM cacheManagerMock.removeCache(cacheName); } + private static class CacheManagerMock { private final List cacheNames; + private final CacheManager cacheManager; private CacheManagerMock() { @@ -103,4 +109,5 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM given(cacheManager.getCache(name)).willReturn(null); } } + } diff --git a/spring-context-support/src/test/java/org/springframework/cache/transaction/AbstractTransactionSupportingCacheManagerTests.java b/spring-context-support/src/test/java/org/springframework/cache/transaction/AbstractTransactionSupportingCacheManagerTests.java index 3adb8bbea0..a86bd573cd 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/transaction/AbstractTransactionSupportingCacheManagerTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/transaction/AbstractTransactionSupportingCacheManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -42,11 +42,10 @@ public abstract class AbstractTransactionSupportingCacheManagerTests