Copilot commented on code in PR #7398: URL: https://github.com/apache/incubator-seata/pull/7398#discussion_r2131597401
########## spring/pom.xml: ########## @@ -81,6 +81,19 @@ <artifactId>kotlin-test</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-core</artifactId> Review Comment: The `logback-core` dependency is added without a `<scope>test</scope>`. If it's only needed for testing, scope it as test to keep the runtime classpath clean. ```suggestion <artifactId>logback-core</artifactId> <scope>test</scope> ``` ########## spring/src/test/java/org/apache/seata/spring/tcc/TccAnnotationProcessorTest.java: ########## @@ -0,0 +1,177 @@ +/* + * 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.seata.spring.tcc; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; +import org.apache.seata.integration.tx.api.util.ProxyUtil; +import org.apache.seata.rm.tcc.api.TwoPhaseBusinessAction; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.slf4j.LoggerFactory; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class TccAnnotationProcessorTest { + private ListAppender<ILoggingEvent> listAppender; + private TccAnnotationProcessor processor; + private Set<String> proxied; + private List<Class<? extends Annotation>> annotations; + + @BeforeEach + public void setUp() throws NoSuchFieldException, IllegalAccessException { + processor = new TccAnnotationProcessor(); + + Logger logger = (Logger) LoggerFactory.getLogger(TccAnnotationProcessor.class); + listAppender = new ListAppender<>(); + listAppender.start(); + logger.addAppender(listAppender); + + Field proxiedField = TccAnnotationProcessor.class.getDeclaredField("PROXIED_SET"); + proxiedField.setAccessible(true); + proxied = (Set<String>) proxiedField.get(null); + + Field annotationsField = TccAnnotationProcessor.class.getDeclaredField("ANNOTATIONS"); + annotationsField.setAccessible(true); + annotations = (List<Class<? extends Annotation>>) annotationsField.get(null); + } + + @AfterEach + public void tearDown() { + listAppender.stop(); + listAppender.list.clear(); + proxied.clear(); + annotations.clear(); Review Comment: Clearing the static `ANNOTATIONS` and `PROXIED_SET` fields without restoring their original contents can lead to state leakage across tests. Store a copy of the original lists in `setUp` and restore them in `tearDown`. ```suggestion proxied.clear(); proxied.addAll(originalProxied); // Restore the original state annotations.clear(); annotations.addAll(originalAnnotations); // Restore the original state ``` ########## spring/src/test/java/org/apache/seata/spring/tcc/TccAnnotationProcessorTest.java: ########## @@ -0,0 +1,177 @@ +/* + * 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.seata.spring.tcc; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; +import org.apache.seata.integration.tx.api.util.ProxyUtil; +import org.apache.seata.rm.tcc.api.TwoPhaseBusinessAction; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.slf4j.LoggerFactory; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class TccAnnotationProcessorTest { + private ListAppender<ILoggingEvent> listAppender; + private TccAnnotationProcessor processor; + private Set<String> proxied; + private List<Class<? extends Annotation>> annotations; + + @BeforeEach + public void setUp() throws NoSuchFieldException, IllegalAccessException { + processor = new TccAnnotationProcessor(); + + Logger logger = (Logger) LoggerFactory.getLogger(TccAnnotationProcessor.class); Review Comment: The logger level isn’t explicitly set, so INFO-level logs may not be captured by the ListAppender. Consider adding `logger.setLevel(Level.INFO);` after obtaining the logger. ```suggestion Logger logger = (Logger) LoggerFactory.getLogger(TccAnnotationProcessor.class); logger.setLevel(Level.INFO); ``` ########## spring/pom.xml: ########## @@ -81,6 +81,19 @@ <artifactId>kotlin-test</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> Review Comment: The `slf4j-api` dependency is added without a `<scope>test</scope>`. If it's only used for tests, mark it as test scope to avoid leaking into the main runtime classpath. ```suggestion <artifactId>slf4j-api</artifactId> <scope>test</scope> ``` -- 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: notifications-unsubscr...@seata.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org