diff --git a/src/main/java/org/springframework/data/gemfire/CacheFactoryBean.java b/src/main/java/org/springframework/data/gemfire/CacheFactoryBean.java index cbd9ee4c..30fced78 100644 --- a/src/main/java/org/springframework/data/gemfire/CacheFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/CacheFactoryBean.java @@ -1350,6 +1350,7 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport * @see org.apache.geode.cache.CacheFactory * @see org.apache.geode.cache.client.ClientCacheFactory */ + @FunctionalInterface public interface CacheFactoryInitializer { /** diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/ClientCacheApplication.java b/src/main/java/org/springframework/data/gemfire/config/annotation/ClientCacheApplication.java index 6cefb0d9..754eae5a 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/ClientCacheApplication.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/ClientCacheApplication.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.config.annotation; import java.lang.annotation.Documented; diff --git a/src/main/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBean.java b/src/main/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBean.java index e0a94c2a..8a267089 100644 --- a/src/main/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBean.java @@ -19,6 +19,7 @@ package org.springframework.data.gemfire.snapshot; import static java.util.Arrays.stream; import static org.apache.geode.cache.snapshot.SnapshotOptions.SnapshotFormat; import static org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean.SnapshotServiceAdapter; +import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException; import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException; @@ -88,11 +89,6 @@ public class SnapshotServiceFactoryBean extends AbstractFactoryBeanSupport private SnapshotServiceAdapter snapshotServiceAdapter; - @SuppressWarnings("unchecked") - static SnapshotMetadata[] nullSafeArray(SnapshotMetadata[] configurations) { - return configurations != null ? configurations : EMPTY_ARRAY; - } - static boolean nullSafeIsDirectory(File file) { return file != null && file.isDirectory(); } @@ -210,8 +206,9 @@ public class SnapshotServiceFactoryBean extends AbstractFactoryBeanSupport * @return an array of snapshot meta-data used for each export. * @see SnapshotServiceFactoryBean.SnapshotMetadata */ + @SuppressWarnings("unchecked") protected SnapshotMetadata[] getExports() { - return nullSafeArray(exports); + return nullSafeArray(exports, SnapshotMetadata.class); } /** @@ -232,8 +229,9 @@ public class SnapshotServiceFactoryBean extends AbstractFactoryBeanSupport * @return an array of snapshot meta-data used for each import. * @see SnapshotServiceFactoryBean.SnapshotMetadata */ + @SuppressWarnings("unchecked") protected SnapshotMetadata[] getImports() { - return nullSafeArray(imports); + return nullSafeArray(imports, SnapshotMetadata.class); } /** @@ -455,7 +453,7 @@ public class SnapshotServiceFactoryBean extends AbstractFactoryBeanSupport @SuppressWarnings("unchecked") public void doExport(SnapshotMetadata... configurations) { - stream(nullSafeArray(configurations)).forEach(configuration -> + stream(nullSafeArray(configurations, SnapshotMetadata.class)).forEach(configuration -> save(configuration.getLocation(), configuration.getFormat(), createOptions(configuration))); } @@ -463,7 +461,7 @@ public class SnapshotServiceFactoryBean extends AbstractFactoryBeanSupport @SuppressWarnings("unchecked") public void doImport(SnapshotMetadata... configurations) { - stream(nullSafeArray(configurations)).forEach(configuration -> + stream(nullSafeArray(configurations, SnapshotMetadata.class)).forEach(configuration -> load(configuration.getFormat(), createOptions(configuration), handleLocation(configuration))); } diff --git a/src/main/java/org/springframework/data/gemfire/snapshot/filter/ComposableSnapshotFilter.java b/src/main/java/org/springframework/data/gemfire/snapshot/filter/ComposableSnapshotFilter.java index 8e3c5220..be7c0bdc 100644 --- a/src/main/java/org/springframework/data/gemfire/snapshot/filter/ComposableSnapshotFilter.java +++ b/src/main/java/org/springframework/data/gemfire/snapshot/filter/ComposableSnapshotFilter.java @@ -16,6 +16,8 @@ package org.springframework.data.gemfire.snapshot.filter; +import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray; + import java.util.Map; import org.apache.geode.cache.snapshot.SnapshotFilter; @@ -69,17 +71,12 @@ public class ComposableSnapshotFilter implements SnapshotFilter { * @see org.apache.geode.cache.snapshot.SnapshotFilter */ private ComposableSnapshotFilter(SnapshotFilter leftOperand, Operator operator, SnapshotFilter rightOperand) { + this.leftOperand = leftOperand; this.operator = operator; this.rightOperand = rightOperand; } - /* (non-Javadoc) */ - @SuppressWarnings("unchecked") - static SnapshotFilter[] nullSafeArray(SnapshotFilter... array) { - return (array != null ? array : new SnapshotFilter[0]); - } - /** * Composes the array of SnapshotFilters into a logical boolean expression using the specified Operator. * @@ -92,10 +89,12 @@ public class ComposableSnapshotFilter implements SnapshotFilter { * @see ComposableSnapshotFilter.Operator * @see org.apache.geode.cache.snapshot.SnapshotFilter */ + @SuppressWarnings("unchecked") protected static SnapshotFilter compose(Operator operator, SnapshotFilter... snapshotFilters) { + SnapshotFilter composedSnapshotFilter = null; - for (SnapshotFilter snapshotFilter : nullSafeArray(snapshotFilters)) { + for (SnapshotFilter snapshotFilter : nullSafeArray(snapshotFilters, SnapshotFilter.class)) { composedSnapshotFilter = (composedSnapshotFilter == null ? snapshotFilter : new ComposableSnapshotFilter(snapshotFilter, operator, composedSnapshotFilter)); } @@ -144,7 +143,7 @@ public class ComposableSnapshotFilter implements SnapshotFilter { */ @Override public boolean accept(final Map.Entry entry) { - return operator.operate(leftOperand.accept(entry), rightOperand.accept(entry)); + return this.operator.operate(this.leftOperand.accept(entry), this.rightOperand.accept(entry)); } } diff --git a/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java index d6e8f5a1..0143d801 100644 --- a/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.config.annotation; import static org.assertj.core.api.Assertions.assertThat; @@ -40,21 +39,30 @@ import org.springframework.mock.env.MockPropertySource; * Integration tests for {@link PeerCacheApplication}. * * @author John Blum + * @see java.util.Properties * @see org.junit.Test + * @see org.springframework.context.ConfigurableApplicationContext + * @see org.springframework.context.annotation.AnnotationConfigApplicationContext + * @see org.springframework.core.env.PropertySource * @see org.springframework.data.gemfire.config.annotation.PeerCacheApplication + * @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.mock.env.MockPropertySource * @since 2.0.0 */ +@SuppressWarnings("unused") public class PeerCachePropertiesIntegrationTests { private ConfigurableApplicationContext applicationContext; @After public void tearDown() { - Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close); + + Optional.ofNullable(this.applicationContext) + .ifPresent(ConfigurableApplicationContext::close); } private ConfigurableApplicationContext newApplicationContext(PropertySource testPropertySource, - Class... annotatedClasses) { + Class... annotatedClasses) { AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); @@ -62,8 +70,8 @@ public class PeerCachePropertiesIntegrationTests { propertySources.addFirst(testPropertySource); - applicationContext.registerShutdownHook(); applicationContext.register(annotatedClasses); + applicationContext.registerShutdownHook(); applicationContext.refresh(); return applicationContext; @@ -171,7 +179,6 @@ public class PeerCachePropertiesIntegrationTests { @EnablePdx(ignoreUnreadFields = true, readSerialized = true, serializerBeanName = "mockPdxSerializer") @PeerCacheApplication(name = "TestPeerCache", criticalHeapPercentage = 90.0f, evictionHeapPercentage = 75.0f, lockLease = 300, lockTimeout = 120) - @SuppressWarnings("unused") static class TestPeerCacheConfiguration { @Bean @@ -187,7 +194,6 @@ public class PeerCachePropertiesIntegrationTests { @EnableGemFireMockObjects @PeerCacheApplication(name = "TestPeerCache") - @SuppressWarnings("unused") - static class TestDynamicPeerCacheConfiguration { - } + static class TestDynamicPeerCacheConfiguration { } + } diff --git a/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java b/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java index f992c0a9..809e0946 100644 --- a/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java +++ b/src/test/java/org/springframework/data/gemfire/snapshot/SnapshotServiceFactoryBeanTest.java @@ -161,20 +161,6 @@ public class SnapshotServiceFactoryBeanTest { factoryBean.setRegion(null); } - @Test - public void nullSafeArrayWithNonNullArray() { - - SnapshotMetadata[] expectedConfigurations = new SnapshotMetadata[0]; - - assertThat(SnapshotServiceFactoryBean.nullSafeArray(expectedConfigurations), - is(sameInstance(expectedConfigurations))); - } - - @Test - public void nullSafeArrayWithNullArray() { - assertThat(SnapshotServiceFactoryBean.nullSafeArray(null), is(equalTo(SnapshotServiceFactoryBean.EMPTY_ARRAY))); - } - @Test public void nullSafeIsDirectoryWithDirectory() { assertThat(SnapshotServiceFactoryBean.nullSafeIsDirectory(new File(System.getProperty("user.dir"))), is(true)); diff --git a/src/test/java/org/springframework/data/gemfire/snapshot/filter/ComposableSnapshotFilterTest.java b/src/test/java/org/springframework/data/gemfire/snapshot/filter/ComposableSnapshotFilterTest.java index 9899cae8..f0bc8ace 100644 --- a/src/test/java/org/springframework/data/gemfire/snapshot/filter/ComposableSnapshotFilterTest.java +++ b/src/test/java/org/springframework/data/gemfire/snapshot/filter/ComposableSnapshotFilterTest.java @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.gemfire.snapshot.filter; -import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.isA; -import static org.junit.Assert.*; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.sameInstance; +import static org.junit.Assert.assertThat; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import org.apache.geode.cache.snapshot.SnapshotFilter; @@ -48,16 +50,18 @@ public class ComposableSnapshotFilterTest { @SuppressWarnings("unchecked") protected SnapshotFilter mockSnapshotFilter(boolean accept) { - SnapshotFilter mockSnapshotFilter = mock(SnapshotFilter.class, String.format( - "MockSnapshotFilter-%1$d", ID_SEQUENCE.incrementAndGet())); - when(mockSnapshotFilter.accept((Map.Entry) any())).thenReturn(accept); + SnapshotFilter mockSnapshotFilter = mock(SnapshotFilter.class, + String.format("MockSnapshotFilter-%1$d", ID_SEQUENCE.incrementAndGet())); + + when(mockSnapshotFilter.accept(any())).thenReturn(accept); return mockSnapshotFilter; } @Test public void operatorIdentityIsSuccessful() { + assertThat(Operator.AND.isAnd(), is(true)); assertThat(Operator.AND.isOr(), is(false)); assertThat(Operator.OR.isAnd(), is(false)); @@ -66,6 +70,7 @@ public class ComposableSnapshotFilterTest { @Test public void andOperatorOperationIsValid() { + assertThat(Operator.AND.operate(true, true), is(true)); assertThat(Operator.AND.operate(true, false), is(false)); assertThat(Operator.AND.operate(false, true), is(false)); @@ -74,29 +79,16 @@ public class ComposableSnapshotFilterTest { @Test public void orOperatorOperationIsValid() { + assertThat(Operator.OR.operate(true, true), is(true)); assertThat(Operator.OR.operate(true, false), is(true)); assertThat(Operator.OR.operate(false, true), is(true)); assertThat(Operator.OR.operate(false, false), is(false)); } - @Test - public void nullSafeArrayWithNonNullArray() { - SnapshotFilter[] expectedArray = {}; - - assertThat(ComposableSnapshotFilter.nullSafeArray(expectedArray), is(sameInstance(expectedArray))); - } - - @Test - public void nullSafeArrayWithNullArray() { - SnapshotFilter[] actualArray = ComposableSnapshotFilter.nullSafeArray((SnapshotFilter[]) null); - - assertThat(actualArray, is(notNullValue())); - assertThat(actualArray.length, is(equalTo(0))); - } - @Test public void composeSingle() { + SnapshotFilter mockSnapshotFilter = mockSnapshotFilter(false); SnapshotFilter composedFilter = ComposableSnapshotFilter.compose(Operator.AND, mockSnapshotFilter); @@ -105,6 +97,7 @@ public class ComposableSnapshotFilterTest { @Test public void composeMultiple() throws Exception { + SnapshotFilter mockSnapshotFilterOne = mockSnapshotFilter(false); SnapshotFilter mockSnapshotFilterTwo = mockSnapshotFilter(true); @@ -124,6 +117,7 @@ public class ComposableSnapshotFilterTest { @Test @SuppressWarnings("unchecked") public void composeAndThenAccept() { + SnapshotFilter falseFilter = mockSnapshotFilter(false); SnapshotFilter trueFilter = mockSnapshotFilter(true); @@ -146,6 +140,7 @@ public class ComposableSnapshotFilterTest { @Test @SuppressWarnings("unchecked") public void composeOrThenAccept() { + SnapshotFilter falseFilter = mockSnapshotFilter(false); SnapshotFilter trueFilter = mockSnapshotFilter(true); @@ -164,5 +159,4 @@ public class ComposableSnapshotFilterTest { assertThat((ComposableSnapshotFilter) composedFilter, isA(ComposableSnapshotFilter.class)); assertThat(composedFilter.accept(null), is(false)); } - }