11package dev .findfirst .security .oauth2 ;
22
33import static org .junit .jupiter .api .Assertions .assertEquals ;
4- import static org .junit .jupiter .api .Assertions .assertTrue ;
4+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
55import static org .mockito .Mockito .mock ;
66import static org .mockito .Mockito .when ;
77
3939@ ExtendWith (MockitoExtension .class )
4040class Oauth2LoginSuccessHandlerTest {
4141
42- private final int ID = 1111111111 ;
42+ private final int id = 1111111111 ;
4343 private final String username = "johndoe" ;
4444
4545 @ Mock
@@ -65,21 +65,21 @@ void authenticateGithubUser() throws Exception {
6565 }
6666
6767 private void authenticateUserByProvider (String provider ) throws Exception {
68- OAuth2AuthenticationToken oAuthToken = mockAuthentication (provider .toLowerCase (), ID ).getFirst ();
68+ OAuth2AuthenticationToken oAuthToken = mockAuthentication (provider .toLowerCase ()).getFirst ();
6969
7070 MockHttpServletResponse response = new MockHttpServletResponse ();
7171 oAuthHandler .onAuthenticationSuccess (new MockHttpServletRequest (), response , oAuthToken );
7272
73- assertTrue (response .getHeader ("Set-Cookie" ) != null );
73+ assertNotNull (response .getHeader ("Set-Cookie" ));
7474 assertEquals ("localhost/account/login/oauth2" , response .getRedirectedUrl ());
7575 }
7676
77- private Entry <OAuth2AuthenticationToken , OAuth2User > mockAuthentication (String provider , int id ) {
77+ private Entry <OAuth2AuthenticationToken , OAuth2User > mockAuthentication (String provider ) {
7878 OAuth2AuthenticationToken oauthToken = mock (OAuth2AuthenticationToken .class );
7979 OAuth2User principal = mock (OAuth2User .class );
8080 Map <String , Object > attributes = new HashMap <>();
8181 attributes .put ("name" , username );
82- attributes .put ("userID" , ID );
82+ attributes .put ("userID" , id );
8383 Collection <GrantedAuthority > authorities = List .of (new SimpleGrantedAuthority ("ROLE_USER" ));
8484 OAuth2User user = new DefaultOAuth2User (authorities , attributes , "name" );
8585 when (oauthToken .getPrincipal ()).thenReturn (user );
0 commit comments