コード例 #1
0
  @Test
  public void billingSystemCallsAllTheComponents() {
    final List<Customer> fakeCustomers = new ArrayList<Customer>();
    fakeCustomers.add(FIRST_CUSTOMER);

    final List<Call> fakeCalls = new ArrayList<Call>();
    final Call fakeCall =
        new Call(new CallEvent(null, null, null), new CallEvent(null, null, null));
    fakeCalls.add(fakeCall);

    context.checking(
        new Expectations() {
          {
            oneOf(customerDB).getCustomers();
            will(returnValue(fakeCustomers));

            oneOf(callLog).getCalls(FIRST_CUSTOMER);
            will(returnValue(fakeCalls));

            allowing(billGenerator)
                .generateBill(
                    with(any(Customer.class)), with(any(List.class)), with(any(String.class)));

            oneOf(tariffLibrary).tarriffFor(FIRST_CUSTOMER);
            will(returnValue(Tariff.Business));

            oneOf(strategy).getCost(Tariff.Business, fakeCall);
            will(returnValue(BigDecimal.ZERO));
          }
        });

    billingSystem.createCustomerBills();
  }
コード例 #2
0
  @Test
  public void callEndedCallsCallLog() {
    context.checking(
        new Expectations() {
          {
            oneOf(callLog).callCompleted(FIRST_CUSTOMER_NUMBER, OTHER_CUSTOMER_NUMBER);
          }
        });

    billingSystem.callCompleted(FIRST_CUSTOMER_NUMBER, OTHER_CUSTOMER_NUMBER);
  }
コード例 #3
0
  @Test
  public void noBillGeneratedForNoCustomers() {
    final List<Customer> fakeCustomers = new ArrayList<Customer>();

    context.checking(
        new Expectations() {
          {
            oneOf(customerDB).getCustomers();
            will(returnValue(fakeCustomers));

            never(billGenerator)
                .generateBill(
                    with(any(Customer.class)), with(any(List.class)), with(any(String.class)));
          }
        });

    billingSystem.createCustomerBills();
  }
コード例 #4
0
  @Test
  public void oneCustomerGeneratesOneBill() {
    final List<Customer> fakeCustomers = new ArrayList<Customer>();
    fakeCustomers.add(FIRST_CUSTOMER);

    context.checking(
        new Expectations() {
          {
            oneOf(customerDB).getCustomers();
            will(returnValue(fakeCustomers));

            oneOf(callLog).getCalls(FIRST_CUSTOMER);

            oneOf(billGenerator)
                .generateBill(with(FIRST_CUSTOMER), with(any(List.class)), with(any(String.class)));
          }
        });

    billingSystem.createCustomerBills();
  }
コード例 #5
0
  @Test
  public void threeCustomersGenerateThreeBills() {
    final List<Customer> fakeCustomers = new ArrayList<Customer>();
    fakeCustomers.add(FIRST_CUSTOMER);
    fakeCustomers.add(SECOND_CUSTOMER);
    fakeCustomers.add(OTHER_CUSTOMER);

    context.checking(
        new Expectations() {
          {
            oneOf(customerDB).getCustomers();
            will(returnValue(fakeCustomers));

            allowing(callLog).getCalls(with(any(Customer.class)));

            exactly(3)
                .of(billGenerator)
                .generateBill(
                    with(any(Customer.class)), with(any(List.class)), with(any(String.class)));
          }
        });

    billingSystem.createCustomerBills();
  }