从文档中:
为了指定
Throwable要抛出的异常(更确切地说:s),由expectLastCall()和返回的对象expect(Tvalue)提供方法andThrow(Throwablethrowable)。在调用要为其指定模拟对象的Mock对象之后,必须以记录状态调用该方法Throwable。可以从每个方法中抛出未经检查的异常(即
RuntimeException,Error以及它们的所有子类)。检查异常只能从实际抛出异常的方法中抛出。
例如:
expectLastCall().andThrow(new HibernateException("Something terrible happened"));expect(query.list()).andThrow( new HibernateException("Something terrible happened"));


