【发布时间】:2018-10-13 17:03:45
【问题描述】:
有在数组中插入元素的方法。
public boolean insertElementToSlot(Element element, int index) {
checkArray(index);
try {
if (element != null && mas[index] == null) {
mas[index] = element;
return true;
} else {
throw new ElementValidationException("Element.insertElementToSlot", device);
}
} catch (ElementValidationException d) {
logger.log(Level.SEVERE, ""+d);
}
return false;
}
并拥有带有方法的异常类:
public ElementValidationException(String operation, Element element) {
super("Element is not valid for operation" + checkOperation(operation));
this.element = element;
}
在测试方法insertElementToSlot时,我有错误
java.lang.AssertionError: Expected exception: com.inventory.exception.ElementValidationException
为什么会出现错误以及如何解决?
【问题讨论】:
-
@Test中有expected子句吗?如果是,如果您不希望测试抛出异常,请将其删除。