@Override
    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
        final HttpServletRequest req = (HttpServletRequest) request;
        final Thread current = Thread.currentThread();
        final String oldName = current.getName();
        try {
            current.setName(formatName(req, oldName));
            chain.doFilter(request, response);
        } finally {
            current.setName(oldName);
        }
    }
@Test
    void setsThreadNameInChain() throws Exception {
        when(request.getMethod()).thenReturn("GET");
        when(request.getRequestURI()).thenReturn("/some/path");

        doAnswer(invocationOnMock -> {
            assertThat(Thread.currentThread().getName()).isEqualTo("test-thread - GET /some/path");
            return null;
        }).when(chain).doFilter(request, response);

        Thread.currentThread().setName("test-thread");
        threadNameFilter.doFilter(request, response, chain);

        verify(chain).doFilter(request, response);
        assertThat(Thread.currentThread().getName()).isEqualTo("test-thread");
    }