如果方法的返回值是 void, 不能用 when thenThrow 让该方法抛出异常
用 doThrow 让返回void的函数抛出异常
Mockito.doThrow(new RuntimeException("update error")).when(orderDao).update((Order)Mockito.any());
try {
orderDao.update(new Order());
}catch(Exception e) {
System.out.println("test3.erro1="+e);
}
mock中抛出受检查异常,要在测试方法上throws声明
any()返回 null, anyLong()返回0
thenThrow 之后 thenReturn 无效 , 继续抛异常