wizardzhang commented on code in PR #4603:
URL: https://github.com/apache/eventmesh/pull/4603#discussion_r1416836217
##########
eventmesh-connectors/eventmesh-connector-wechat/src/test/java/org/apache/eventmesh/connector/wechat/sink/connector/WeChatSinkConnectorTest.java:
##########
@@ -95,31 +112,44 @@ public void setUp() throws Exception {
Mockito.doReturn(sendMessageRequestCall).when(okHttpClient).newCall(Mockito.argThat(sendMessageMatcher));
Mockito.doReturn(sendMessageResponse).when(sendMessageRequestCall).execute();
- weChatSinkConnector = new WeChatSinkConnector();
- WeChatSinkConfig weChatSinkConfig = (WeChatSinkConfig)
ConfigUtil.parse(weChatSinkConnector.configClass());
- weChatSinkConnector.init(weChatSinkConfig);
- Field clientField =
ReflectionSupport.findFields(weChatSinkConnector.getClass(),
- (f) -> f.getName().equals("okHttpClient"),
- HierarchyTraversalMode.BOTTOM_UP).get(0);
- clientField.setAccessible(true);
- clientField.set(weChatSinkConnector, okHttpClient);
- weChatSinkConnector.start();
+ List<ConnectRecord> records = new ArrayList<>();
+ RecordPartition partition = new RecordPartition();
+ RecordOffset offset = new RecordOffset();
+ ConnectRecord connectRecord = new ConnectRecord(partition, offset,
+ System.currentTimeMillis(), "Hello,
EventMesh!".getBytes(StandardCharsets.UTF_8));
+ records.add(connectRecord);
+
+ weChatSinkConnector.put(records);
+ verify(okHttpClient, times(2)).newCall(any(Request.class));
+
+
WeChatSinkConnector.ACCESS_TOKEN_CACHE.invalidate(WeChatSinkConnector.ACCESS_TOKEN_CACHE_KEY);
Review Comment:
first u should use app id and app secret to get a token, then use token to
send message. so i mock a get token response and store the token in cache, in
testSendMessageToWeChat() method, the mock token repsone is used, and then in
testSendMessageToWeChatAbnormally() method, the mock token repsone will not be
used, because token has been stored in cache and then will throw a
org.mockito.exceptions.misusing.UnnecessaryStubbingException. the test result
like this

testSendMessageToWeChat() passed, testSendMessageToWeChatAbnormally() failed
--
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]