Mock the Map/Region.putAll(:Map<K, V>) operation.
This commit is contained in:
@@ -2751,6 +2751,18 @@ public abstract class GemFireMockObjectsSupport extends MockObjectsSupport {
|
||||
|
||||
}).when(mockRegion).put(any(), any());
|
||||
|
||||
// Map.putAll(:Map<K, V>) / Region.putAll(:Map<K, V>)
|
||||
doAnswer(invocation -> {
|
||||
|
||||
Map<K, V> map = invocation.getArgument(0);
|
||||
|
||||
CollectionUtils.nullSafeMap(map).entrySet()
|
||||
.forEach(entry -> mockRegion.put(entry.getKey(), entry.getValue()));
|
||||
|
||||
return null;
|
||||
|
||||
}).when(mockRegion).putAll(any(Map.class));
|
||||
|
||||
// Region.remove(key)
|
||||
when(mockRegion.remove(any())).thenAnswer(invocation -> {
|
||||
|
||||
|
||||
@@ -707,4 +707,23 @@ public class MockRegionDataAccessOperationsAndEventsUnitTests {
|
||||
|
||||
verify(this.mockRegion, times(1)).invalidate(eq(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapRegionPutAllIsCorrect() {
|
||||
|
||||
Map<Object, Object> map = MapBuilder.newMapBuilder()
|
||||
.put(1, "TEST")
|
||||
.put(2, "MOCK")
|
||||
.build();
|
||||
|
||||
assertThat(this.mockRegion).isEmpty();
|
||||
|
||||
this.mockRegion.putAll(map);
|
||||
|
||||
assertThat(this.mockRegion).hasSize(map.size());
|
||||
assertThat(this.mockRegion.getAll(map.keySet())).isEqualTo(map);
|
||||
|
||||
verify(this.mockRegion, times(1)).put(eq(1), eq("TEST"));
|
||||
verify(this.mockRegion, times(1)).put(eq(2), eq("MOCK"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user