【发布时间】:2022-01-13 10:20:06
【问题描述】:
考虑:
return attachmentList.stream().map(attachment -> {
AttachmentBO attachmentBO = new AttachmentBO();
attachmentBO.setId(attachment.getId());
attachmentBO.setTitle(attachment.getName());
attachmentBO.setType(attachment.getValue().get("type").toString());
attachmentBO.setCreatorId(attachment.getAuditUserId());
String[] filteredPermissionsForNote = this.filterPermissionCommand.filterPermissions(answer.getTopicId(), attachment.getAuditUserId(), topicDetails.getPermissions(), topicDetails.getEffectiveRoles(), true);
attachmentBO.setPermissions(filteredPermissionsForNote);
if (attachmentBO.getType().equalsIgnoreCase("URL")) {
attachmentBO.setUrl(String.valueOf(attachment.getMediaInfo().get("url")));
} else if (attachmentBO.getType().equalsIgnoreCase("FILE")) {
attachmentBO.setSize((Double) attachment.getValue().get("size"));
}
return attachmentBO;
}).collect(Collectors.toList());
我已经使用 Mockito 模拟了附件列表,所以我得到了附件列表。但是我应该如何模拟剩下的代码呢?我什至嘲笑过过滤器权限。
【问题讨论】:
-
1) 你想测试什么? 2)也许只是使用预定义的列表而不是模拟它?
-
我正在测试我的控制器,所以我在我的控制器中注入了这个服务,上面的代码是我的服务层的。
-
您到底想测试什么:该服务的方法是用正确的参数调用的,还是您正在编写集成测试?
-
(Stack Overflow 上的语法高亮显示:为什么变量“
attachmentBO”在声明中的颜色与其使用位置不同?为什么(数组)变量“@”不同987654324@" in this question?)
标签: java spring-boot mockito