Copilot commented on code in PR #6337:
URL: https://github.com/apache/shenyu/pull/6337#discussion_r3198439324
##########
shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/test/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListenerTest.java:
##########
@@ -85,20 +89,7 @@ public class SpringWebSocketClientEventListenerTest {
@BeforeEach
public void setUp() {
MockitoAnnotations.openMocks(this);
- Properties properties = mock(Properties.class);
- when(properties.getProperty("appName")).thenReturn("appName");
- when(properties.getProperty("contextPath")).thenReturn("contextPath");
-
when(properties.getProperty(ShenyuClientConstants.PORT)).thenReturn("8080");
-
when(properties.getProperty(ShenyuClientConstants.HOST)).thenReturn("127.0.0.1");
-
when(properties.getProperty(ShenyuClientConstants.IP_PORT)).thenReturn("127.0.0.1:8080");
-
- ShenyuClientConfig clientConfig = mock(ShenyuClientConfig.class);
- Map<String, ClientPropertiesConfig> client = new HashMap<>();
- ClientPropertiesConfig clientPropertiesConfig = new
ClientPropertiesConfig();
- clientPropertiesConfig.setProps(properties);
- client.put(RpcTypeEnum.WEB_SOCKET.getName(), clientPropertiesConfig);
- when(clientConfig.getClient()).thenReturn(client);
- eventListener = new SpringWebSocketClientEventListener(clientConfig,
registerRepository);
+ eventListener = buildEventListener(false);
Review Comment:
`@ExtendWith(MockitoExtension.class)` already initializes/cleans up mocks.
Calling `MockitoAnnotations.openMocks(this)` here is redundant and the returned
`AutoCloseable` is not closed, which can leak Mockito resources across tests.
Remove the `openMocks` call (preferred) or store/close it in an `@AfterEach`.
--
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]