这是我在运行我编写的JUnit测试时删除队列中第一个元素的代码,它在E上提供了nullPointerException。retVal = head.getElement(); 这是构造函数
/** Create a new (empty) instance of this class. */
public ProperQueue() {
head = null;
tail = null;
size = 0;
}
public E remove() {
if (head == null) {
tail = null;
}
E retVal = head.getElement();
if( head.getNext()==null) {
head=null;
tail=null;
size-=1;
return retVal;
}
head = head.getNext();
return retVal;
}
这是我的Junit测试
@Test
public void testRemove() {
ProperQueue testRemove = new ProperQueue();
testRemove.add(7);
testRemove.add(6);
testRemove.remove();
assertEquals(7 ,testRemove.remove());
}