QueryIPRetriever implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try { Optional<String> vipClientIP = getVipClientIP(request); if (vipClientIP.isPresent()) { ipAddress.set(vipClientIP.get()); } else { String remoteAddr = request.getRemoteAddr(); logger.debug( "remoteAddr: " + remoteAddr); ipAddress.set(remoteAddr); } chain.doFilter(request, response); } finally { ipAddress.remove(); } } QueryIPRetriever(String ipForwardingHeaderValue, 
							String[] mappingsValue);  QueryIPRetriever(); static String getIpAddress(); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void init(FilterConfig filterConfig); @Override void destroy();  }
@Test public void testDoFilter() throws IOException, ServletException { ServletRequest request = mock(ServletRequest.class); ServletResponse response = mock(ServletResponse.class); when(request.getRemoteAddr()).thenReturn("10.10.11.11"); QueryIPRetriever queryIPRetriever = new QueryIPRetriever(); MyFilterChain myFilterChain = new MyFilterChain(); myFilterChain.setQueryIPRetriever(queryIPRetriever); queryIPRetriever.doFilter(request, response, myFilterChain); assertEquals("IP address not equal", "10.10.11.11", myFilterChain.getIpAddress()); assertNull(QueryIPRetriever.getIpAddress()); }