JMockitでDAOをモックしようとしています:
public interface MyDao {
Details getDetailsById(int id);
}
このテストクラスでは:
public class TestClass {
@Test
public void testStuff(final MyDao dao) throws Exception
{
new Expectations()
{
{
// when we try to get the message details, return our sample
// details
dao.getDetailsById((Integer) any); ***THROWS AN NPE
result = sampleDetails;
}
};
ClassUsingDao daoUser = new ClassUsingDao(dao);
// calls dao.getDetailsById()
daoUser.doStuff();
}
Expectations ブロックで dao オブジェクトが使用されると、NPE がスローされます。dao の宣言を @Mocked アノテーションが付けられたメンバー変数に移動しようとしましたが、同じことが起こります。また、MyDao の具体的な実装を使用してみましたが、同じことが起こります。