简体   繁体   中英

java.lang.AssertionError: Expectation failure on Verify: jUnit4 TestCase

The following code returns Expectation failure of verification: What's up with the code? can someone help me what am I missing there?

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);
    }

}

Wondering why it is throwing an error on verify?

The call to replay should be followed by a call the the expected methods, in your case, you should call the mockJdbcTemplate.queryForObject(); method with appropriate parameters; before calling the verfiy method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM