diff --git a/spring-data-geode/pom.xml b/spring-data-geode/pom.xml
index 38ca267f..8ac402d1 100644
--- a/spring-data-geode/pom.xml
+++ b/spring-data-geode/pom.xml
@@ -217,20 +217,6 @@
test
-
- org.hamcrest
- hamcrest-core
- ${hamcrest}
- test
-
-
-
- org.hamcrest
- hamcrest-library
- ${hamcrest}
- test
-
-
org.iq80.snappy
snappy
diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/IndexMaintenancePolicyType.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/IndexMaintenancePolicyType.java
index 82caf3ae..ff386e40 100644
--- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/IndexMaintenancePolicyType.java
+++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/IndexMaintenancePolicyType.java
@@ -13,14 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.gemfire;
import org.apache.geode.cache.AttributesFactory;
import org.apache.geode.cache.RegionFactory;
/**
- * The IndexMaintenanceType enum is a enumerated type of GemFire Index maintenance update options.
+ * The {@link IndexMaintenancePolicyType} enum is a enumerated type of GemFire Index maintenance update options.
*
* @author John Blum
* @see org.apache.geode.cache.AttributesFactory#setIndexMaintenanceSynchronous(boolean)
@@ -30,6 +29,7 @@ import org.apache.geode.cache.RegionFactory;
*/
@SuppressWarnings("unused")
public enum IndexMaintenancePolicyType {
+
SYNCHRONOUS,
ASYNCHRONOUS;
@@ -45,7 +45,8 @@ public enum IndexMaintenancePolicyType {
* @see java.lang.String#equalsIgnoreCase(String)
* @see #name()
*/
- public static IndexMaintenancePolicyType valueOfIgnoreCase(final String name) {
+ public static IndexMaintenancePolicyType valueOfIgnoreCase(String name) {
+
for (IndexMaintenancePolicyType indexMaintenancePolicyType : values()) {
if (indexMaintenancePolicyType.name().equalsIgnoreCase(name)) {
return indexMaintenancePolicyType;
@@ -64,7 +65,7 @@ public enum IndexMaintenancePolicyType {
* @see #setIndexMaintenance(org.apache.geode.cache.RegionFactory)
*/
@SuppressWarnings("deprecation")
- public void setIndexMaintenance(final AttributesFactory attributesFactory) {
+ public void setIndexMaintenance(AttributesFactory, ?> attributesFactory) {
attributesFactory.setIndexMaintenanceSynchronous(equals(SYNCHRONOUS));
}
@@ -76,8 +77,7 @@ public enum IndexMaintenancePolicyType {
* @throws java.lang.NullPointerException if the RegionFactory reference is null.
* @see #setIndexMaintenance(org.apache.geode.cache.AttributesFactory)
*/
- public void setIndexMaintenance(final RegionFactory regionFactory) {
+ public void setIndexMaintenance(RegionFactory, ?> regionFactory) {
regionFactory.setIndexMaintenanceSynchronous(equals(SYNCHRONOUS));
}
-
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateIntegrationTests.java
index f9c8f190..c67025d4 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateIntegrationTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireTemplateIntegrationTests.java
@@ -16,8 +16,7 @@
package org.springframework.data.gemfire;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assume.assumeThat;
+import static org.assertj.core.api.Assumptions.assumeThat;
import java.time.Instant;
import java.util.ArrayList;
@@ -190,7 +189,7 @@ public class GemfireTemplateIntegrationTests extends IntegrationTestsSupport {
@Test
public void containsKeyOnServer() {
- assumeThat(CacheUtils.isClient(this.gemfireCache), is(true));
+ assumeThat(CacheUtils.isClient(this.gemfireCache)).isTrue();
assertThat(this.usersTemplate.containsKeyOnServer(getKey(getUser("jackHandy")))).isTrue();
assertThat(this.usersTemplate.containsKeyOnServer("maxPayne")).isFalse();
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireUtilsTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireUtilsUnitTests.java
similarity index 79%
rename from spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireUtilsTest.java
rename to spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireUtilsUnitTests.java
index e4589a90..bbc8663a 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireUtilsTest.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/GemfireUtilsUnitTests.java
@@ -13,45 +13,42 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.gemfire;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import java.util.Properties;
+import org.junit.Test;
+
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.distributed.DistributedSystem;
-import org.junit.Test;
-
/**
- * The GemfireUtilsTest class is a test suite of test cases testing the contract and functionality of the GemfireUtils
- * abstract utility class.
+ * Unit Tests for {@link GemfireUtils}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.GemfireUtils
* @since 1.3.3
*/
-public class GemfireUtilsTest {
+public class GemfireUtilsUnitTests {
@Test
public void isClientWithClientIsTrue() {
ClientCache mockClient = mock(ClientCache.class);
- assertThat(GemfireUtils.isClient(mockClient), is(true));
+ assertThat(GemfireUtils.isClient(mockClient)).isTrue();
- verifyZeroInteractions(mockClient);
+ verifyNoInteractions(mockClient);
}
@Test
@@ -59,9 +56,9 @@ public class GemfireUtilsTest {
Cache mockCache = mock(Cache.class);
- assertThat(GemfireUtils.isClient(mockCache), is(false));
+ assertThat(GemfireUtils.isClient(mockCache)).isFalse();
- verifyZeroInteractions(mockCache);
+ verifyNoInteractions(mockCache);
}
@Test
@@ -79,7 +76,7 @@ public class GemfireUtilsTest {
when(mockDistributedSystem.isConnected()).thenReturn(true);
when(mockDistributedSystem.getProperties()).thenReturn(gemfireProperties);
- assertThat(GemfireUtils.isDurable(mockClientCache), is(true));
+ assertThat(GemfireUtils.isDurable(mockClientCache)).isTrue();
verify(mockClientCache, times(1)).getDistributedSystem();
verify(mockDistributedSystem, times(1)).isConnected();
@@ -101,7 +98,7 @@ public class GemfireUtilsTest {
when(mockDistributedSystem.isConnected()).thenReturn(true);
when(mockDistributedSystem.getProperties()).thenReturn(gemfireProperties);
- assertThat(GemfireUtils.isDurable(mockClientCache), is(false));
+ assertThat(GemfireUtils.isDurable(mockClientCache)).isFalse();
verify(mockClientCache, times(1)).getDistributedSystem();
verify(mockDistributedSystem, times(1)).isConnected();
@@ -118,7 +115,7 @@ public class GemfireUtilsTest {
when(mockClientCache.getDistributedSystem()).thenReturn(mockDistributedSystem);
when(mockDistributedSystem.isConnected()).thenReturn(false);
- assertThat(GemfireUtils.isDurable(mockClientCache), is(false));
+ assertThat(GemfireUtils.isDurable(mockClientCache)).isFalse();
verify(mockClientCache, times(1)).getDistributedSystem();
verify(mockDistributedSystem, times(1)).isConnected();
@@ -130,9 +127,9 @@ public class GemfireUtilsTest {
Cache mockCache = mock(Cache.class);
- assertThat(GemfireUtils.isPeer(mockCache), is(true));
+ assertThat(GemfireUtils.isPeer(mockCache)).isTrue();
- verifyZeroInteractions(mockCache);
+ verifyNoInteractions(mockCache);
}
@Test
@@ -140,8 +137,8 @@ public class GemfireUtilsTest {
ClientCache mockClientCache = mock(ClientCache.class);
- assertThat(GemfireUtils.isPeer(mockClientCache), is(false));
+ assertThat(GemfireUtils.isPeer(mockClientCache)).isFalse();
- verifyZeroInteractions(mockClientCache);
+ verifyNoInteractions(mockClientCache);
}
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexMaintenancePolicyConverterUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexMaintenancePolicyConverterUnitTests.java
index 8393c10d..f616d44f 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexMaintenancePolicyConverterUnitTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexMaintenancePolicyConverterUnitTests.java
@@ -13,20 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.gemfire;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
import org.junit.After;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
/**
- * Unit tests for {@link IndexMaintenancePolicyConverter}.
+ * Unit Tests for {@link IndexMaintenancePolicyConverter}.
*
* @author John Blum
* @see org.junit.Test
@@ -36,9 +31,6 @@ import org.junit.rules.ExpectedException;
*/
public class IndexMaintenancePolicyConverterUnitTests {
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
private final IndexMaintenancePolicyConverter converter = new IndexMaintenancePolicyConverter();
@After
@@ -48,37 +40,53 @@ public class IndexMaintenancePolicyConverterUnitTests {
@Test
public void convert() {
+
assertThat(converter.convert("asynchronous")).isEqualTo(IndexMaintenancePolicyType.ASYNCHRONOUS);
assertThat(converter.convert("Synchronous")).isEqualTo(IndexMaintenancePolicyType.SYNCHRONOUS);
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void convertIllegalValue() {
- exception.expect(IllegalArgumentException.class);
- exception.expectCause(is(nullValue(Throwable.class)));
- exception.expectMessage("[sync] is not a valid IndexMaintenancePolicyType");
- converter.convert("sync");
+ try {
+ converter.convert("sync");
+ }
+ catch (IllegalArgumentException expected) {
+
+ assertThat(expected).hasMessage("[sync] is not a valid IndexMaintenancePolicyType");
+ assertThat(expected).hasNoCause();
+
+ throw expected;
+ }
}
@Test
public void setAsText() {
+
assertThat(converter.getValue()).isNull();
+
converter.setAsText("aSynchronous");
+
assertThat(converter.getValue()).isEqualTo(IndexMaintenancePolicyType.ASYNCHRONOUS);
+
converter.setAsText("synchrONoUS");
+
assertThat(converter.getValue()).isEqualTo(IndexMaintenancePolicyType.SYNCHRONOUS);
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void setAsTextWithIllegalValue() {
- try {
- exception.expect(IllegalArgumentException.class);
- exception.expectCause(is(nullValue(Throwable.class)));
- exception.expectMessage("[async] is not a valid IndexMaintenancePolicyType");
+ try {
converter.setAsText("async");
}
+ catch (IllegalArgumentException expected) {
+
+ assertThat(expected).hasMessage("[async] is not a valid IndexMaintenancePolicyType");
+ assertThat(expected).hasNoCause();
+
+ throw expected;
+ }
finally {
assertThat(converter.getValue()).isNull();
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexTypeConverterUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexTypeConverterUnitTests.java
index 99b0d1d7..9d5f27ff 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexTypeConverterUnitTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/IndexTypeConverterUnitTests.java
@@ -13,20 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.gemfire;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
import org.junit.After;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
/**
- * Unit tests for {@link IndexTypeConverter}.
+ * Unit Tests for {@link IndexTypeConverter}.
*
* @author John Blum
* @see org.junit.Test
@@ -36,9 +31,6 @@ import org.junit.rules.ExpectedException;
*/
public class IndexTypeConverterUnitTests {
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
private final IndexTypeConverter converter = new IndexTypeConverter();
@After
@@ -48,6 +40,7 @@ public class IndexTypeConverterUnitTests {
@Test
public void convert() {
+
assertThat(converter.convert("FUNCTIONAL")).isEqualTo(IndexType.FUNCTIONAL);
assertThat(converter.convert("hASh")).isEqualTo(IndexType.HASH);
assertThat(converter.convert("hASH")).isEqualTo(IndexType.HASH);
@@ -55,33 +48,48 @@ public class IndexTypeConverterUnitTests {
assertThat(converter.convert("primary_KEY")).isEqualTo(IndexType.PRIMARY_KEY);
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void convertWithIllegalValue() {
- exception.expect(IllegalArgumentException.class);
- exception.expectCause(is(nullValue(Throwable.class)));
- exception.expectMessage("[function] is not a valid IndexType");
- converter.convert("function");
+ try {
+ converter.convert("function");
+ }
+ catch (IllegalArgumentException expected) {
+
+ assertThat(expected).hasMessage("[function] is not a valid IndexType");
+ assertThat(expected).hasNoCause();
+
+ throw expected;
+ }
}
@Test
public void setAsText() {
+
assertThat(converter.getValue()).isNull();
+
converter.setAsText("HasH");
+
assertThat(converter.getValue()).isEqualTo(IndexType.HASH);
+
converter.setAsText("key");
+
assertThat(converter.getValue()).isEqualTo(IndexType.KEY);
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void setAsTextWithIllegalValue() {
- try {
- exception.expect(IllegalArgumentException.class);
- exception.expectCause(is(nullValue(Throwable.class)));
- exception.expectMessage("[invalid] is not a valid IndexType");
+ try {
converter.setAsText("invalid");
}
+ catch (IllegalArgumentException expected) {
+
+ assertThat(expected).hasMessage("[invalid] is not a valid IndexType");
+ assertThat(expected).hasNoCause();
+
+ throw expected;
+ }
finally {
assertThat(converter.getValue()).isNull();
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/InterestPolicyConverterUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/InterestPolicyConverterUnitTests.java
index ce074e18..8a432cc8 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/InterestPolicyConverterUnitTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/InterestPolicyConverterUnitTests.java
@@ -13,35 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.gemfire;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
+
+import org.junit.After;
+import org.junit.Test;
import org.apache.geode.cache.InterestPolicy;
-import org.junit.After;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
/**
- * Unit tests for {@link InterestPolicyConverter}.
+ * Unit Tests for {@link InterestPolicyConverter}.
*
* @author John Blum
* @see org.junit.Test
- * @see org.springframework.data.gemfire.InterestPolicyConverter
* @see org.apache.geode.cache.InterestPolicy
+ * @see org.springframework.data.gemfire.InterestPolicyConverter
* @since 1.6.0
*/
public class InterestPolicyConverterUnitTests {
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
- private InterestPolicyConverter converter = new InterestPolicyConverter();
+ private final InterestPolicyConverter converter = new InterestPolicyConverter();
@After
public void tearDown() {
@@ -50,39 +42,55 @@ public class InterestPolicyConverterUnitTests {
@Test
public void convert() {
+
assertThat(converter.convert("all")).isEqualTo(InterestPolicy.ALL);
assertThat(converter.convert("Cache_Content")).isEqualTo(InterestPolicy.CACHE_CONTENT);
assertThat(converter.convert("CACHE_ConTent")).isEqualTo(InterestPolicy.CACHE_CONTENT);
assertThat(converter.convert("ALL")).isEqualTo(InterestPolicy.ALL);
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void convertIllegalValue() {
- exception.expect(IllegalArgumentException.class);
- exception.expectCause(is(nullValue(Throwable.class)));
- exception.expectMessage("[invalid_value] is not a valid InterestPolicy");
- converter.convert("invalid_value");
+ try {
+ converter.convert("invalid_value");
+ }
+ catch (IllegalArgumentException expected) {
+
+ assertThat(expected).hasMessage("[invalid_value] is not a valid InterestPolicy");
+ assertThat(expected).hasNoCause();
+
+ throw expected;
+ }
}
@Test
public void setAsText() {
+
assertThat(converter.getValue()).isNull();
+
converter.setAsText("aLl");
+
assertThat(converter.getValue()).isEqualTo(InterestPolicy.ALL);
+
converter.setAsText("Cache_CoNTeNT");
+
assertThat(converter.getValue()).isEqualTo(InterestPolicy.CACHE_CONTENT);
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void setAsTextWithInvalidValue() {
- try {
- exception.expect(IllegalArgumentException.class);
- exception.expectCause(is(nullValue(Throwable.class)));
- exception.expectMessage("[none] is not a valid InterestPolicy");
+ try {
converter.setAsText("none");
}
+ catch (IllegalArgumentException expected) {
+
+ assertThat(expected).hasMessage("[none] is not a valid InterestPolicy");
+ assertThat(expected).hasNoCause();
+
+ throw expected;
+ }
finally {
assertThat(converter.getValue()).isNull();
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/ScopeConverterUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/ScopeConverterUnitTests.java
index 1f2ee3cb..969f3cb8 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/ScopeConverterUnitTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/ScopeConverterUnitTests.java
@@ -13,22 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.gemfire;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
+
+import org.junit.After;
+import org.junit.Test;
import org.apache.geode.cache.Scope;
-import org.junit.After;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
/**
- * Unit tests for {@link ScopeConverter}.
+ * Unit Tests for {@link ScopeConverter}.
*
* @author John Blum
* @see org.junit.Test
@@ -38,9 +33,6 @@ import org.junit.rules.ExpectedException;
*/
public class ScopeConverterUnitTests {
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
private final ScopeConverter converter = new ScopeConverter();
@After
@@ -50,39 +42,55 @@ public class ScopeConverterUnitTests {
@Test
public void convert() {
+
assertThat(converter.convert("distributed-ACK")).isEqualTo(Scope.DISTRIBUTED_ACK);
assertThat(converter.convert(" Distributed_NO-aCK")).isEqualTo(Scope.DISTRIBUTED_NO_ACK);
assertThat(converter.convert("loCAL ")).isEqualTo(Scope.LOCAL);
assertThat(converter.convert(" GLOBal ")).isEqualTo(Scope.GLOBAL);
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void convertIllegalValue() {
- exception.expect(IllegalArgumentException.class);
- exception.expectCause(is(nullValue(Throwable.class)));
- exception.expectMessage("[illegal-value] is not a valid Scope");
- converter.convert("illegal-value");
+ try {
+ converter.convert("illegal-value");
+ }
+ catch (IllegalArgumentException expected) {
+
+ assertThat(expected).hasMessage("[illegal-value] is not a valid Scope");
+ assertThat(expected).hasNoCause();
+
+ throw expected;
+ }
}
@Test
public void setAsText() {
+
assertThat(converter.getValue()).isNull();
+
converter.setAsText("DisTributeD-nO_Ack");
+
assertThat(converter.getValue()).isEqualTo(Scope.DISTRIBUTED_NO_ACK);
+
converter.setAsText("distributed-ack");
+
assertThat(converter.getValue()).isEqualTo(Scope.DISTRIBUTED_ACK);
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void setAsTextWithIllegalValue() {
- try {
- exception.expect(IllegalArgumentException.class);
- exception.expectCause(is(nullValue(Throwable.class)));
- exception.expectMessage("[d!5tr!but3d-n0_@ck] is not a valid Scope");
+ try {
converter.setAsText("d!5tr!but3d-n0_@ck");
}
+ catch (IllegalArgumentException expected) {
+
+ assertThat(expected).hasMessage("[d!5tr!but3d-n0_@ck] is not a valid Scope");
+ assertThat(expected).hasNoCause();
+
+ throw expected;
+ }
finally {
assertThat(converter.getValue()).isNull();
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CallableCacheLoaderAdapterTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CallableCacheLoaderAdapterTest.java
index 70a44bc0..fab21e41 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CallableCacheLoaderAdapterTest.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/CallableCacheLoaderAdapterTest.java
@@ -14,15 +14,9 @@
* limitations under the License.
*
*/
-
package org.springframework.data.gemfire.cache;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-import static org.hamcrest.Matchers.sameInstance;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
@@ -30,12 +24,9 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
@@ -44,14 +35,11 @@ import org.apache.geode.cache.LoaderHelper;
import org.apache.geode.cache.Region;
/**
- * Unit tests to test the adaption of the {@link java.util.concurrent.Callable}
- * into GemFire's {@link org.apache.geode.cache.CacheLoader} interface.
+ * Unit Tests to test the adaption of the {@link java.util.concurrent.Callable}
+ * into Apache Geode's {@link org.apache.geode.cache.CacheLoader} interface.
*
* @author John Blum
- * @see org.junit.Rule
* @see org.junit.Test
- * @see org.junit.rules.ExpectedException
- * @see org.junit.runner.RunWith
* @see org.mockito.Mock
* @see org.mockito.Mockito
* @see org.mockito.junit.MockitoJUnitRunner
@@ -67,9 +55,6 @@ public class CallableCacheLoaderAdapterTest {
@Mock
private CacheLoader mockCacheLoader;
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
@Mock
private LoaderHelper mockLoaderHelper;
@@ -79,115 +64,139 @@ public class CallableCacheLoaderAdapterTest {
@Test
public void constructCallableCacheLoaderAdapterWithArgumentKeyAndRegion() {
CallableCacheLoaderAdapter instance =
+
new CallableCacheLoaderAdapter<>(mockCacheLoader, "key", mockRegion, "test");
- assertThat(instance, is(notNullValue()));
- assertThat(instance.getCacheLoader(), is(sameInstance(mockCacheLoader)));
- assertThat(instance.getKey(), is(equalTo("key")));
- assertThat(instance.getRegion(), is(sameInstance(mockRegion)));
- assertThat(String.valueOf(instance.getArgument()), is(equalTo("test")));
+ assertThat(instance).isNotNull();
+ assertThat(instance.getCacheLoader()).isSameAs(mockCacheLoader);
+ assertThat(instance.getKey()).isEqualTo("key");
+ assertThat(instance.getRegion()).isSameAs(mockRegion);
+ assertThat(String.valueOf(instance.getArgument())).isEqualTo("test");
}
@Test
public void constructCallableCacheLoaderAdapterWithKeyRegionAndNoArgument() {
+
CallableCacheLoaderAdapter instance =
new CallableCacheLoaderAdapter<>(mockCacheLoader, "key", mockRegion);
- assertThat(instance, is(notNullValue()));
- assertThat(instance.getCacheLoader(), is(sameInstance(mockCacheLoader)));
- assertThat(instance.getKey(), is(equalTo("key")));
- assertThat(instance.getRegion(), is(sameInstance(mockRegion)));
- assertThat(instance.getArgument(), is(nullValue()));
+ assertThat(instance).isNotNull();
+ assertThat(instance.getCacheLoader()).isSameAs(mockCacheLoader);
+ assertThat(instance.getKey()).isEqualTo("key");
+ assertThat(instance.getRegion()).isSameAs(mockRegion);
+ assertThat(instance.getArgument()).isNull();
}
@Test
public void constructCallableCacheLoaderAdapterWithNoArgumentKeyOrRegion() {
+
CallableCacheLoaderAdapter instance =
new CallableCacheLoaderAdapter<>(mockCacheLoader);
- assertThat(instance, is(notNullValue()));
- assertThat(instance.getCacheLoader(), is(sameInstance(mockCacheLoader)));
- assertThat(instance.getKey(), is(nullValue()));
- assertThat(instance.getRegion(), is(nullValue()));
- assertThat(instance.getArgument(), is(nullValue()));
+ assertThat(instance).isNotNull();
+ assertThat(instance.getCacheLoader()).isSameAs(mockCacheLoader);
+ assertThat(instance.getKey()).isNull();
+ assertThat(instance.getRegion()).isNull();
+ assertThat(instance.getArgument()).isNull();
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void constructCallableCacheLoaderAdapterWithNullCacheLoader() {
- exception.expect(IllegalArgumentException.class);
- exception.expectCause(is(nullValue(Throwable.class)));
- exception.expectMessage("CacheLoader must not be null");
- new CallableCacheLoaderAdapter<>(null);
+ try {
+ new CallableCacheLoaderAdapter<>(null);
+ }
+ catch (IllegalArgumentException expected) {
+
+ assertThat(expected).hasMessage("CacheLoader must not be null");
+ assertThat(expected).hasNoCause();
+
+ throw expected;
+ }
}
@Test
@SuppressWarnings("unchecked")
public void callDelegatesToLoad() throws Exception {
+
CallableCacheLoaderAdapter instance =
new CallableCacheLoaderAdapter<>(mockCacheLoader, "key", mockRegion, "test");
- when(mockCacheLoader.load(any(LoaderHelper.class))).thenAnswer(new Answer() {
- public String answer(final InvocationOnMock invocation) throws Throwable {
- LoaderHelper loaderHelper = invocation.getArgument(0);
+ when(mockCacheLoader.load(any(LoaderHelper.class))).thenAnswer((Answer) invocation -> {
- assertThat(loaderHelper, is(notNullValue()));
- assertThat(loaderHelper.getArgument(), is(equalTo("test")));
- assertThat(loaderHelper.getKey(), is(equalTo("key")));
- assertThat(loaderHelper.getRegion(), is(sameInstance(mockRegion)));
+ LoaderHelper loaderHelper = invocation.getArgument(0);
- return "mockValue";
- }
+ assertThat(loaderHelper).isNotNull();
+ assertThat(loaderHelper.getArgument()).isEqualTo("test");
+ assertThat(loaderHelper.getKey()).isEqualTo("key");
+ assertThat(loaderHelper.getRegion()).isSameAs(mockRegion);
+
+ return "mockValue";
});
- assertThat(instance.call(), is(equalTo("mockValue")));
+ assertThat(instance.call()).isEqualTo("mockValue");
verify(mockCacheLoader, times(1)).load(isA(LoaderHelper.class));
}
- @Test
+ @Test(expected = IllegalStateException.class)
public void callThrowsIllegalStateExceptionForNullKey() throws Exception {
+
CallableCacheLoaderAdapter instance =
new CallableCacheLoaderAdapter<>(mockCacheLoader, null, mockRegion);
- assertThat(instance.getKey(), is(nullValue()));
- assertThat(instance.getRegion(), is(sameInstance(mockRegion)));
+ assertThat(instance.getKey()).isNull();
+ assertThat(instance.getRegion()).isSameAs(mockRegion);
- exception.expect(IllegalStateException.class);
- exception.expectCause(is(nullValue(Throwable.class)));
- exception.expectMessage("The key for which the value is loaded for cannot be null");
+ try {
+ instance.call();
+ }
+ catch (IllegalStateException expected) {
- instance.call();
+ assertThat(expected).hasMessage("The key for which the value is loaded for cannot be null");
+ assertThat(expected).hasNoCause();
+
+ throw expected;
+ }
}
@Test
public void callThrowsIllegalStateExceptionForNullRegion() throws Exception {
+
CallableCacheLoaderAdapter instance =
new CallableCacheLoaderAdapter<>(mockCacheLoader, "key", null);
- assertThat(instance.getKey(), is(equalTo("key")));
- assertThat(instance.getRegion(), is(nullValue()));
+ assertThat(instance.getKey()).isEqualTo("key");
+ assertThat(instance.getRegion()).isNull();
- exception.expect(IllegalStateException.class);
- exception.expectCause(is(nullValue(Throwable.class)));
- exception.expectMessage("The Region to load cannot be null");
+ try {
+ instance.call();
+ }
+ catch (IllegalStateException expected) {
- instance.call();
+ assertThat(expected).hasMessage("The Region to load cannot be null");
+ assertThat(expected).hasNoCause();
+
+ throw expected;
+ }
}
@Test
public void closeDelegatesToCacheLoaderClose() {
+
new CallableCacheLoaderAdapter<>(mockCacheLoader).close();
+
verify(mockCacheLoader, times(1)).close();
}
@Test
public void loadDelegatesToCacheLoaderLoad() {
+
CallableCacheLoaderAdapter instance = new CallableCacheLoaderAdapter<>(mockCacheLoader);
when(mockCacheLoader.load(eq(mockLoaderHelper))).thenReturn("test");
- assertThat(instance.load(mockLoaderHelper), is(equalTo("test")));
+ assertThat(instance.load(mockLoaderHelper)).isEqualTo("test");
verify(mockCacheLoader, times(1)).load(eq(mockLoaderHelper));
}
diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/GemfireCacheManagerUnitTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/GemfireCacheManagerUnitTests.java
index fd7798ad..f2fca456 100644
--- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/GemfireCacheManagerUnitTests.java
+++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/cache/GemfireCacheManagerUnitTests.java
@@ -14,13 +14,9 @@
* limitations under the License.
*
*/
-
package org.springframework.data.gemfire.cache;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@@ -35,9 +31,7 @@ import java.util.HashSet;
import java.util.Set;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
@@ -59,36 +53,40 @@ import org.springframework.cache.Cache;
@RunWith(MockitoJUnitRunner.class)
public class GemfireCacheManagerUnitTests {
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
@Mock
private GemFireCache mockGemFireCache;
private GemfireCacheManager cacheManager;
@Mock
- private Region mockRegion;
+ private Region