我想模拟构建器模式中使用的 DAO 接口,如下所示。但是,当我在下面运行测试时,它通过表明我的模拟对象永远不会被调用。我究竟做错了什么?
public class DBContent {
...
public static class Builder {
DAO dao = new DAO();
...
public Builder callInsert() {
...
long latest = dao.insert();
...
}
}
...
}
@RunWith(MockitoJUnitRunner.class)
public class DBContentTest {
@Mock
DAO dao;
@Test
public void test() {
when(dao.insert()).thenReturn(1111L);
DBContent db = DBContent.db()
.callInsert()
.callInsert()
.callInsert()
.build();
verifyZeroInteractions(dao);
}
}