@Test
 public void incorrectClientIdAndSecrect() throws Exception {
   when(request.getParameter("client_id")).thenReturn(Common.CLIENT_ID);
   when(request.getParameter("client_secret")).thenReturn(Common.CLIENT_SECRET);
   when(request.getParameter("grant_type")).thenReturn(GrantType.CLIENT_CREDENTIALS.toString());
   when(request.getMethod()).thenReturn("POST");
   when(request.getContentType()).thenReturn("application/x-www-form-urlencoded");
   when(verifier.checkClient(anyString(), anyString())).thenReturn(false);
   Optional<String> token = processor.process(request);
   assertThat(token).isEmpty();
 }
  @Test
  public void saveTokenData() throws Exception {
    when(request.getParameter("client_id")).thenReturn(Common.CLIENT_ID);
    when(request.getParameter("client_secret")).thenReturn(Common.CLIENT_SECRET);
    when(request.getParameter("grant_type")).thenReturn(GrantType.CLIENT_CREDENTIALS.toString());
    when(request.getMethod()).thenReturn("POST");
    when(request.getContentType()).thenReturn("application/x-www-form-urlencoded");
    when(verifier.checkClient(anyString(), anyString())).thenReturn(true);
    when(generator.createAccessToken()).thenReturn(TOKEN);

    processor.process(request);
    AccessTokenData accessTokenData = new AccessTokenData().withClientId(Common.CLIENT_ID);
    verify(tokenDao, times(1)).save(eq(TOKEN), eq(accessTokenData));
  }
  @Test(expected = ServerErrorException.class)
  @Ignore
  public void correctRequestWithOauthSystemException() throws Exception {
    when(request.getParameter("client_id")).thenReturn(Common.CLIENT_ID);
    when(request.getParameter("client_secret")).thenReturn(Common.CLIENT_SECRET);
    when(request.getParameter("grant_type")).thenReturn(GrantType.CLIENT_CREDENTIALS.toString());
    when(request.getMethod()).thenReturn("POST");
    when(request.getContentType()).thenReturn("application/x-www-form-urlencoded");
    when(verifier.checkClient(anyString(), anyString())).thenReturn(true);
    OAuthASResponse.OAuthTokenResponseBuilder mockBuilder =
        mock(OAuthASResponse.OAuthTokenResponseBuilder.class);
    when(mockBuilder.setExpiresIn(anyString())).thenReturn(mockBuilder);
    when(mockBuilder.setAccessToken(anyString())).thenReturn(mockBuilder);
    when(mockBuilder.buildJSONMessage()).thenThrow(OAuthSystemException.class);
    PowerMockito.mockStatic(OAuthASResponse.class);
    when(OAuthASResponse.tokenResponse(Response.Status.OK.getStatusCode())).thenReturn(mockBuilder);

    processor.process(request);
  }