@Test public void authenticateWhenValidThenSuccess() { when(this.accessTokenResponseClient.getTokenResponse(any())).thenReturn(Mono.just(this.tokenResponse.build())); OAuth2AuthorizationCodeAuthenticationToken result = authenticate(); assertThat(result).isNotNull(); }
@Test public void authenticateWhenEmptyThenEmpty() { when(this.accessTokenResponseClient.getTokenResponse(any())).thenReturn(Mono.empty()); OAuth2AuthorizationCodeAuthenticationToken result = authenticate(); assertThat(result).isNull(); }
@Test public void authenticateWhenRedirectUriNotEqualThenOAuth2AuthorizationException() { this.authorizationRequest.redirectUri("https://example.org/notequal"); assertThatCode(() -> authenticate()) .isInstanceOf(OAuth2AuthorizationException.class); }
@Test public void authenticateWhenErrorThenOAuth2AuthorizationException() { this.authorizationResponse = TestOAuth2AuthorizationResponses.error(); assertThatCode(() -> authenticate()) .isInstanceOf(OAuth2AuthorizationException.class); }
@Test public void authenticateWhenStateNotEqualThenOAuth2AuthorizationException() { this.authorizationRequest.state("notequal"); assertThatCode(() -> authenticate()) .isInstanceOf(OAuth2AuthorizationException.class); }
@Test public void authenticateWhenOAuth2AuthorizationExceptionThenOAuth2AuthorizationException() { when(this.accessTokenResponseClient.getTokenResponse(any())).thenReturn(Mono.error(() -> new OAuth2AuthorizationException(new OAuth2Error("error")))); assertThatCode(() -> authenticate()) .isInstanceOf(OAuth2AuthorizationException.class); }