Source:
<code>public void closesSpanWhenResponseStatusIs2xxAndExceptionIsClientAbortException() throws Exception { this.request = builder().header(Span.SPAN_ID_NAME, PARENT_ID) .header(Span.TRACE_ID_NAME, 20L).buildRequest(new MockServletContext()); TraceFilter filter = new TraceFilter(beanFactory()); BDDMockito.given(beanFactory.getBean(ErrorController.class)).willReturn(() -> "/error"); <START> List<ExceptionToIgnoreInTraceFilter> filters = Lists.newArrayList(getClientAbortExpcetionToIgnoreInTraceFilter()); <END> BDDMockito.given(beanFactory.getBean(ExceptionToIgnoreInTraceFilterProvider.class)) .willReturn(getExceptionToIgnoreInTraceFilterProvider(filters)); this.response = new MockHttpServletResponse(){ @Override public ServletOutputStream getOutputStream() { ServletOutputStream outputStream = super.getOutputStream(); return new ServletOutputStream() { @Override public boolean isReady() { return outputStream.isReady(); } @Override public void setWriteListener(WriteListener listener) { outputStream.setWriteListener(listener); } @Override public void write(int b) throws IOException { outputStream.write(b); } @Override public void flush() throws IOException { throw new ClientAbortException("Broken pipe"); } }; } }; response.setStatus(200); this.filterChain = new MockFilterChain(){ @Override public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { ServletOutputStream outputStream = response.getOutputStream(); outputStream.write(1); outputStream.flush(); } }; try { filter.doFilter(this.request, this.response, this.filterChain); }catch (ClientAbortException e){ } then(TestSpanContextHolder.getCurrentSpan()).isNull(); }</code><technical_language>yeah java then(TestSpanContextHolder.getCurrentSpan()).isNull(); // verify span reported then(spanReporter.getSpans()).hasSize(1);</technical_language>

Target:
public void closesSpanWhenResponseStatusIs2xxAndExceptionIsClientAbortException() throws Exception { this.request = builder().header(Span.SPAN_ID_NAME, PARENT_ID) .header(Span.TRACE_ID_NAME, 20L).buildRequest(new MockServletContext()); TraceFilter filter = new TraceFilter(beanFactory()); BDDMockito.given(beanFactory.getBean(ErrorController.class)).willReturn(() -> "/error"); List<ExceptionToIgnoreInTraceFilter> filters = Lists.newArrayList(getClientAbortExpcetionToIgnoreInTraceFilter()); BDDMockito.given(beanFactory.getBean(ExceptionToIgnoreInTraceFilterProvider.class)) .willReturn(getExceptionToIgnoreInTraceFilterProvider(filters)); this.response = new MockHttpServletResponse(){ @Override public ServletOutputStream getOutputStream() { ServletOutputStream outputStream = super.getOutputStream(); return new ServletOutputStream() { @Override public boolean isReady() { return outputStream.isReady(); } @Override public void setWriteListener(WriteListener listener) { outputStream.setWriteListener(listener); } @Override public void write(int b) throws IOException { outputStream.write(b); } @Override public void flush() throws IOException { throw new ClientAbortException("Broken pipe"); } }; } }; response.setStatus(200); this.filterChain = new MockFilterChain(){ @Override public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { ServletOutputStream outputStream = response.getOutputStream(); outputStream.write(1); outputStream.flush(); } }; try { filter.doFilter(this.request, this.response, this.filterChain); }catch (ClientAbortException e){ } then(TestSpanContextHolder.getCurrentSpan()).isNull(); then(spanReporter.getSpans()).hasSize(1); }