以下代码返回验证的期望失败: 代码怎么了? 有人可以帮助我,我在那里错过了什么?
public class DAOImplTest {
private DAOImpl dao;
private JdbcTemplate mockJdbcTemplate;
@Before
public void before() {
dao = new DAOImpl();
mockJdbcTemplate = createMock(JdbcTemplate.class);
dao.setJdbcTempate(mockJdbcTemplate);
}
@After
public void after() {
dao = null;
}
@SuppressWarnings("unchecked")
@Test
public void methReturnsWhenOrgIdsAndGuidFound(){
final String expectedOrgIds = "d514d112566e";
final String expectedGUID = "one";
expect(mockJdbcTemplate.queryForObject(eq(SSOSASguidDAOImpl.GET_GUID_FOR_ORG_IDS),
(RowMapper<String>) anyObject(), eq(expectedGUID), eq(expectedOrgIds))).andReturn(expectedOrgIds);
replay(mockJdbcTemplate);
// verify(mockJdbcTemplate, expectedOrgIds);
verify(mockJdbcTemplate);
assertNotNull(expectedOrgIds);
assertEquals("d514d112566e", expectedOrgIds);
}
}
想知道为什么它会在验证时抛出错误?
答案 0 :(得分:1)
对replay
的调用之后应该调用预期的方法,在您的情况下,您应该使用适当的参数调用mockJdbcTemplate.queryForObject();
方法;在调用verfiy
方法之前。