Mock the Map/Region.clear() operation.
This commit is contained in:
@@ -2332,7 +2332,13 @@ public abstract class GemFireMockObjectsSupport extends MockObjectsSupport {
|
||||
return regions.get(subRegionFullPath);
|
||||
});
|
||||
|
||||
// Region.containsKey(key)
|
||||
// Map.clear() / Region.clear()
|
||||
doAnswer(invocation -> {
|
||||
data.clear();
|
||||
return null;
|
||||
}).when(mockRegion).clear();
|
||||
|
||||
// Map.containsKey(key) / Region.containsKey(key)
|
||||
when(mockRegion.containsKey(any())).thenAnswer(invocation ->
|
||||
data.containsKey(invocation.getArgument(0)));
|
||||
|
||||
@@ -2502,7 +2508,7 @@ public abstract class GemFireMockObjectsSupport extends MockObjectsSupport {
|
||||
});
|
||||
|
||||
// Region.size()
|
||||
when(mockRegion.size()).thenAnswer(invocation -> data.size());
|
||||
doAnswer(invocation -> data.size()).when(mockRegion).size();
|
||||
|
||||
when(mockRegion.subregions(anyBoolean())).thenAnswer(invocation -> {
|
||||
|
||||
|
||||
@@ -488,4 +488,19 @@ public class MockRegionDataAccessOperationsAndEventsUnitTests {
|
||||
assertThat(this.mockRegion).containsKey(1);
|
||||
assertThat(this.mockRegion.get(1)).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapRegionClearIsCorrect() {
|
||||
|
||||
assertThat(this.mockRegion).hasSize(0);
|
||||
|
||||
this.mockRegion.put(1, "TEST");
|
||||
this.mockRegion.put(2, "MOCK");
|
||||
|
||||
assertThat(this.mockRegion).hasSize(2);
|
||||
|
||||
this.mockRegion.clear();
|
||||
|
||||
assertThat(this.mockRegion).hasSize(0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user