DATAREDIS-687 - Polishing.
Parse Spring version for semantic version comparision. Remove redundant cast. Add issue tag to test, Visibility, formatting, imports. Original pull request: #273.
This commit is contained in:
@@ -13,20 +13,16 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.redis.cache;
|
||||
|
||||
import static edu.umd.cs.mtc.TestFramework.*;
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.hamcrest.core.IsEqual.*;
|
||||
import static org.hamcrest.core.IsInstanceOf.*;
|
||||
import static org.hamcrest.core.IsNot.*;
|
||||
import static org.hamcrest.core.IsNull.*;
|
||||
import static org.hamcrest.core.IsSame.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
|
||||
|
||||
import edu.umd.cs.mtc.MultithreadedTestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -54,8 +50,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
import edu.umd.cs.mtc.MultithreadedTestCase;
|
||||
import org.springframework.data.util.Version;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
@@ -67,6 +62,9 @@ import edu.umd.cs.mtc.MultithreadedTestCase;
|
||||
@RunWith(Parameterized.class)
|
||||
public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
|
||||
private static final Version SPRING_FRAMEWORK_VERSION = Version.parse(SpringVersion.getVersion());
|
||||
private static final Version SPRING_5 = Version.parse("5.0.0");
|
||||
|
||||
private ObjectFactory<Object> keyFactory;
|
||||
private ObjectFactory<Object> valueFactory;
|
||||
private RedisTemplate template;
|
||||
@@ -232,13 +230,14 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
|
||||
@Test // DATAREDIS-243
|
||||
public void testCacheGetShouldReturnCachedInstance() {
|
||||
|
||||
assumeThat(cache, instanceOf(RedisCache.class));
|
||||
|
||||
Object key = getKey();
|
||||
Object value = getValue();
|
||||
cache.put(key, value);
|
||||
|
||||
assertThat(value, isEqual(((RedisCache) cache).get(key, Object.class)));
|
||||
assertThat(value, isEqual(cache.get(key, Object.class)));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-243
|
||||
@@ -309,7 +308,6 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
assumeThat(getAllowCacheNullValues(), is(false));
|
||||
|
||||
Object key = getKey();
|
||||
Object value = getValue();
|
||||
|
||||
try {
|
||||
|
||||
@@ -317,13 +315,13 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
assertThat(cache.get(key), is(nullValue()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
if (!SpringVersion.getVersion().startsWith("5")) {
|
||||
if (SPRING_FRAMEWORK_VERSION.isLessThan(SPRING_5)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-510
|
||||
@Test // DATAREDIS-510, DATAREDIS-687
|
||||
public void cachePutWithNullShouldRemoveKeyIfExists() {
|
||||
|
||||
assumeThat(getAllowCacheNullValues(), is(false));
|
||||
@@ -341,7 +339,7 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
assertThat(cache.get(key), is(nullValue()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
if (!SpringVersion.getVersion().startsWith("5")) {
|
||||
if (SPRING_FRAMEWORK_VERSION.isLessThan(SPRING_5)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -362,7 +360,6 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
assumeThat(getAllowCacheNullValues(), is(true));
|
||||
|
||||
Object key = getKey();
|
||||
Object value = getValue();
|
||||
|
||||
cache.put(key, null);
|
||||
|
||||
@@ -409,7 +406,7 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
assertThat(cache.get(key), is(nullValue()));
|
||||
} catch (ValueRetrievalException e) {
|
||||
|
||||
if (!SpringVersion.getVersion().startsWith("5")) {
|
||||
if (SPRING_FRAMEWORK_VERSION.isLessThan(SPRING_5)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -440,7 +437,7 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
RedisCache redisCache;
|
||||
TestCacheLoader<String> cacheLoader;
|
||||
|
||||
public CacheGetWithValueLoaderIsThreadSafe(RedisCache redisCache) {
|
||||
CacheGetWithValueLoaderIsThreadSafe(RedisCache redisCache) {
|
||||
|
||||
this.redisCache = redisCache;
|
||||
|
||||
@@ -473,7 +470,7 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
|
||||
private final T value;
|
||||
|
||||
public TestCacheLoader(T value) {
|
||||
TestCacheLoader(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
package org.springframework.data.redis.cache;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.core.IsEqual.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -44,6 +44,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.ReturnType;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.util.Version;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
@@ -53,6 +54,9 @@ import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RedisCacheUnitTests {
|
||||
|
||||
private static final Version SPRING_FRAMEWORK_VERSION = Version.parse(SpringVersion.getVersion());
|
||||
private static final Version SPRING_5 = Version.parse("5.0.0");
|
||||
|
||||
private static final String CACHE_NAME = "foo";
|
||||
private static final String PREFIX = "prefix:";
|
||||
private static final byte[] PREFIX_BYTES = "prefix:".getBytes();
|
||||
@@ -212,7 +216,7 @@ public class RedisCacheUnitTests {
|
||||
|
||||
@Test // DATAREDIS-553, DATAREDIS-687
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getWithCallableShouldStoreNullNotAllowingNull() throws ClassNotFoundException {
|
||||
public void getWithCallableShouldStoreNullNotAllowingNull() {
|
||||
|
||||
cache = new RedisCache(CACHE_NAME, NO_PREFIX_BYTES, templateSpy, 0L, false);
|
||||
|
||||
@@ -232,7 +236,7 @@ public class RedisCacheUnitTests {
|
||||
|
||||
} catch (ValueRetrievalException e) {
|
||||
|
||||
if (!SpringVersion.getVersion().startsWith("5")) {
|
||||
if (SPRING_FRAMEWORK_VERSION.isLessThan(SPRING_5)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -240,7 +244,7 @@ public class RedisCacheUnitTests {
|
||||
|
||||
@Test // DATAREDIS-553
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getWithCallableShouldStoreNullAllowingNull() throws ClassNotFoundException {
|
||||
public void getWithCallableShouldStoreNullAllowingNull() {
|
||||
|
||||
cache = new RedisCache(CACHE_NAME, NO_PREFIX_BYTES, templateSpy, 0L, true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user