gnodet commented on code in PR #12694:
URL: https://github.com/apache/maven/pull/12694#discussion_r4057750748


##########
impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultLogTest.java:
##########
@@ -51,13 +54,31 @@ void warnWithSupplierAndThrowableDelegatesToWarn() {
         verify(mockLogger).warn("warning message", ex);
     }
 
+    /**
+     * Verify that Log API metadata is set during the log call and
+     * cleared afterwards — no leakage across calls.
+     */
+    @Test
+    void logApiMetadataIsClearedAfterCall() {
+        Logger mockLogger = mock(Logger.class);
+        when(mockLogger.isInfoEnabled()).thenReturn(true);
+        when(mockLogger.getName()).thenReturn("com.example.MyMojo");
+
+        DefaultLog log = new DefaultLog(mockLogger);
+        log.info("test message");
+
+        // After the call completes, metadata should be cleared
+        assertNull(DefaultLog.getLogApiMetadata(), "Log API metadata should be 
cleared after the log call");

Review Comment:
   Fixed in d7f564ab9dbd8fd1e4f44cb06d13d03d515b08c4: the test now calls 
`ProjectBuildLogAppender.setReportCapture(event -> {})` before `log.info()` to 
activate the metadata code path, ensuring the `finally { 
LOG_API_METADATA.remove() }` block is actually exercised. Capture is cleared in 
a `finally` block to avoid leaking across tests.



##########
impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultLogTest.java:
##########
@@ -51,13 +54,31 @@ void warnWithSupplierAndThrowableDelegatesToWarn() {
         verify(mockLogger).warn("warning message", ex);
     }
 
+    /**
+     * Verify that Log API metadata is set during the log call and
+     * cleared afterwards — no leakage across calls.
+     */
+    @Test
+    void logApiMetadataIsClearedAfterCall() {
+        Logger mockLogger = mock(Logger.class);
+        when(mockLogger.isInfoEnabled()).thenReturn(true);
+        when(mockLogger.getName()).thenReturn("com.example.MyMojo");
+
+        DefaultLog log = new DefaultLog(mockLogger);
+        log.info("test message");
+
+        // After the call completes, metadata should be cleared
+        assertNull(DefaultLog.getLogApiMetadata(), "Log API metadata should be 
cleared after the log call");

Review Comment:
   Fixed in d7f564ab9dbd8fd1e4f44cb06d13d03d515b08c4: the test now calls 
`ProjectBuildLogAppender.setReportCapture(event -> {})` before `log.info()` to 
activate the metadata code path, ensuring the `finally { 
LOG_API_METADATA.remove() }` block is actually exercised. Capture is cleared in 
a `finally` block to avoid leaking across tests.



##########
impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultLogTest.java:
##########
@@ -51,13 +54,31 @@ void warnWithSupplierAndThrowableDelegatesToWarn() {
         verify(mockLogger).warn("warning message", ex);
     }
 
+    /**
+     * Verify that Log API metadata is set during the log call and
+     * cleared afterwards — no leakage across calls.
+     */
+    @Test
+    void logApiMetadataIsClearedAfterCall() {
+        Logger mockLogger = mock(Logger.class);
+        when(mockLogger.isInfoEnabled()).thenReturn(true);
+        when(mockLogger.getName()).thenReturn("com.example.MyMojo");
+
+        DefaultLog log = new DefaultLog(mockLogger);
+        log.info("test message");
+
+        // After the call completes, metadata should be cleared
+        assertNull(DefaultLog.getLogApiMetadata(), "Log API metadata should be 
cleared after the log call");

Review Comment:
   Fixed in d7f564ab9dbd8fd1e4f44cb06d13d03d515b08c4: the test now calls 
`ProjectBuildLogAppender.setReportCapture(event -> {})` before `log.info()` to 
activate the metadata code path, ensuring the `finally { 
LOG_API_METADATA.remove() }` block is actually exercised. Capture is cleared in 
a `finally` block to avoid leaking across tests.



-- 
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