### Question:
SpaceNameBasedAuthorizationFilter implements UriAuthorizationFilter { @Override public final boolean ensureUserIsAuthorized(HttpServletRequest request, HttpServletResponse response) throws IOException { CloudTarget target = extractAndLogTarget(request); try { authorizationChecker.ensureUserIsAuthorized(request, SecurityContextUtil.getUserInfo(), target, null); return true; } catch (ResponseStatusException e) { logUnauthorizedRequest(request, e); response.sendError(HttpStatus.UNAUTHORIZED.value(), MessageFormat.format(Messages.NOT_AUTHORIZED_TO_OPERATE_IN_ORGANIZATION_0_AND_SPACE_1, target.getOrganizationName(), target.getSpaceName())); return false; } } SpaceNameBasedAuthorizationFilter(AuthorizationChecker authorizationChecker); @Override final boolean ensureUserIsAuthorized(HttpServletRequest request, HttpServletResponse response);  }### Answer:
@Test void testWithSuccessfulAuthorization() throws IOException { dummyUriAuthorizationFilter.ensureUserIsAuthorized(request, response); Mockito.verify(authorizationChecker) .ensureUserIsAuthorized(Mockito.eq(request), Mockito.any(), Mockito.eq(new CloudTarget(ORGANIZATION_NAME, SPACE_NAME)), Mockito.any()); }
@Test void testWithException() throws IOException { Mockito.doThrow(new ResponseStatusException(HttpStatus.FORBIDDEN)) .when(authorizationChecker) .ensureUserIsAuthorized(Mockito.eq(request), Mockito.any(), Mockito.eq(new CloudTarget(ORGANIZATION_NAME, SPACE_NAME)), Mockito.any()); dummyUriAuthorizationFilter.ensureUserIsAuthorized(request, response); Mockito.verify(response) .sendError(Mockito.eq(HttpStatus.UNAUTHORIZED.value()), Mockito.any()); }