### Question:
RestAPIAuthorizationFilter extends AbstractAuthorizationFilter { @Override protected boolean checkValidCondition(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws ServletException { try { if (httpRequest.getRequestURI().matches(PLATFORM_API_URI_REGEXP)) { return platformAPIsCheck(httpRequest, httpResponse); } else { return tenantAPIsCheck(httpRequest, httpResponse); } } catch (final Exception e) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } throw new ServletException(e); } } RestAPIAuthorizationFilter(final boolean reload);  RestAPIAuthorizationFilter();  static final String SCRIPT_TYPE_AUTHORIZATION_PREFIX; }### Answer:
@Test public void should_checkValidCondition_check_session_is_platform() throws ServletException { doReturn("API/platform/plop").when(request).getRequestURI(); doReturn(mock(PlatformSession.class)).when(httpSession).getAttribute(RestAPIAuthorizationFilter.PLATFORM_SESSION_PARAM_KEY); final boolean isValid = restAPIAuthorizationFilter.checkValidCondition(request, response); assertThat(isValid).isTrue(); }
@Test public void should_checkValidCondition_check_session_is_platform_with_API_toolkit() throws ServletException { doReturn("APIToolkit/platform/plop").when(request).getRequestURI(); doReturn(mock(PlatformSession.class)).when(httpSession).getAttribute(RestAPIAuthorizationFilter.PLATFORM_SESSION_PARAM_KEY); final boolean isValid = restAPIAuthorizationFilter.checkValidCondition(request, response); assertThat(isValid).isTrue(); }
@Test public void should_checkValidCondition_check_unauthorized_if_no_platform_session() throws ServletException { doReturn("API/platform/plop").when(request).getRequestURI(); doReturn(null).when(httpSession).getAttribute(RestAPIAuthorizationFilter.PLATFORM_SESSION_PARAM_KEY); final boolean isValid = restAPIAuthorizationFilter.checkValidCondition(request, response); assertThat(isValid).isFalse(); verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED); }
@Test public void should_checkValidCondition_check_unauthorized_if_no_tenant_session() throws ServletException { doReturn(null).when(httpSession).getAttribute(SessionUtil.API_SESSION_PARAM_KEY); doReturn("API/bpm/case/15").when(request).getRequestURI(); final boolean isValid = restAPIAuthorizationFilter.checkValidCondition(request, response); assertThat(isValid).isFalse(); verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED); }
@Test(expected = ServletException.class) public void should_checkValidCondition_catch_runtime() throws ServletException { doThrow(new RuntimeException()).when(request).getRequestURI(); restAPIAuthorizationFilter.checkValidCondition(request, response); }