예제 #1
0
  @Test
  public void testDeleteByUserId() throws Exception {
    int id = 34;
    SavedReviewerSearchDAO dao =
        EasyMock.createMockBuilder(SavedReviewerSearchDAO.class)
            .withConstructor()
            .addMockedMethod("deleteByUserId", Connection.class, Integer.TYPE)
            .createStrictMock();
    ITransactionManager txMgr = EasyMock.createStrictMock(ITransactionManager.class);
    dao.setTransactionManager(txMgr);
    Connection mockConn = EasyMock.createStrictMock(Connection.class);
    EasyMock.expect(dao.deleteByUserId(mockConn, id)).andReturn(34);

    MockExecutionWithThrow.<Boolean>execute(txMgr, mockConn);
    EasyMock.replay(txMgr, mockConn, dao);
    assertEquals("Wrong delete result.", 34, dao.deleteByUserId(id));
    EasyMock.verify(txMgr, mockConn, dao);
  }
예제 #2
0
  @Test
  public void testDeleteByUserIdWithConnection() throws Exception {
    PreparedStatement preparedStatement = EasyMock.createStrictMock(PreparedStatement.class);
    Connection connection = EasyMock.createStrictMock(Connection.class);
    int id = 34;
    int count = 342;
    SavedReviewerSearchDAO dao = new SavedReviewerSearchDAO();

    EasyMock.expect(connection.prepareStatement(SavedReviewerSearchDAO.DELETE_BY_USER_SQL))
        .andReturn(preparedStatement);
    preparedStatement.setInt(1, id);
    EasyMock.expectLastCall();
    EasyMock.expect(preparedStatement.executeUpdate()).andReturn(count);
    preparedStatement.close();
    EasyMock.expectLastCall();

    EasyMock.replay(preparedStatement, connection);
    assertEquals(
        "Should return count when item is deleted.", count, dao.deleteByUserId(connection, id));
    EasyMock.verify(preparedStatement, connection);
  }