Add MockSettings to all mock objects.

Set mock objects to lenient and not strict stubbing.
This commit is contained in:
John Blum
2018-09-19 11:19:52 -07:00
parent 9e51e631c7
commit 4ea6c3921d
7 changed files with 32 additions and 20 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.data.gemfire.tests.mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
import org.apache.geode.cache.wan.GatewaySender;
@@ -41,7 +42,7 @@ public abstract class AsyncEventQueueMockObjects {
boolean forwardExpirationDestroy, int maximumQueueMemory, GatewaySender.OrderPolicy orderPolicy,
boolean parallel, boolean persistent, boolean primary, int size) {
AsyncEventQueue mockAsyncEventQueue = mock(AsyncEventQueue.class, id);
AsyncEventQueue mockAsyncEventQueue = mock(AsyncEventQueue.class, withSettings().name(id).lenient());
when(mockAsyncEventQueue.getId()).thenReturn(id);
when(mockAsyncEventQueue.isBatchConflationEnabled()).thenReturn(batchConflationEnabled);

View File

@@ -19,6 +19,7 @@ package org.springframework.data.gemfire.tests.mock;
import static org.apache.geode.internal.util.CollectionUtils.asSet;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
import java.util.Arrays;
import java.util.Optional;
@@ -54,12 +55,14 @@ import org.springframework.data.gemfire.util.RegionUtils;
public abstract class CacheMockObjects {
@SuppressWarnings("unchecked")
public static <T extends GemFireCache> T mockGemFireCache(T mockGemFireCache,
public static <T extends GemFireCache> T mockGemFireCache(T mockGemFireCache, String name,
DistributedSystem distributedSystem, ResourceManager resourceManager, Region<?, ?>... regions) {
T theMockGemFireCache = mockGemFireCache != null ? mockGemFireCache : (T) mock(GemFireCache.class);
T theMockGemFireCache = mockGemFireCache != null ? mockGemFireCache
: (T) mock(GemFireCache.class, withSettings().name(name).lenient());
when(theMockGemFireCache.getDistributedSystem()).thenReturn(distributedSystem);
when(theMockGemFireCache.getName()).thenReturn(name);
when(theMockGemFireCache.getResourceManager()).thenReturn(resourceManager);
Optional.ofNullable(regions)
@@ -69,21 +72,23 @@ public abstract class CacheMockObjects {
return theMockGemFireCache;
}
public static ClientCache mockClientCache(DistributedSystem distributedSystem, ResourceManager resourceManager,
public static ClientCache mockClientCache(String name, DistributedSystem distributedSystem, ResourceManager resourceManager,
Region<?, ?>... regions) {
return mockGemFireCache(mock(ClientCache.class), distributedSystem, resourceManager, regions);
return mockGemFireCache(mock(ClientCache.class, withSettings().name(name).lenient()),
name, distributedSystem, resourceManager, regions);
}
public static Cache mockPeerCache(DistributedSystem distributedSystem, ResourceManager resourceManager,
public static Cache mockPeerCache(String name, DistributedSystem distributedSystem, ResourceManager resourceManager,
Region<?, ?>... regions) {
return mockGemFireCache(mock(Cache.class), distributedSystem, resourceManager, regions);
return mockGemFireCache(mock(Cache.class, withSettings().name(name).lenient()),
name, distributedSystem, resourceManager, regions);
}
public static DistributedSystem mockDistributedSystem(DistributedMember distributedMember) {
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class, withSettings().lenient());
when(mockDistributedSystem.getDistributedMember()).thenReturn(distributedMember);
@@ -92,7 +97,7 @@ public abstract class CacheMockObjects {
public static DistributedMember mockDistributedMember(String name, String... groups) {
DistributedMember mockDistributeMember = mock(DistributedMember.class, name);
DistributedMember mockDistributeMember = mock(DistributedMember.class, withSettings().name(name).lenient());
when(mockDistributeMember.getName()).thenReturn(name);
when(mockDistributeMember.getGroups()).thenReturn(Arrays.asList(groups));
@@ -105,7 +110,7 @@ public abstract class CacheMockObjects {
public static ResourceManager mockResourceManager(float criticalHeapPercentage, float criticalOffHeapPercentage,
float evictionHeapPercentage, float evictionOffHeapPercentage) {
ResourceManager mockResourceManager = mock(ResourceManager.class);
ResourceManager mockResourceManager = mock(ResourceManager.class, withSettings().lenient());
when(mockResourceManager.getCriticalHeapPercentage()).thenReturn(criticalHeapPercentage);
when(mockResourceManager.getCriticalOffHeapPercentage()).thenReturn(criticalOffHeapPercentage);
@@ -118,7 +123,7 @@ public abstract class CacheMockObjects {
@SuppressWarnings("unchecked")
public static <K, V> Region<K, V> mockRegion(String name, DataPolicy dataPolicy) {
Region<K, V> mockRegion = mock(Region.class, name);
Region<K, V> mockRegion = mock(Region.class, withSettings().name(name).lenient());
when(mockRegion.getName()).thenReturn(RegionUtils.toRegionName(name));
when(mockRegion.getFullPath()).thenReturn(RegionUtils.toRegionPath(name));

View File

@@ -19,6 +19,7 @@ package org.springframework.data.gemfire.tests.mock;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -55,7 +56,7 @@ public abstract class CacheServerMockObjects extends MockObjectsSupport {
AtomicBoolean runningState = new AtomicBoolean(running);
CacheServer mockCacheServer = mock(CacheServer.class);
CacheServer mockCacheServer = mock(CacheServer.class, withSettings().lenient());
when(mockCacheServer.getBindAddress()).thenReturn(bindAddress);
when(mockCacheServer.getHostnameForClients()).thenReturn(hostnameForClients);
@@ -94,7 +95,8 @@ public abstract class CacheServerMockObjects extends MockObjectsSupport {
public static ClientSubscriptionConfig mockClientSubscriptionConfig(int capacity, String diskStoreName,
String evictionPolicy) {
ClientSubscriptionConfig mockClientSubscriptionConfig = mock(ClientSubscriptionConfig.class);
ClientSubscriptionConfig mockClientSubscriptionConfig =
mock(ClientSubscriptionConfig.class, withSettings().lenient());
when(mockClientSubscriptionConfig.getCapacity()).thenReturn(capacity);
when(mockClientSubscriptionConfig.getDiskStoreName()).thenReturn(diskStoreName);
@@ -118,7 +120,7 @@ public abstract class CacheServerMockObjects extends MockObjectsSupport {
public static ServerMetrics mockServerMetrics(int clientCount, int connectionCount, int maxConnections,
int subscriptionConnectionCount) {
ServerMetrics mockServerMetrics = mock(ServerMetrics.class);
ServerMetrics mockServerMetrics = mock(ServerMetrics.class, withSettings().lenient());
when(mockServerMetrics.getClientCount()).thenReturn(clientCount);
when(mockServerMetrics.getConnectionCount()).thenReturn(connectionCount);

View File

@@ -18,6 +18,7 @@ package org.springframework.data.gemfire.tests.mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
import java.io.File;
import java.util.UUID;
@@ -41,7 +42,7 @@ public abstract class DiskStoreMockObjects extends MockObjectsSupport {
int compactionThreshold, File[] diskDirectories, int[] diskDirectorySizes, float diskUsageCriticalPercentage,
float diskUsageWarningPercentage, long maxOplogSize, int queueSize, long timeInterval, int writeBufferSize) {
DiskStore mockDiskStore = mock(DiskStore.class, name);
DiskStore mockDiskStore = mock(DiskStore.class, withSettings().name(name).lenient());
when(mockDiskStore.getAllowForceCompaction()).thenReturn(allowForceCompaction);
when(mockDiskStore.getAutoCompact()).thenReturn(autoCompact);

View File

@@ -19,6 +19,7 @@ package org.springframework.data.gemfire.tests.mock;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -48,7 +49,7 @@ public abstract class GatewayMockObjects extends MockObjectsSupport {
AtomicBoolean running = new AtomicBoolean(initialRunningState);
GatewayReceiver mockGatewayReceiver = mock(GatewayReceiver.class);
GatewayReceiver mockGatewayReceiver = mock(GatewayReceiver.class, withSettings().lenient());
when(mockGatewayReceiver.getBindAddress()).thenReturn(bindAddress);
when(mockGatewayReceiver.getEndPort()).thenReturn(endPort);
@@ -78,7 +79,7 @@ public abstract class GatewayMockObjects extends MockObjectsSupport {
AtomicBoolean running = new AtomicBoolean(initialRunningState);
AtomicBoolean runningState = new AtomicBoolean(running.get());
GatewaySender mockGatewaySender = mock(GatewaySender.class, id);
GatewaySender mockGatewaySender = mock(GatewaySender.class, withSettings().name(id).lenient());
when(mockGatewaySender.getAlertThreshold()).thenReturn(alertThreshold);
when(mockGatewaySender.isBatchConflationEnabled()).thenReturn(batchConflationEnabled);

View File

@@ -18,6 +18,7 @@ package org.springframework.data.gemfire.tests.mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.query.Index;
@@ -42,7 +43,7 @@ public abstract class IndexMockObjects extends MockObjectsSupport {
public static Index mockIndex(String name, String fromClause, String indexedExpression, String projectionAttributes,
Region region, IndexStatistics statistics, IndexType type) {
Index mockIndex = mock(Index.class, name);
Index mockIndex = mock(Index.class, withSettings().name(name).lenient());
when(mockIndex.getName()).thenReturn(name);
when(mockIndex.getCanonicalizedFromClause()).thenReturn(fromClause);
@@ -62,7 +63,7 @@ public abstract class IndexMockObjects extends MockObjectsSupport {
long numberOfMapIndexKeys, long numberOfValues, long numberOfUpdates, int readLockCount,
long totalUpdateTime, long totalUses) {
IndexStatistics mockIndexStatistics = mock(IndexStatistics.class);
IndexStatistics mockIndexStatistics = mock(IndexStatistics.class, withSettings().lenient());
when(mockIndexStatistics.getNumberOfBucketIndexes()).thenReturn(numberOfBucketIndexes);
when(mockIndexStatistics.getNumberOfKeys()).thenReturn(numberOfKeys);

View File

@@ -20,6 +20,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
import java.net.InetSocketAddress;
import java.util.List;
@@ -53,7 +54,7 @@ public abstract class PoolMockObjects extends MockObjectsSupport {
AtomicBoolean destroyed = new AtomicBoolean(initialDestroyedState);
Pool mockPool = mock(Pool.class, name);
Pool mockPool = mock(Pool.class, withSettings().name(name).lenient());
when(mockPool.isDestroyed()).thenAnswer(newGetter(destroyed));
when(mockPool.getFreeConnectionTimeout()).thenReturn(freeConnectionTimeout);