Use doAnswer(..) instead of thenAnser(..) Mockito mock stubbing for Map/Region.get(key).

This commit is contained in:
John Blum
2020-09-15 19:42:58 -07:00
parent ea2241847a
commit 028f9c16da

View File

@@ -2358,6 +2358,7 @@ public abstract class GemFireMockObjectsSupport extends MockObjectsSupport {
}).when(mockRegion).containsValueForKey(any());
// Map.forEach(:BiConsumer<K, V>)
doAnswer(invocation -> {
BiConsumer<K, V> consumer = invocation.getArgument(0);
@@ -2368,8 +2369,8 @@ public abstract class GemFireMockObjectsSupport extends MockObjectsSupport {
}).when(mockRegion).forEach(any(BiConsumer.class));
// Region.get(key)
when(mockRegion.get(ArgumentMatchers.<K>any())).thenAnswer(invocation -> {
// Map.get(key) / Region.get(key)
doAnswer(invocation -> {
K key = invocation.getArgument(0);
V value = invalidatedKeys.contains(key) ? null : data.get(key);
@@ -2400,7 +2401,8 @@ public abstract class GemFireMockObjectsSupport extends MockObjectsSupport {
}
return value;
});
}).when(mockRegion).get(ArgumentMatchers.<K>any());
// Region.getEntry(key)
when(mockRegion.getEntry(ArgumentMatchers.<K>any())).thenAnswer(regionGetEntryInvocation ->