DATAGEODE-188 - Refactor and simplify codebase.

This commit is contained in:
John Blum
2019-05-12 23:25:07 -07:00
parent ad0ad251a1
commit ef4e32e43d
7 changed files with 47 additions and 64 deletions

View File

@@ -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 { }
}

View File

@@ -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));

View File

@@ -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));
}
}