简体   繁体   English

Junit覆盖Objects.notnull

[英]Junit to cover Objects.notnull

public List<ClassRoomListAdapterModel> getRoomListItems() {
final List<ClassRoomListAdapterModel> classRoomListItemsList = new ArrayList<>();
if (Objects.nonNull (classRoomListItemsList)) {
classRoomListItemsList.addAll
(classRoomListItemsList);
}
return classRoomListItemsList;
}

Stuck with junit coverage to cover if conditions Objects.nonNull卡在 junit 覆盖范围以覆盖 if 条件 Objects.nonNull

There is no way classRoomListItemsList can be null, since it is created right beforehand. classRoomListItemsList 不可能是 null,因为它是预先创建的。 So to me it seems you should remove the dead code path (=> remove the null check).所以对我来说,您似乎应该删除死代码路径(=> 删除 null 检查)。

Also, you do realize all this method does is produce an empty ArrayList?另外,您是否意识到所有这些方法都会产生一个空的 ArrayList?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM