/*
 * Copyright 2015, Joseph "Deven" Phillips
 * Copyright 2015, Alexandre Lewandowski
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sonar.plugins.oauth2;

import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.junit.Test;

import static org.fest.assertions.Assertions.*;
import static org.mockito.Mockito.*;

/**
 * @author <a href="https://github.com/InfoSec812">Deven Phillips</a>
 */
public class OAuth2AuthenticationFilterTest {

  public OAuth2AuthenticationFilterTest() {
  }

  /**
   * Test of init method, of class OAuth2AuthenticationFilter.
   */
  @Test
  public void testInit() throws Exception {
    FilterConfig filterConfig = mock(FilterConfig.class);
    OAuth2Client client = mock(OAuth2Client.class);
    OAuth2AuthenticationFilter instance = new OAuth2AuthenticationFilter(client);
    instance.init(filterConfig);
    assertThat(instance).isNotNull();
    assertThat(instance).isInstanceOf(OAuth2AuthenticationFilter.class);
  }

  /**
   * Test of doFilter method, of class OAuth2AuthenticationFilter.
   */
  @Test
  public void testDoFilter() throws Exception {
    HttpServletRequest request = mock(HttpServletRequest.class, RETURNS_DEEP_STUBS);
    HttpServletResponse response = mock(HttpServletResponse.class);
    FilterChain chain = mock(FilterChain.class);
    OAuth2Client client = mock(OAuth2Client.class);
    OAuth2AuthenticationFilter instance = new OAuth2AuthenticationFilter(client);
    instance.doFilter(request, response, chain);
    verify(response).sendRedirect(anyString());
  }

  /**
   * Test of destroy method, of class OAuth2AuthenticationFilter.
   */
  @Test
  public void testDestroy() {
    OAuth2Client client = mock(OAuth2Client.class);
    OAuth2AuthenticationFilter instance = new OAuth2AuthenticationFilter(client);
    instance.destroy();
  }

}

@@ -1954,16 +1954,95 @@
 STUBS);%0A
+    when(request.getSession(true).getAttribute(anyString())).thenReturn(null);%0A
     Http
@@ -2094,24 +2094,44 @@
 sponse.class
+, RETURNS_DEEP_STUBS
 );%0A    Filte
@@ -2211,34 +2211,140 @@
 uth2Client.class
-);
+, RETURNS_DEEP_STUBS);%0A    when(client.getRedirectRequest(anyString()).getLocationUri()).thenReturn(%22url%22);%0A
 %0A    OAuth2Authe
@@ -2493,27 +2493,21 @@
 edirect(
-anyString()
+%22url%22
 );%0A  %7D%0A%0A

Fix test but it seems to be a bad test we a lot of mock.