@Test(expected = NoSuchObjectInDB.class) public void getDocumentsByAuthorNo1() throws Exception { when(rs.next()).thenReturn(false); DocumentDAO dao = DAOFactory.getInstance().getDocumentDAO(conn); // when dao.getDocumentID("", 0); // then verify(conn).prepareStatement(QueriesSQL.SELECT_ID_FROM_DOCUMENT); verify(ps).setString(1, anyString()); verify(ps).setLong(2, anyLong()); verify(ps).executeQuery(); verify(rs).next(); verify(rs).getLong("id"); verify(ps).close(); }
@Test public void getDocumentsByAuthorSuccessful() throws Exception { when(rs.next()).thenReturn(true); when(rs.getLong("id")).thenReturn((long) 1); DocumentDAO dao = DAOFactory.getInstance().getDocumentDAO(conn); // when dao.getDocumentID("", 0); // then verify(conn).prepareStatement(QueriesSQL.SELECT_ID_FROM_DOCUMENT); verify(ps).setString(1, eq(anyString())); verify(ps).setLong(2, eq(anyLong())); verify(ps).executeQuery(); verify(rs).next(); verify(rs).getLong("id"); verify(ps).close(); }