@Test public void filterWhenMatchThenAuthorizedClientSaved() { Mono<Authentication> authentication = Mono .just(TestOAuth2AuthorizationCodeAuthenticationTokens.unauthenticated()); OAuth2AuthorizationCodeAuthenticationToken authenticated = TestOAuth2AuthorizationCodeAuthenticationTokens .authenticated(); ServerAuthenticationConverter converter = e -> authentication; this.filter = new OAuth2AuthorizationCodeGrantWebFilter( this.authenticationManager, converter, this.authorizedClientRepository); MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest .get("/authorize/oauth2/code/registration-id")); DefaultWebFilterChain chain = new DefaultWebFilterChain( e -> e.getResponse().setComplete()); when(this.authenticationManager.authenticate(any())).thenReturn(Mono.just( authenticated)); when(this.authorizedClientRepository.saveAuthorizedClient(any(), any(), any())) .thenReturn(Mono.empty()); this.filter.filter(exchange, chain).block(); verify(this.authorizedClientRepository).saveAuthorizedClient(any(), any(AnonymousAuthenticationToken.class), any()); } }