@@ -26,7 +26,6 @@ void callsNextFilterInChain() throws IOException {
2626
2727 @ Test
2828 void logsHttpMethodAndPath () throws IOException {
29-
3029 LoggingFilter filter = new LoggingFilter ();
3130 HttpRequest req = mock (HttpRequest .class );
3231 HttpResponse res = mock (HttpResponse .class );
@@ -35,17 +34,28 @@ void logsHttpMethodAndPath() throws IOException {
3534 when (req .method ()).thenReturn ("GET" );
3635 when (req .path ()).thenReturn ("/test" );
3736
38- var originalOut = System .out ;
39- var out = new java .io .ByteArrayOutputStream ();
40- System .setOut (new java .io .PrintStream (out ));
37+ java .util .logging .Logger logger = org .juv25d .logging .ServerLogging .getLogger ();
38+ java .util .List <java .util .logging .LogRecord > records = new java .util .ArrayList <>();
39+ java .util .logging .Handler handler = new java .util .logging .Handler () {
40+ @ Override
41+ public void publish (java .util .logging .LogRecord record ) {
42+ records .add (record );
43+ }
44+ @ Override
45+ public void flush () {}
46+ @ Override
47+ public void close () throws SecurityException {}
48+ };
49+ logger .addHandler (handler );
4150
4251 try {
4352 filter .doFilter (req , res , chain );
4453
45- String output = out .toString ();
46- assertTrue (output .contains ("GET /test" ), "Output should contain logged method and path" );
54+ boolean found = records .stream ()
55+ .anyMatch (r -> r .getMessage ().contains ("GET /test" ));
56+ assertTrue (found , "Logger should have captured the method and path" );
4757 } finally {
48- System . setOut ( originalOut );
58+ logger . removeHandler ( handler );
4959 }
5060 }
5161}
0 commit comments