final String clientIp = "1.1.1.1";
when(request.getRemoteAddr()).thenReturn("9.9.9.9");
when(request.getHeaders("X-FORWARDED-FOR")).thenReturn(Collections.enumeration(ImmutableList.of(clientIp, "192.168.1.2, 172.16.0.1", "169.254.1.2, 127.1.2.3", "10.1.2.3")));
InMemoryEventClient eventClient = new InMemoryEventClient();
DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, null, eventClient);
logger.log(request, response);
logger.stop();
List<Object> events = eventClient.getEvents();
Assert.assertEquals(events.size(), 1);
HttpRequestEvent event = (HttpRequestEvent) events.get(0);
Assert.assertEquals(event.getClientAddress(), clientIp);
}