@Override
    @NonNull
    public Mono<Void> filter(@NonNull ServerWebExchange exchange, @NonNull WebFilterChain chain) {
        return redirectMatcher.matches(exchange)
            .flatMap(matched -> {
                if (!matched.isMatch()) {
                    return chain.filter(exchange);
                }
                return initializationStateGetter.userInitialized()
                    .defaultIfEmpty(false)
                    .flatMap(initialized -> {
                        if (initialized) {
                            return chain.filter(exchange);
                        }
                        // Redirect to set up page if system is not initialized.
                        return redirectStrategy.sendRedirect(exchange, location);
                    });
            });
    }
@Test
    void shouldRedirectWhenSystemNotInitialized() {
        when(initializationStateGetter.userInitialized()).thenReturn(Mono.just(false));

        WebFilterChain chain = mock(WebFilterChain.class);

        MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
        MockServerWebExchange exchange = MockServerWebExchange.from(request);

        when(serverRedirectStrategy.sendRedirect(any(), any())).thenReturn(Mono.empty().then());

        Mono<Void> result = filter.filter(exchange, chain);

        StepVerifier.create(result)
            .expectNextCount(0)
            .expectComplete()
            .verify();

        verify(serverRedirectStrategy).sendRedirect(eq(exchange), eq(URI.create("/console")));
        verify(chain, never()).filter(eq(exchange));
    }