Copilot commented on code in PR #6348:
URL: https://github.com/apache/shenyu/pull/6348#discussion_r3575931807


##########
shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java:
##########
@@ -210,6 +218,57 @@ public void testOnBuildApiSuperPath() {
         registerUtilsMockedStatic.close();
     }
 
+    @Test
+    public void testBuildApiDocSextetDefaultProducesConsumes() throws 
NoSuchMethodException {
+        SpringMvcClientEventListener listener = 
buildSpringMvcClientEventListener(false, false);
+        Method method = ApiDocTestBean.class.getDeclaredMethod("getDefault");
+        Sextet<String[], String, String, ApiHttpMethodEnum[], RpcTypeEnum, 
String> result =
+                listener.buildApiDocSextet(method, null, 
Collections.emptyMap());
+
+        Assertions.assertArrayEquals(new String[]{"/get-default"}, 
result.getValue0());
+        Assertions.assertEquals("*/*", result.getValue1());
+        Assertions.assertEquals("*/*", result.getValue2());
+        Assertions.assertArrayEquals(new 
ApiHttpMethodEnum[]{ApiHttpMethodEnum.GET}, result.getValue3());
+        Assertions.assertEquals(RpcTypeEnum.HTTP, result.getValue4());
+        Assertions.assertEquals("v0.01", result.getValue5());
+        registerUtilsMockedStatic.close();
+    }

Review Comment:
   registerUtilsMockedStatic.close() is not in a finally block, so if an 
assertion fails (or an exception is thrown) the static mock may remain open and 
leak into later tests. Wrap the test body in try/finally (or close in an 
@AfterEach) to guarantee cleanup.



##########
shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java:
##########
@@ -210,6 +218,57 @@ public void testOnBuildApiSuperPath() {
         registerUtilsMockedStatic.close();
     }
 
+    @Test
+    public void testBuildApiDocSextetDefaultProducesConsumes() throws 
NoSuchMethodException {
+        SpringMvcClientEventListener listener = 
buildSpringMvcClientEventListener(false, false);
+        Method method = ApiDocTestBean.class.getDeclaredMethod("getDefault");
+        Sextet<String[], String, String, ApiHttpMethodEnum[], RpcTypeEnum, 
String> result =
+                listener.buildApiDocSextet(method, null, 
Collections.emptyMap());
+
+        Assertions.assertArrayEquals(new String[]{"/get-default"}, 
result.getValue0());
+        Assertions.assertEquals("*/*", result.getValue1());
+        Assertions.assertEquals("*/*", result.getValue2());
+        Assertions.assertArrayEquals(new 
ApiHttpMethodEnum[]{ApiHttpMethodEnum.GET}, result.getValue3());
+        Assertions.assertEquals(RpcTypeEnum.HTTP, result.getValue4());
+        Assertions.assertEquals("v0.01", result.getValue5());
+        registerUtilsMockedStatic.close();
+    }
+
+    @Test
+    public void testBuildApiDocSextetExplicitProducesConsumesAndMethod() 
throws NoSuchMethodException {
+        SpringMvcClientEventListener listener = 
buildSpringMvcClientEventListener(false, false);
+        Method method = ApiDocTestBean.class.getDeclaredMethod("postExplicit", 
String.class);
+        Sextet<String[], String, String, ApiHttpMethodEnum[], RpcTypeEnum, 
String> result =
+                listener.buildApiDocSextet(method, null, 
Collections.emptyMap());
+
+        Assertions.assertArrayEquals(new String[]{"/post-explicit"}, 
result.getValue0());
+        Assertions.assertEquals("application/json", result.getValue1());
+        Assertions.assertEquals("application/json", result.getValue2());
+        Assertions.assertArrayEquals(new 
ApiHttpMethodEnum[]{ApiHttpMethodEnum.POST}, result.getValue3());
+        Assertions.assertEquals(RpcTypeEnum.HTTP, result.getValue4());
+        Assertions.assertEquals("v0.01", result.getValue5());
+        registerUtilsMockedStatic.close();
+    }

Review Comment:
   registerUtilsMockedStatic.close() is not in a finally block, so if an 
assertion fails (or an exception is thrown) the static mock may remain open and 
leak into later tests. Wrap the test body in try/finally (or close in an 
@AfterEach) to guarantee cleanup.



##########
shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/SpringMvcMappingPathControllerTest.java:
##########
@@ -17,30 +17,75 @@
 
 package org.apache.shenyu.integrated.test.http;
 
-import org.junit.jupiter.api.Test;
-import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
 import org.apache.shenyu.integratedtest.common.AbstractTest;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
+import java.util.concurrent.TimeUnit;
 
