UserFunctionExecution implements InternalFunction<Object[]> { @SuppressWarnings("unchecked") Execution<Object, Object, List<Object>> buildExecution(Cache cache, String onRegion) throws RegionNotFoundException { Execution<Object, Object, List<Object>> execution; DistributedMember member = cache.getDistributedSystem().getDistributedMember(); if (onRegion != null && onRegion.length() > 0) { Region<?, ?> region = cache.getRegion(onRegion); if (region == null) { throw new RegionNotFoundException(onRegion); } execution = FunctionService.onRegion(region); } else { execution = FunctionService.onMember(member); } return execution; }  @Override boolean isHA(); @Override String getId(); @Override Collection<ResourcePermission> getRequiredPermissions(String regionName); @Override void execute(FunctionContext<Object[]> context); static final String ID; }
@Test public void buildExecutionShouldThrowExceptionWhenRegionIsRequiredButItDoesNotExist() throws Exception { when(filterCache.getRegion("region")).thenReturn(null); when(function.buildExecution(any(), any())).thenCallRealMethod(); assertThatThrownBy(() -> function.buildExecution(filterCache, "region")) .isInstanceOf(RegionNotFoundException.class); }