Skip to content

Commit 525d111

Browse files
committed
Polishing
1 parent 75ea6f5 commit 525d111

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
2424

2525
import org.springframework.cache.Cache;
2626
import org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager;
27-
import org.springframework.util.Assert;
2827

2928
/**
3029
* CacheManager backed by an EhCache {@link net.sf.ehcache.CacheManager}.
@@ -81,8 +80,10 @@ public void afterPropertiesSet() {
8180
@Override
8281
protected Collection<Cache> loadCaches() {
8382
Status status = getCacheManager().getStatus();
84-
Assert.isTrue(Status.STATUS_ALIVE.equals(status),
85-
"An 'alive' EhCache CacheManager is required - current cache is " + status.toString());
83+
if (!Status.STATUS_ALIVE.equals(status)) {
84+
throw new IllegalStateException(
85+
"An 'alive' EhCache CacheManager is required - current cache is " + status.toString());
86+
}
8687

8788
String[] names = getCacheManager().getCacheNames();
8889
Collection<Cache> caches = new LinkedHashSet<Cache>(names.length);
@@ -94,8 +95,7 @@ protected Collection<Cache> loadCaches() {
9495

9596
@Override
9697
protected Cache getMissingCache(String name) {
97-
// check the EhCache cache again
98-
// (in case the cache was added at runtime)
98+
// Check the EhCache cache again (in case the cache was added at runtime)
9999
Ehcache ehcache = getCacheManager().getEhcache(name);
100100
if (ehcache != null) {
101101
return new EhCacheCache(ehcache);

spring-context-support/src/test/java/org/springframework/cache/ehcache/EhCacheCacheManagerTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,9 +30,12 @@
3030
public class EhCacheCacheManagerTests extends AbstractTransactionSupportingCacheManagerTests<EhCacheCacheManager> {
3131

3232
private CacheManager nativeCacheManager;
33+
3334
private EhCacheCacheManager cacheManager;
35+
3436
private EhCacheCacheManager transactionalCacheManager;
3537

38+
3639
@Before
3740
public void setup() {
3841
nativeCacheManager = new CacheManager(new Configuration().name("EhCacheCacheManagerTests")
@@ -58,7 +61,8 @@ public void tearDown() {
5861
protected EhCacheCacheManager getCacheManager(boolean transactionAware) {
5962
if (transactionAware) {
6063
return transactionalCacheManager;
61-
} else {
64+
}
65+
else {
6266
return cacheManager;
6367
}
6468
}
@@ -77,4 +81,5 @@ protected void addNativeCache(String cacheName) {
7781
protected void removeNativeCache(String cacheName) {
7882
nativeCacheManager.removeCache(cacheName);
7983
}
84+
8085
}

spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheCacheManagerTests.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,9 +33,12 @@
3333
public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheManagerTests<JCacheCacheManager> {
3434

3535
private CacheManagerMock cacheManagerMock;
36+
3637
private JCacheCacheManager cacheManager;
38+
3739
private JCacheCacheManager transactionalCacheManager;
3840

41+
3942
@Before
4043
public void setupOnce() {
4144
cacheManagerMock = new CacheManagerMock();
@@ -55,7 +58,8 @@ public void setupOnce() {
5558
protected JCacheCacheManager getCacheManager(boolean transactionAware) {
5659
if (transactionAware) {
5760
return transactionalCacheManager;
58-
} else {
61+
}
62+
else {
5963
return cacheManager;
6064
}
6165
}
@@ -75,9 +79,11 @@ protected void removeNativeCache(String cacheName) {
7579
cacheManagerMock.removeCache(cacheName);
7680
}
7781

82+
7883
private static class CacheManagerMock {
7984

8085
private final List<String> cacheNames;
86+
8187
private final CacheManager cacheManager;
8288

8389
private CacheManagerMock() {
@@ -103,4 +109,5 @@ public void removeCache(String name) {
103109
given(cacheManager.getCache(name)).willReturn(null);
104110
}
105111
}
112+
106113
}

spring-context-support/src/test/java/org/springframework/cache/transaction/AbstractTransactionSupportingCacheManagerTests.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,11 +42,10 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
4242

4343
/**
4444
* Returns the {@link CacheManager} to use.
45-
*
4645
* @param transactionAware if the requested cache manager should be aware
4746
* of the transaction
4847
* @return the cache manager to use
49-
* @see org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager#setTransactionAware(boolean)
48+
* @see org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager#setTransactionAware
5049
*/
5150
protected abstract T getCacheManager(boolean transactionAware);
5251

@@ -65,6 +64,7 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
6564
*/
6665
protected abstract void removeNativeCache(String cacheName);
6766

67+
6868
@Test
6969
public void getOnExistingCache() {
7070
assertThat(getCacheManager(false).getCache(CACHE_NAME), is(instanceOf(getCacheType())));
@@ -77,10 +77,10 @@ public void getOnNewCache() {
7777
addNativeCache(cacheName);
7878
assertFalse(cacheManager.getCacheNames().contains(cacheName));
7979
try {
80-
assertThat(cacheManager.getCache(cacheName),
81-
is(instanceOf(getCacheType())));
80+
assertThat(cacheManager.getCache(cacheName), is(instanceOf(getCacheType())));
8281
assertTrue(cacheManager.getCacheNames().contains(cacheName));
83-
} finally {
82+
}
83+
finally {
8484
removeNativeCache(cacheName);
8585
}
8686
}
@@ -109,8 +109,10 @@ public void getTransactionalOnNewCache() {
109109
assertThat(cacheManager.getCache(cacheName),
110110
is(instanceOf(TransactionAwareCacheDecorator.class)));
111111
assertTrue(cacheManager.getCacheNames().contains(cacheName));
112-
} finally {
112+
}
113+
finally {
113114
removeNativeCache(cacheName);
114115
}
115116
}
117+
116118
}

0 commit comments

Comments
 (0)