检查空输入时获取空指针异常

时间:2018-12-19 15:31:35

标签: java unit-testing junit nullpointerexception

我有一个这样的课程。

public class Event {

public Event(String objectName, Integer moduleId, Integer actionId) {

  if (StringUtils.nullOrEmpty(objectName)) {
     throw new IllegalArgumentException("The objectName field is not supplied");
  }
  if (0 > moduleId || null == moduleId) {
     throw new IllegalArgumentException("The moduleId field is invalid");
  }
  if (0 > actionId || null == actionId) {
     throw new IllegalArgumentException("The actionId field is invalid");
  }

  objectName = objectName;
  moduleId = moduleId;
  actionId = actionId;
 }
}

当我测试moduleId和actionId的空值时,我得到了空指针异常。但这对于objectName很好。我做错什么了吗?

0 个答案:

没有答案