コード例 #1
0
  @Test
  public void testDeleteByCustomerId() throws Exception {
    int id = 34;
    SavedReviewerSearchDAO dao =
        EasyMock.createMockBuilder(SavedReviewerSearchDAO.class)
            .withConstructor()
            .addMockedMethod("deleteByCustomerId", Connection.class, Integer.TYPE)
            .createStrictMock();
    ITransactionManager txMgr = EasyMock.createStrictMock(ITransactionManager.class);
    dao.setTransactionManager(txMgr);
    Connection mockConn = EasyMock.createStrictMock(Connection.class);
    EasyMock.expect(dao.deleteByCustomerId(mockConn, id)).andReturn(34);

    MockExecutionWithThrow.<Boolean>execute(txMgr, mockConn);
    EasyMock.replay(txMgr, mockConn, dao);
    assertEquals("Wrong delete result.", 34, dao.deleteByCustomerId(id));
    EasyMock.verify(txMgr, mockConn, dao);
  }
コード例 #2
0
  @Test
  public void testDeleteByCustomerIdWithConnection() 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_CUSTOMER_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.deleteByCustomerId(connection, id));
    EasyMock.verify(preparedStatement, connection);
  }