我想知道如何测试这样的方法:
public PublishResponse broadcast(String eventJson, Class<? extends BaseEvent> type) {
//Build Sns client.
AwsCredentials awsCredentials = AwsBasicCredentials
.create(snsConfiguration.getAwsAccessKeyId(), snsConfiguration.getAwsSecretAccessKey());
StaticCredentialsProvider credentialsProvider = StaticCredentialsProvider.create(awsCredentials);
SnsClient snsClient = SnsClient.builder().credentialsProvider(credentialsProvider).build();
//Prepare message attributes.
Map<String, MessageAttributeValue> messageAttributes = new HashMap<>();
MessageAttributeValue messageAttributeValue = MessageAttributeValue.builder().dataType("String").stringValue(type.getName())
.build();
messageAttributes.put("type", messageAttributeValue);
//Publish message with event json to Amazon SNS.
return snsClient.publish(PublishRequest.builder()
.message(eventJson)
.messageAttributes(messageAttributes)
.topicArn(snsConfiguration.getTopicARN())
.build());
}
这里的所有代码都依赖于 AWS SDK api。我知道我可以在这里嘲笑一下,但最后他的方法的职责是向 SNS 发送消息。如何为这样的事情编写联合测试?