给出AssertionError的JdbcTemplate更新查询?

时间:2015-05-12 05:12:55

标签: java powermock

我正在为DAO类编写测试用例,我正在使用JDBC模板和Power mock .IN dao方法我调用了两次jdbctemplate方法然后我收到了一些错误。 请在下面找到代码

JdbcTemplate jt = createStrictMock(JdbcTemplate.class);
String sql = "select SQN_ALERTS_CCH_JOB_ID.NEXTVAL from DUAL";
String sqlInsert = "insert into C_ALERTS_CCH_JOB (MSG_ID, MESSAGE, ACTION, ACTION_TM, ERR_DESC, SEQ_NO)"
                        + " values (?,?,?,?,?,?)";
EasyMock.expect(jt.queryForLong(sql)).andReturn(529340l).times(1);
EasyMock.expect(jt.update(sqlInsert, parameters)).andReturn(1).times(1);
PowerMock.replay(jt);
PowerMock.replayAll();
Object[] parameters = new Object[6];
parameters[0] = jt.queryForLong(sql);
jt.update(sql, parameters);

然后我得到以下错误

    java.lang.AssertionError: 
Unexpected method call JdbcTemplate.update("insert into C_ALERTS_CCH_JOB (MSG_ID, MESSAGE, ACTION, ACTION_TM,
ERR_DESC, SEQ_NO) values (?,?,?,?,?,?)", [null, null, null, 2015-05-11 19:49:29.585, null, 529340]):
JdbcTemplate.queryForLong("select SQN_ALERTS_CCH_JOB_ID.NEXTVAL from DUAL"): expected: 1, actual: 1
JdbcTemplate.update("insert into C_ALERTS_CCH_JOB (MSG_ID, MESSAGE, ACTION, ACTION_TM, ERR_DESC, SEQ_NO) values (?,?,?,?,?,?)", [null, null, null, 2015-05-11 19:49:29.585, null, 529340]): expected: 1, actual: 0
at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:44)
at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:94)
at org.easymock.internal.ClassProxyFactory$MockMethodInterceptor.intercept(ClassProxyFactory.java:97)
at org.springframework.jdbc.core.JdbcTemplate$$EnhancerByCGLIB$$6e3c18ec.update(<generated>)

为什么?

1 个答案:

答案 0 :(得分:0)

你的第二个模拟在期望1时返回0 ...因此断言错误