Beispiel #1
0
  @Test
  public void testGetCustomerWithConnection() throws Exception {
    CustomerDAO dao =
        EasyMock.createMockBuilder(CustomerDAO.class)
            .addMockedMethod("findCustomers", List.class, Connection.class)
            .createStrictMock();
    Customer customer = EasyMock.createStrictMock(Customer.class);
    Connection connection = EasyMock.createStrictMock(Connection.class);
    int custId = 322;
    List<ICustomer> customerList = new LinkedList<ICustomer>();
    customerList.add(customer);

    Capture<List<SearchConstraint>> capture = new Capture<List<SearchConstraint>>();
    EasyMock.expect(dao.findCustomers(EasyMock.capture(capture), EasyMock.eq(connection)))
        .andReturn(customerList);

    EasyMock.replay(dao, customer, connection);
    assertEquals("Wrong customer returned.", customer, dao.getCustomer(custId, connection));
    EasyMock.verify(dao, customer, connection);
    assertEquals("Wrong # of constraints.", 1, capture.getValue().size());
    SearchConstraint constraint = capture.getValue().get(0);
    assertEquals(
        "Wrong property in constraint.",
        ICustomerService.PROP_CUSTOMER_ID,
        constraint.getProperty());
    assertEquals(
        "Wrong operator in constraint.",
        SearchConstraintOperator.CONSTRAINT_EQUALS,
        constraint.getOperator());
    assertEquals("Wrong value in constraint.", custId, constraint.getValue());

    // no customers
    customerList.clear();
    EasyMock.reset(dao, customer, connection);
    capture = new Capture<List<SearchConstraint>>();
    EasyMock.expect(dao.findCustomers(EasyMock.capture(capture), EasyMock.eq(connection)))
        .andReturn(customerList);

    EasyMock.replay(dao, customer, connection);
    assertEquals(
        "Should not have found a customer returned.", null, dao.getCustomer(custId, connection));
    EasyMock.verify(dao, customer, connection);
  }
Beispiel #2
0
  @Test
  public void testGetCustomer() throws Exception {
    CustomerDAO dao =
        EasyMock.createMockBuilder(CustomerDAO.class)
            .addMockedMethod("getCustomer", Integer.TYPE, Connection.class)
            .createStrictMock();
    Customer customer = EasyMock.createStrictMock(Customer.class);
    ITransactionManager txMgr = EasyMock.createStrictMock(ITransactionManager.class);
    dao.setTransactionManager(txMgr);
    Connection connection = EasyMock.createStrictMock(Connection.class);
    int custId = 322;

    EasyMock.expect(dao.getCustomer(custId, connection)).andReturn(customer);
    CustomerTestUtils.MockJoinAndExecuteWithConnection.<Customer>execute(txMgr, connection);

    EasyMock.replay(dao, customer, txMgr, connection);
    assertEquals("Wrong customer returned.", customer, dao.getCustomer(custId));
    EasyMock.verify(dao, customer, txMgr, connection);
  }