Ejemplo n.º 1
0
  @Test
  public void findCustomerWithCar() {
    assertTrue(car1.getAvailable());
    assertTrue(car2.getAvailable());
    assertTrue(car3.getAvailable());

    manager.rentCarToCustomer(
        car1, customer1, Date.valueOf("2012-03-21"), Date.valueOf("2012-03-31"));

    assertEquals(customer1, manager.findCustomerWithCar(car1));
    assertCustomerDeepEquals(customer1, manager.findCustomerWithCar(car1));
    assertTrue(car2.getAvailable());
    assertTrue(car3.getAvailable());

    try {
      manager.findCustomerWithCar(null);
      fail();
    } catch (IllegalArgumentException e) {
    }
    try {
      manager.findCustomerWithCar(carWithoutID);
      fail();
    } catch (IllegalArgumentException e) {
    }
  }
Ejemplo n.º 2
0
  @Test
  public void getCarFromCustomer() {
    assertTrue(car1.getAvailable());
    assertTrue(car2.getAvailable());
    assertTrue(car3.getAvailable());

    manager.rentCarToCustomer(
        car1, customer1, Date.valueOf("2012-03-21"), Date.valueOf("2012-03-31"));
    manager.rentCarToCustomer(
        car2, customer1, Date.valueOf("2012-03-25"), Date.valueOf("2012-04-02"));
    manager.rentCarToCustomer(
        car3, customer2, Date.valueOf("2012-03-15"), Date.valueOf("2012-03-27"));

    assertEquals(customer1, manager.findCustomerWithCar(car1));
    assertCustomerDeepEquals(customer1, manager.findCustomerWithCar(car1));
    assertEquals(customer1, manager.findCustomerWithCar(car2));
    assertCustomerDeepEquals(customer1, manager.findCustomerWithCar(car2));
    assertEquals(customer2, manager.findCustomerWithCar(car3));
    assertCustomerDeepEquals(customer2, manager.findCustomerWithCar(car3));

    manager.getCarFromCustomer(car3, customer2);

    List<Car> carsRetnedtoCustomer1 = Arrays.asList(car1, car2);

    assertCarDeepEquals(carsRetnedtoCustomer1, manager.getAllCustomerCars(customer1));
    assertFalse(customer2.getActive());
    assertFalse(customer3.getActive());

    assertEquals(customer1, manager.findCustomerWithCar(car1));
    assertCustomerDeepEquals(customer1, manager.findCustomerWithCar(car1));
    assertEquals(customer1, manager.findCustomerWithCar(car2));
    assertCustomerDeepEquals(customer1, manager.findCustomerWithCar(car2));
    assertTrue(car3.getAvailable());

    try {
      manager.getCarFromCustomer(car3, customer1);
      fail();
    } catch (TransactionException e) {
    }

    try {
      manager.getCarFromCustomer(car3, customer2);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      manager.getCarFromCustomer(null, customer1);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      manager.getCarFromCustomer(carWithoutID, customer1);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      manager.getCarFromCustomer(carNotInDB, customer1);
      fail();
    } catch (TransactionException e) {
    }

    try {
      manager.getCarFromCustomer(car1, null);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      manager.getCarFromCustomer(car1, customerWithoutID);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      manager.getCarFromCustomer(car1, customerNotInDB);
      fail();
    } catch (TransactionException e) {
    }

    // Check that previous tests didn't affect data in database
    assertCarDeepEquals(carsRetnedtoCustomer1, manager.getAllCustomerCars(customer1));
    assertFalse(customer2.getActive());
    assertFalse(customer3.getActive());

    assertEquals(customer1, manager.findCustomerWithCar(car1));
    assertCustomerDeepEquals(customer1, manager.findCustomerWithCar(car1));
    assertEquals(customer1, manager.findCustomerWithCar(car2));
    assertCustomerDeepEquals(customer1, manager.findCustomerWithCar(car2));
    assertTrue(car3.getAvailable());
  }