pandaapo commented on code in PR #4522: URL: https://github.com/apache/eventmesh/pull/4522#discussion_r1398197182
########## eventmesh-connectors/eventmesh-connector-feishu/src/test/java/org/apache/eventmesh/connector/s3/source/FeishuSinkConnectorTest.java: ########## @@ -0,0 +1,99 @@ +/* + * 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.eventmesh.connector.s3.source; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.apache.eventmesh.connector.feishu.sink.config.FeishuSinkConfig; +import org.apache.eventmesh.connector.feishu.sink.config.SinkConnectorConfig; +import org.apache.eventmesh.connector.feishu.sink.connector.FeishuSinkConnector; +import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.platform.commons.support.HierarchyTraversalMode; +import org.junit.platform.commons.support.ReflectionSupport; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.lark.oapi.Client; +import com.lark.oapi.core.response.RawResponse; + +@ExtendWith(MockitoExtension.class) +public class FeishuSinkConnectorTest { + + private static final FeishuSinkConfig sinkConfig; + + private static final SinkConnectorConfig SINK_CONNECTOR_CONFIG; + + static { + sinkConfig = new FeishuSinkConfig(); + SINK_CONNECTOR_CONFIG = new SinkConnectorConfig(); + SINK_CONNECTOR_CONFIG.setConnectorName("FeishuSinkConnector"); + SINK_CONNECTOR_CONFIG.setAppId("xxx"); + SINK_CONNECTOR_CONFIG.setAppSecret("xxx"); + SINK_CONNECTOR_CONFIG.setReceiveId("xxx"); + SINK_CONNECTOR_CONFIG.setReceiveIdType("open_id"); + sinkConfig.setConnectorConfig(SINK_CONNECTOR_CONFIG); + } + + @Spy + private FeishuSinkConnector feishuSinkConnector; + + @Mock + private Client feishuClient; + + @BeforeEach + public void setup() throws Exception { + RawResponse response = new RawResponse(); + response.setStatusCode(200); + Mockito.doReturn(response).when(feishuClient).post(Mockito.any(), Mockito.any(), Mockito.any()); + + Field feishuClientField = ReflectionSupport.findFields(feishuSinkConnector.getClass(), + (f) -> f.getName().equals("feishuClient"), + HierarchyTraversalMode.BOTTOM_UP).get(0); + + feishuClientField.setAccessible(true); + feishuClientField.set(feishuSinkConnector, feishuClient); + + Field sinkConfigField = ReflectionSupport.findFields(feishuSinkConnector.getClass(), + (f) -> f.getName().equals("sinkConfig"), + HierarchyTraversalMode.BOTTOM_UP).get(0); + + sinkConfigField.setAccessible(true); + sinkConfigField.set(feishuSinkConnector, sinkConfig); + } + + @Test + public void testFeishuSinkConnector() { + assertDoesNotThrow(() -> { Review Comment: Now that you are using Mockito for mocking, you can change the verification method of `assertDoesNotThrow()` to verify the number of calls to the `feishuClient` that you are mocking. Otherwise, the introduction of Mockito is meaningless. 现在您已经使用Mockito进行模拟了,就可以将`assertDoesNotThrow()`的验证方式改成验证您所模拟的`feishuClient`的调用次数。否则引入的Mockito就没有意义了。 ########## eventmesh-connectors/eventmesh-connector-feishu/src/test/java/org/apache/eventmesh/connector/s3/source/FeishuSinkConnectorTest.java: ########## @@ -0,0 +1,99 @@ +/* + * 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.eventmesh.connector.s3.source; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.apache.eventmesh.connector.feishu.sink.config.FeishuSinkConfig; +import org.apache.eventmesh.connector.feishu.sink.config.SinkConnectorConfig; +import org.apache.eventmesh.connector.feishu.sink.connector.FeishuSinkConnector; +import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.platform.commons.support.HierarchyTraversalMode; +import org.junit.platform.commons.support.ReflectionSupport; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.lark.oapi.Client; +import com.lark.oapi.core.response.RawResponse; + +@ExtendWith(MockitoExtension.class) +public class FeishuSinkConnectorTest { + + private static final FeishuSinkConfig sinkConfig; + + private static final SinkConnectorConfig SINK_CONNECTOR_CONFIG; + + static { + sinkConfig = new FeishuSinkConfig(); + SINK_CONNECTOR_CONFIG = new SinkConnectorConfig(); + SINK_CONNECTOR_CONFIG.setConnectorName("FeishuSinkConnector"); + SINK_CONNECTOR_CONFIG.setAppId("xxx"); + SINK_CONNECTOR_CONFIG.setAppSecret("xxx"); + SINK_CONNECTOR_CONFIG.setReceiveId("xxx"); + SINK_CONNECTOR_CONFIG.setReceiveIdType("open_id"); + sinkConfig.setConnectorConfig(SINK_CONNECTOR_CONFIG); + } + + @Spy + private FeishuSinkConnector feishuSinkConnector; + + @Mock + private Client feishuClient; + + @BeforeEach + public void setup() throws Exception { + RawResponse response = new RawResponse(); + response.setStatusCode(200); + Mockito.doReturn(response).when(feishuClient).post(Mockito.any(), Mockito.any(), Mockito.any()); + + Field feishuClientField = ReflectionSupport.findFields(feishuSinkConnector.getClass(), + (f) -> f.getName().equals("feishuClient"), + HierarchyTraversalMode.BOTTOM_UP).get(0); + + feishuClientField.setAccessible(true); + feishuClientField.set(feishuSinkConnector, feishuClient); + + Field sinkConfigField = ReflectionSupport.findFields(feishuSinkConnector.getClass(), + (f) -> f.getName().equals("sinkConfig"), + HierarchyTraversalMode.BOTTOM_UP).get(0); + + sinkConfigField.setAccessible(true); + sinkConfigField.set(feishuSinkConnector, sinkConfig); + } + + @Test + public void testFeishuSinkConnector() { + assertDoesNotThrow(() -> { Review Comment: Now that you are using Mockito for mocking, you can change the verification method of `assertDoesNotThrow()` to verify the number of calls to the `feishuClient` that you are mocking. Otherwise, the introduction of Mockito is meaningless. 现在您已经使用Mockito进行模拟了,就可以将`assertDoesNotThrow()`的验证方式改成验证您所模拟的`feishuClient`的调用次数。否则引入的Mockito就没有意义了。 ########## eventmesh-connectors/eventmesh-connector-feishu/src/test/java/org/apache/eventmesh/connector/s3/source/FeishuSinkConnectorTest.java: ########## @@ -0,0 +1,99 @@ +/* + * 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.eventmesh.connector.s3.source; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.apache.eventmesh.connector.feishu.sink.config.FeishuSinkConfig; +import org.apache.eventmesh.connector.feishu.sink.config.SinkConnectorConfig; +import org.apache.eventmesh.connector.feishu.sink.connector.FeishuSinkConnector; +import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.platform.commons.support.HierarchyTraversalMode; +import org.junit.platform.commons.support.ReflectionSupport; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.lark.oapi.Client; +import com.lark.oapi.core.response.RawResponse; + +@ExtendWith(MockitoExtension.class) +public class FeishuSinkConnectorTest { + + private static final FeishuSinkConfig sinkConfig; + + private static final SinkConnectorConfig SINK_CONNECTOR_CONFIG; + + static { + sinkConfig = new FeishuSinkConfig(); + SINK_CONNECTOR_CONFIG = new SinkConnectorConfig(); + SINK_CONNECTOR_CONFIG.setConnectorName("FeishuSinkConnector"); + SINK_CONNECTOR_CONFIG.setAppId("xxx"); + SINK_CONNECTOR_CONFIG.setAppSecret("xxx"); + SINK_CONNECTOR_CONFIG.setReceiveId("xxx"); + SINK_CONNECTOR_CONFIG.setReceiveIdType("open_id"); + sinkConfig.setConnectorConfig(SINK_CONNECTOR_CONFIG); + } + + @Spy + private FeishuSinkConnector feishuSinkConnector; Review Comment: The `@Spy` annotation is not very meaningful here, because you are not mocking the object at all. You are basically constructing it manually. 这个`@Spy`注解意义不大,因为您没有对该对象进行任何模拟,基本上是手动构建的。 ########## eventmesh-connectors/eventmesh-connector-feishu/src/test/java/org/apache/eventmesh/connector/s3/source/FeishuSinkConnectorTest.java: ########## @@ -0,0 +1,99 @@ +/* + * 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.eventmesh.connector.s3.source; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.apache.eventmesh.connector.feishu.sink.config.FeishuSinkConfig; +import org.apache.eventmesh.connector.feishu.sink.config.SinkConnectorConfig; +import org.apache.eventmesh.connector.feishu.sink.connector.FeishuSinkConnector; +import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.platform.commons.support.HierarchyTraversalMode; +import org.junit.platform.commons.support.ReflectionSupport; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.lark.oapi.Client; +import com.lark.oapi.core.response.RawResponse; + +@ExtendWith(MockitoExtension.class) +public class FeishuSinkConnectorTest { + + private static final FeishuSinkConfig sinkConfig; + + private static final SinkConnectorConfig SINK_CONNECTOR_CONFIG; + + static { + sinkConfig = new FeishuSinkConfig(); + SINK_CONNECTOR_CONFIG = new SinkConnectorConfig(); + SINK_CONNECTOR_CONFIG.setConnectorName("FeishuSinkConnector"); + SINK_CONNECTOR_CONFIG.setAppId("xxx"); + SINK_CONNECTOR_CONFIG.setAppSecret("xxx"); + SINK_CONNECTOR_CONFIG.setReceiveId("xxx"); + SINK_CONNECTOR_CONFIG.setReceiveIdType("open_id"); + sinkConfig.setConnectorConfig(SINK_CONNECTOR_CONFIG); + } + + @Spy + private FeishuSinkConnector feishuSinkConnector; Review Comment: The `@Spy` annotation is not very meaningful here, because you are not mocking the object at all. You are basically constructing it manually. 这个`@Spy`注解意义不大,因为您没有对该对象进行任何模拟,基本上是手动构建的。 -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
