gnodet-bot commented on code in PR #13832:
URL: https://github.com/apache/maven/pull/13832#discussion_r4530750755


##########
impl/maven-logging-jul/src/test/java/org/apache/maven/logging/jul/MavenJulHandlerTest.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.logging.jul;
+
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+import org.apache.maven.api.logging.LogLevel;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class MavenJulHandlerTest {
+
+    @ParameterizedTest(name = "JUL {0} -> LogLevel.{1}")
+    @CsvSource({
+        "FINEST, TRACE",
+        "FINER, DEBUG",
+        "FINE, DEBUG",
+        "CONFIG, INFO",
+        "INFO, INFO",
+        "WARNING, WARN",
+        "SEVERE, ERROR",
+    })
+    void julLevelMapsToCorrectLogLevel(String julLevelName, String 
expectedLogLevel) {
+        Level julLevel = Level.parse(julLevelName);
+        LogLevel actual = MavenJulHandler.julLevelToLogLevel(julLevel);
+        assertEquals(LogLevel.valueOf(expectedLogLevel), actual);
+    }
+
+    @Test
+    void finestMapsToTrace() {
+        assertEquals(LogLevel.TRACE, 
MavenJulHandler.julLevelToLogLevel(Level.FINEST));
+    }
+
+    @Test
+    void configMapsToInfo() {
+        assertEquals(LogLevel.INFO, 
MavenJulHandler.julLevelToLogLevel(Level.CONFIG));
+    }
+
+    @Test
+    void publishIsReentrantSafe() {
+        MavenJulHandler handler = new MavenJulHandler();
+        LogRecord record = new LogRecord(Level.INFO, "nested");
+
+        MavenJulHandler.setInPublishForTest(true);
+        try {
+            handler.publish(record);
+        } finally {
+            MavenJulHandler.setInPublishForTest(false);
+        }
+    }
+}

Review Comment:
   ⚠️ **Missing test for the lazy-formatting path**
   
   `publishIsReentrantSafe()` returns at the reentrancy guard (`isInPublish` is 
`true`) before reaching the `DefaultLogEvent` constructor — it never exercises 
the new `messageTemplate` / `messageArgs` path. The other tests only cover 
`julLevelToLogLevel()`.
   
   Add a test that exercises the full `publish()` path with a parameterized 
`LogRecord` and asserts the formatted message:
   
   ```java
   @Test
   void publishWithParameterizedMessage() throws Exception {
       MavenJulHandler handler = new MavenJulHandler();
       
java.util.concurrent.atomic.AtomicReference<org.apache.maven.api.logging.LogEvent>
 captured =
               new java.util.concurrent.atomic.AtomicReference<>();
       
org.apache.maven.api.logging.LoggerManager.get().setLogSink(captured::set);
       try {
           LogRecord record = new LogRecord(Level.INFO, "Hello {0}, value={1}");
           record.setParameters(new Object[]{"world", 42});
           handler.publish(record);
           org.apache.maven.api.logging.LogEvent event = captured.get();
           assertNotNull(event, "event must be captured");
           assertEquals("Hello world, value=42", event.message());
           assertEquals("Hello {0}, value={1}", event.messageTemplate());
       } finally {
           org.apache.maven.api.logging.LoggerManager.get().setLogSink(null);
       }
   }
   ```
   
   Also add a case for the apostrophe-corruption fix that motivated this change:
   
   ```java
   @Test
   void apostropheInMessageTemplateIsPreserved() throws Exception {
       MavenJulHandler handler = new MavenJulHandler();
       
java.util.concurrent.atomic.AtomicReference<org.apache.maven.api.logging.LogEvent>
 captured =
               new java.util.concurrent.atomic.AtomicReference<>();
       
org.apache.maven.api.logging.LoggerManager.get().setLogSink(captured::set);
       try {
           LogRecord record = new LogRecord(Level.WARNING, "Can''t find {0}");
           record.setParameters(new Object[]{"artifact"});
           handler.publish(record);
           // The old MessageFormat.format() path would produce "Cant find 
artifact"
           // (double-apostrophe is the MessageFormat escape — it disappears).
           // The new positional path preserves both characters.
           assertEquals("Can''t find artifact", captured.get().message());
       } finally {
           org.apache.maven.api.logging.LoggerManager.get().setLogSink(null);
       }
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to