From bdea1051deb72749eada4bdbf24bef27052839c7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 14 May 2014 15:08:57 +0100 Subject: [PATCH] DATAREDIS-299 - Assert compatibility with Spring IO. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upgrade to JUnit 4.11 Upgrade to JUnit 4.11 and remove use of a matcher in an internal package in favour of the Hamcrest equivalent. To avoid a clash between JUnit 4.11's Hamcrest dependency and the version of Hamcrest that's bundled in mockito-all, use of mockito-all has been replaced with mockito-core Add the Spring IO plugin Configure the Spring IO plugin such that it's only applied when the build is run with -PplatformVersion=. This platformVersion property is used to determine the version of the Platform that will be used when running the springIoCheck task. The plugin can be used by running a build as follows: ./gradlew clean springIoCheck -PplatformVersion=1.0.0.BUILD-SNAPSHOT -PJDK7_HOME=… -PJDK8_HOME=… This will test the project on JDK7 and JDK 8 using the dependencies defined in the latest snapshot of Spring IO Platform 1.0.0. Address Java 6 compilation problem The JUnit and Hamcrest upgrades caused a compilation error on Java 6 due to a bug in the compiler’s handling of generics. This commit adds more type information to help to guide the compiler around the problem. Additionally, deprecation warnings caused by the JUnit and Hamcrest upgrades have also been addressed. Original pull request: #72. --- build.gradle | 17 +++++++++++++++-- gradle.properties | 2 +- .../redis/cache/RedisCacheManagerUnitTests.java | 2 +- .../jedis/JedisConnectionIntegrationTests.java | 4 ++-- .../JRedisConnectionIntegrationTests.java | 2 +- .../LettuceConnectionIntegrationTests.java | 4 ++-- .../redis/core/DefaultSetOperationsTests.java | 12 ++++++++---- .../data/redis/listener/PubSubTests.java | 2 +- .../data/redis/matcher/Equals.java | 3 ++- .../AbstractRedisCollectionTests.java | 4 ++-- .../collections/AbstractRedisListTests.java | 4 ++-- .../collections/AbstractRedisMapTests.java | 4 ++-- .../collections/AbstractRedisSetTests.java | 1 - .../collections/AbstractRedisZSetTest.java | 4 ++-- .../RedisCollectionFactoryBeanTests.java | 6 +++--- 15 files changed, 44 insertions(+), 27 deletions(-) diff --git a/build.gradle b/build.gradle index dd1827b16..7fb11d851 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,7 @@ buildscript { dependencies { classpath 'org.springframework.build.gradle:bundlor-plugin:0.1.2' classpath 'org.springframework.build.gradle:docbook-reference-plugin:0.2.4' + classpath 'org.springframework.build.gradle:spring-io-plugin:0.0.3.RELEASE' classpath 'me.champeau.gradle:gradle-javadoc-hotfix-plugin:0.1' } } @@ -26,6 +27,18 @@ apply plugin: 'docbook-reference' apply plugin: 'bundlor' apply plugin: 'javadocHotfix' +if (project.hasProperty('platformVersion')) { + apply plugin: 'spring-io' + + repositories { + maven { url "https://repo.spring.io/libs-snapshot" } + } + + dependencies { + springIoVersions "io.spring.platform:platform-versions:${platformVersion}@properties" + } +} + [compileJava, compileTestJava]*.options*.compilerArgs = ["-Xlint:-serial"] [compileJava, compileTestJava]*.options*.compilerArgs = ["-Xlint:-serial", "-Xlint:deprecation"] @@ -44,7 +57,7 @@ dependencies { // Spring Framework compile("org.springframework:spring-core:$springVersion") { - exclude module: "commons-logging" + exclude group: "commons-logging", module: "commons-logging" } compile "org.springframework:spring-context-support:$springVersion" compile "org.springframework:spring-context:$springVersion" @@ -72,7 +85,7 @@ dependencies { testCompile "junit:junit:$junitVersion" testCompile "org.springframework:spring-test:$springVersion" testCompile "org.springframework:spring-jdbc:$springVersion" - testCompile "org.mockito:mockito-all:$mockitoVersion" + testCompile "org.mockito:mockito-core:$mockitoVersion" testCompile("javax.annotation:jsr250-api:1.0", optional) testCompile("com.thoughtworks.xstream:xstream:1.4.4", optional) testCompile("javax.transaction:jta:1.1") diff --git a/gradle.properties b/gradle.properties index f09fb8eb5..bc3dfaec5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ slf4jVersion=1.7.5 -junitVersion=4.10 +junitVersion=4.11 jredisVersion=06052013 jedisVersion=2.4.1 springVersion=3.2.8.RELEASE diff --git a/src/test/java/org/springframework/data/redis/cache/RedisCacheManagerUnitTests.java b/src/test/java/org/springframework/data/redis/cache/RedisCacheManagerUnitTests.java index 17f2cdd25..ab7e8e3cb 100644 --- a/src/test/java/org/springframework/data/redis/cache/RedisCacheManagerUnitTests.java +++ b/src/test/java/org/springframework/data/redis/cache/RedisCacheManagerUnitTests.java @@ -27,9 +27,9 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; +import org.hamcrest.core.IsCollectionContaining; import org.junit.Before; import org.junit.Test; -import org.junit.internal.matchers.IsCollectionContaining; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java index 81971162f..51b9f4b91 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java @@ -27,10 +27,10 @@ import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.TimeUnit; import org.hamcrest.core.AllOf; +import org.hamcrest.core.IsCollectionContaining; import org.hamcrest.core.IsInstanceOf; import org.junit.After; import org.junit.Test; -import org.junit.internal.matchers.IsCollectionContaining; import org.junit.runner.RunWith; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.redis.SettingsUtils; @@ -331,7 +331,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati connection.set("redis", "supercalifragilisticexpialidocious"); assertThat( - connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes()), + (Iterable)connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes()), AllOf.allOf(IsInstanceOf.instanceOf(List.class), IsCollectionContaining.hasItems("awesome".getBytes(), "cool".getBytes(), "supercalifragilisticexpialidocious".getBytes()))); } diff --git a/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java index ad9707887..4aa7f1a8c 100644 --- a/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java @@ -25,13 +25,13 @@ import java.util.List; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.hamcrest.core.IsInstanceOf; +import org.hamcrest.core.IsCollectionContaining; import org.jredis.JRedis; import org.jredis.protocol.BulkResponse; import org.jredis.ri.alphazero.protocol.SyncProtocol.SyncMultiBulkResponse; import org.junit.After; import org.junit.Ignore; import org.junit.Test; -import org.junit.internal.matchers.IsCollectionContaining; import org.junit.runner.RunWith; import org.springframework.dao.DataAccessException; import org.springframework.data.redis.RedisConnectionFailureException; diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java index 5ef58a80c..729014cee 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java @@ -25,9 +25,9 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import org.hamcrest.core.AllOf; +import org.hamcrest.core.IsCollectionContaining; import org.hamcrest.core.IsInstanceOf; import org.junit.Test; -import org.junit.internal.matchers.IsCollectionContaining; import org.junit.runner.RunWith; import org.springframework.dao.DataAccessException; import org.springframework.data.redis.RedisSystemException; @@ -293,7 +293,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra connection.set("redis", "supercalifragilisticexpialidocious"); assertThat( - connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes()), + (Iterable)connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes()), AllOf.allOf(IsInstanceOf.instanceOf(List.class), IsCollectionContaining.hasItems("awesome".getBytes(), "cool".getBytes(), "supercalifragilisticexpialidocious".getBytes()))); } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java index 6b44edfd7..5ab5d1093 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java @@ -15,14 +15,14 @@ */ package org.springframework.data.redis.core; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.either; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; -import static org.junit.matchers.JUnitMatchers.hasItem; -import static org.junit.matchers.JUnitMatchers.hasItems; -import static org.junit.matchers.JUnitMatchers.either; import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual; import java.util.Collection; @@ -31,6 +31,9 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.hamcrest.CoreMatchers; +import org.hamcrest.core.CombinableMatcher; +import org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -115,7 +118,8 @@ public class DefaultSetOperationsTests { setOps.add(setKey, v2); List members = setOps.randomMembers(setKey, 2); assertEquals(2, members.size()); - assertThat(members, either(hasItem(v1)).or(hasItem(v2))); + + assertThat(members, CoreMatchers.>either(hasItem(v1)).or(hasItem(v2))); } @Test diff --git a/src/test/java/org/springframework/data/redis/listener/PubSubTests.java b/src/test/java/org/springframework/data/redis/listener/PubSubTests.java index 01b904f36..c99fffa2f 100644 --- a/src/test/java/org/springframework/data/redis/listener/PubSubTests.java +++ b/src/test/java/org/springframework/data/redis/listener/PubSubTests.java @@ -15,11 +15,11 @@ */ package org.springframework.data.redis.listener; +import static org.hamcrest.CoreMatchers.hasItems; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assume.assumeTrue; -import static org.junit.matchers.JUnitMatchers.hasItems; import java.util.Arrays; import java.util.Collection; diff --git a/src/test/java/org/springframework/data/redis/matcher/Equals.java b/src/test/java/org/springframework/data/redis/matcher/Equals.java index 84790c01b..096b47c7c 100644 --- a/src/test/java/org/springframework/data/redis/matcher/Equals.java +++ b/src/test/java/org/springframework/data/redis/matcher/Equals.java @@ -15,6 +15,8 @@ */ package org.springframework.data.redis.matcher; +import static org.hamcrest.CoreMatchers.hasItems; + import java.util.Arrays; import java.util.Collection; import java.util.Iterator; @@ -27,7 +29,6 @@ import java.util.Set; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; -import static org.junit.matchers.JUnitMatchers.hasItems; /** * Custom JUnit {@link Matcher} that exists to properly compare byte arrays, either as individual results or members of diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java index d27c35181..34c671829 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java @@ -16,6 +16,8 @@ package org.springframework.data.redis.support.collections; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertArrayEquals; @@ -24,8 +26,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.junit.matchers.JUnitMatchers.hasItem; -import static org.junit.matchers.JUnitMatchers.hasItems; import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual; import java.util.Arrays; diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java index 9b79758e6..945b8de1c 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java @@ -15,14 +15,14 @@ */ package org.springframework.data.redis.support.collections; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.hasItems; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; -import static org.junit.matchers.JUnitMatchers.hasItem; -import static org.junit.matchers.JUnitMatchers.hasItems; import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual; import java.util.ArrayList; diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java index 42572eaf3..fbe468493 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java @@ -16,6 +16,8 @@ package org.springframework.data.redis.support.collections; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -24,8 +26,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; -import static org.junit.matchers.JUnitMatchers.hasItem; -import static org.junit.matchers.JUnitMatchers.hasItems; import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual; import java.text.DecimalFormat; diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java index 724314526..2d274d8c4 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java @@ -17,7 +17,6 @@ package org.springframework.data.redis.support.collections; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; -import static org.junit.matchers.JUnitMatchers.*; import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual; import java.util.ArrayList; diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java index 654df2729..6d725b34a 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java @@ -15,14 +15,14 @@ */ package org.springframework.data.redis.support.collections; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.hasItems; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assume.assumeTrue; -import static org.junit.matchers.JUnitMatchers.hasItem; -import static org.junit.matchers.JUnitMatchers.hasItems; import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual; import java.util.Arrays; diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java index 4836b0dfa..002cae4b4 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java @@ -115,15 +115,15 @@ public class RedisCollectionFactoryBeanTests { template.boundSetOps(key).add(val); RedisStore col = createCollection(key); - assertThat(col, is(DefaultRedisSet.class)); + assertThat(col, instanceOf(DefaultRedisSet.class)); key = "map"; template.boundHashOps(key).put(val, val); col = createCollection(key); - assertThat(col, is(DefaultRedisMap.class)); + assertThat(col, instanceOf(DefaultRedisMap.class)); col = createCollection(key, CollectionType.PROPERTIES); - assertThat(col, is(RedisProperties.class)); + assertThat(col, instanceOf(RedisProperties.class)); } }