【发布时间】:2015-11-25 21:47:45
【问题描述】:
我正在使用 jmock 运行一些测试。我想确保第三方库在 JDBC API 上正确调用以下序列:
context.checking(new Expectations() {{
oneOf(connection).prepareStatement("test");
oneOf(statement).setFetchSize(10);
oneOf(statement).executeQuery();
}});
connection 对象是这样创建的:
Mockery context = new Mockery();
connection = context.mock(Connection.class);
如何创建statement 对象?这些我都试过了,都不管用:
// This creates an independent PreparedStatement mock, not the one that will be returned
// by the Connection.prepareStatement call
PreparedStatement statement = context.mock(PreparedStatement.class);
// This doesn't return a mock object, which I can pass to the oneOf() method.
PreparedStatement statement = oneOf(connection).prepareStatement("test");
【问题讨论】: