SecureCacheImpl implements SecureCache { @Override public Collection<String> getRegionNames() { security.authorize(DATA, READ, ALL, ALL); Set<String> regionNames = new HashSet<>(); cache.rootRegions().forEach(region -> { regionNames.add(region.getFullPath()); region.subregions(true).stream().map(Region::getFullPath).forEach(regionNames::add); }); return regionNames; } SecureCacheImpl(InternalCache cache, Security security); @Override void getAll(String regionName, Iterable<K> keys, BiConsumer<K, V> successConsumer,
      BiConsumer<K, Exception> failureConsumer); @Override V get(String regionName, K key); @Override void put(String regionName, K key, V value); @Override void putAll(String regionName, Map<K, V> entries,
      BiConsumer<K, Exception> failureConsumer); @Override V remove(String regionName, K key); @Override Collection<String> getRegionNames(); @Override int getSize(String regionName); @Override Set<K> keySet(String regionName); @Override SecureFunctionService getFunctionService(); @Override void clear(String regionName); @Override V putIfAbsent(String regionName, K key, V value); @Override Object query(String queryString, Object[] bindParameters);  }
@Test public void getRegionNames() { authorize(DATA, READ, ALL, ALL); Set<Region<?, ?>> regions = new HashSet<>(); regions.add(region); when(cache.rootRegions()).thenReturn(regions); Set<Region<?, ?>> subregions = new HashSet<>(); @SuppressWarnings("unchecked") Region<Object, Object> region2 = mock(Region.class); subregions.add(region2); @SuppressWarnings("unchecked") Region<Object, Object> region3 = mock(Region.class); subregions.add(region3); when(region.getFullPath()).thenReturn("region1"); when(region2.getFullPath()).thenReturn("region2"); when(region3.getFullPath()).thenReturn("region3"); when(region.subregions(true)).thenReturn(subregions); Collection<String> regionNames = authorizingCache.getRegionNames(); assertThat(regionNames).containsExactly("region1", "region2", "region3"); verify(cache).rootRegions(); }
@Test public void getRegionNamesWithoutAuthorization() { assertThatThrownBy(() -> authorizingCache.getRegionNames()) .isInstanceOf(NotAuthorizedException.class); }