-public class SpringMvcMappingPathControllerTest extends AbstractTest {
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class SpringMvcMappingPathControllerTest extends AbstractTest {
+
+    private static final String MULTI_PATH_SUFFIX = "I'm Shenyu-Gateway 
System. Welcome!";
+
+    @BeforeAll
+    static void waitForMultiPathRoutes() throws InterruptedException {
+        // Multi-path routes are registered asynchronously; poll until 
available
+        for (int i = 0; i < 30; i++) {
+            try {
+                String res = 
HttpHelper.INSTANCE.postGateway("/http/multipath/v1/greet", String.class);
+                if (("hello from multipath! " + 
MULTI_PATH_SUFFIX).equals(res)) {
+                    return;
+                }
+            } catch (IOException e) {
+                // route not ready yet, keep waiting
+            }
+            Thread.sleep(TimeUnit.SECONDS.toMillis(2));
+        }
+    }

Review Comment:
   The `@BeforeAll` polling loop exits silently after the timeout, which can 
make subsequent test failures confusing (and still spends up to 60s waiting). 
If the route never becomes available, fail the test setup explicitly so the 
cause is clear.



##########
shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/test/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListenerTest.java:
##########
@@ -210,6 +218,57 @@ public void testOnBuildApiSuperPath() {
         registerUtilsMockedStatic.close();
     }
 
+    @Test
+    public void testBuildApiDocSextetDefaultProducesConsumes() throws 
NoSuchMethodException {
+        SpringMvcClientEventListener listener = 
buildSpringMvcClientEventListener(false, false);
+        Method method = ApiDocTestBean.class.getDeclaredMethod("getDefault");
+        Sextet<String[], String, String, ApiHttpMethodEnum[], RpcTypeEnum, 
String> result =
+                listener.buildApiDocSextet(method, null, 
Collections.emptyMap());
+
+        Assertions.assertArrayEquals(new String[]{"/get-default"}, 
result.getValue0());
+        Assertions.assertEquals("*/*", result.getValue1());
+        Assertions.assertEquals("*/*", result.getValue2());
+        Assertions.assertArrayEquals(new 
ApiHttpMethodEnum[]{ApiHttpMethodEnum.GET}, result.getValue3());
+        Assertions.assertEquals(RpcTypeEnum.HTTP, result.getValue4());
+        Assertions.assertEquals("v0.01", result.getValue5());
+        registerUtilsMockedStatic.close();
+    }
+
+    @Test
+    public void testBuildApiDocSextetExplicitProducesConsumesAndMethod() 
throws NoSuchMethodException {
+        SpringMvcClientEventListener listener = 
buildSpringMvcClientEventListener(false, false);
+        Method method = ApiDocTestBean.class.getDeclaredMethod("postExplicit", 
String.class);
+        Sextet<String[], String, String, ApiHttpMethodEnum[], RpcTypeEnum, 
String> result =
+                listener.buildApiDocSextet(method, null, 
Collections.emptyMap());
+
+        Assertions.assertArrayEquals(new String[]{"/post-explicit"}, 
result.getValue0());
+        Assertions.assertEquals("application/json", result.getValue1());
+        Assertions.assertEquals("application/json", result.getValue2());
+        Assertions.assertArrayEquals(new 
ApiHttpMethodEnum[]{ApiHttpMethodEnum.POST}, result.getValue3());
+        Assertions.assertEquals(RpcTypeEnum.HTTP, result.getValue4());
+        Assertions.assertEquals("v0.01", result.getValue5());
+        registerUtilsMockedStatic.close();
+    }
+
+    @Test
+    public void testBuildApiDocSextetMultipleMethodsProducesConsumes() throws 
NoSuchMethodException {
+        SpringMvcClientEventListener listener = 
buildSpringMvcClientEventListener(false, false);
+        Method method = ApiDocTestBean.class.getDeclaredMethod("multi", 
String.class);
+        Sextet<String[], String, String, ApiHttpMethodEnum[], RpcTypeEnum, 
String> result =
+                listener.buildApiDocSextet(method, null, 
Collections.emptyMap());
+
+        Assertions.assertArrayEquals(new String[]{"/multi"}, 
result.getValue0());
+        Assertions.assertEquals("application/json,application/xml", 
result.getValue1());
+        Assertions.assertEquals("application/json,application/xml", 
result.getValue2());
+        List<ApiHttpMethodEnum> methods = Arrays.asList(result.getValue3());
+        Assertions.assertTrue(methods.contains(ApiHttpMethodEnum.GET));
+        Assertions.assertTrue(methods.contains(ApiHttpMethodEnum.POST));
+        Assertions.assertEquals(2, methods.size());
+        Assertions.assertEquals(RpcTypeEnum.HTTP, result.getValue4());
+        Assertions.assertEquals("v0.01", result.getValue5());
+        registerUtilsMockedStatic.close();
+    }

Review Comment:
   registerUtilsMockedStatic.close() is not in a finally block, so if an 
assertion fails (or an exception is thrown) the static mock may remain open and 
leak into later tests. Wrap the test body in try/finally (or close in an 
@AfterEach) to guarantee cleanup.



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