本周在写单元测试的时候遇见了一个新的exception,在此记录一下。
单元测试中有一段代码是这样的:
logger.debug(“设置班级的学生”);
klass.setStudentList(Collections.singletonList(student1));
klassService.save(klass);
使用了singletonList来生成一个只有一个数据的链表,运行之后却报了exception
然后在看了这篇文章知道了是AbstractList的方法没有重写,运行这个时就直接抛出异常,作者使用的是没有重写add,看报错我这个应该是remove。
通过查看singletonList的源码果然是这样
没有重写remove
AbstractList的remove
发表回复