コード例 #1
0
ファイル: CustomerDAOTest.java プロジェクト: piyush76/EMS
  @SuppressWarnings("unchecked")
  @Test
  public void testFindCustomersWithConnection() throws Exception {
    CustomerDAO dao =
        EasyMock.createMockBuilder(CustomerDAO.class)
            .addMockedMethod("readNextCustomer")
            .addMockedMethod("getCustomerQuery")
            .createStrictMock();
    ResultSet resultSet = EasyMock.createStrictMock(ResultSet.class);
    Connection connection = EasyMock.createStrictMock(Connection.class);
    Statement statement = EasyMock.createStrictMock(Statement.class);
    List<SearchConstraint> constraints = new LinkedList<SearchConstraint>();

    EasyMock.expect(dao.getCustomerQuery(constraints)).andReturn("aQuery");
    EasyMock.expect(connection.createStatement()).andReturn(statement);
    EasyMock.expect(statement.executeQuery("aQuery")).andReturn(resultSet);

    EasyMock.expect(resultSet.next()).andReturn(true);
    EasyMock.expect(dao.readNextCustomer(EasyMock.eq(resultSet), EasyMock.isA(List.class)))
        .andReturn(true);
    EasyMock.expect(dao.readNextCustomer(EasyMock.eq(resultSet), EasyMock.isA(List.class)))
        .andReturn(true);
    EasyMock.expect(dao.readNextCustomer(EasyMock.eq(resultSet), EasyMock.isA(List.class)))
        .andReturn(false);
    resultSet.close();
    EasyMock.expectLastCall();
    statement.close();
  }
コード例 #2
0
ファイル: CustomerDAOTest.java プロジェクト: piyush76/EMS
  @Test
  public void testGetCustomerQuery() throws Exception {
    List<SearchConstraint> constraintList = new LinkedList<SearchConstraint>();

    CustomerDAO dao =
        new CustomerDAO() {
          @Override
          protected void appendConstraints(
              List<SearchConstraint> constraints, StringBuilder whereClause) {
            whereClause.append("hello world");
          }
        };

    String expected =
        CustomerDAO.SQL_CUSTOMER_QUERY + "hello world" + CustomerDAO.SQL_CUSTOMER_QUERY_ORDER_BY;
    assertEquals(
        "Wrong query with no constraints.", expected, dao.getCustomerQuery(constraintList));
  }