private TestScenario buildTestScenarioPrePaidPriceAndQuantityIncreaseForUnbIlledPeriod() {
    TestScenario scenario = prePaid();
    TestOrderChangeBuilder change;
    Expectation expected;

    change = scenario.getChangeBuilder().applicationDate("01/01/2015").quantity(10.0).price(5.0);
    scenario.addChange(change, AsDate(2015, 1, 1));
    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 2, 1))
            .nextInvoiceDate(AsDate(2015, 2, 1))
            .invoiceTotal(new BigDecimal("50.00"));
    scenario.addExpecation(expected, AsDate(2015, 1, 1));

    change = scenario.getChangeBuilder().applicationDate("02/20/2015").quantity(2.0).price(6.0);
    scenario.addChange(change, AsDate(2015, 2, 1));

    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 3, 1))
            .nextInvoiceDate(AsDate(2015, 3, 1))
            .invoiceTotal(new BigDecimal("57.07" /* "56.27" */));
    scenario.addExpecation(expected, AsDate(2015, 2, 1));

    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 4, 1))
            .nextInvoiceDate(AsDate(2015, 4, 1))
            .invoiceTotal(new BigDecimal("72.00"));
    scenario.addExpecation(expected, AsDate(2015, 3, 1));

    return scenario;
  }
 @Test(enabled = true)
 public void test001BIllng() {
   logger.info("#test001BIllng");
   for (Date date : billingDates) {
     for (TestScenario scenario : scenarios) {
       scenario.applyChanges(date);
     }
     billingProcessBuilder.triggerForDate(date);
     for (TestScenario scenario : scenarios) {
       scenario.verify(date);
     }
     for (String error : getErrors()) {
       logger.info(error);
     }
     assertEquals(S("Tests failed on billing run for date {}", date), 0, getErrors().size());
   }
 }
  private TestScenario buildTestScenarioPrePaidBackDatedQuantityIncreaseForBIlledPeriod() {
    TestScenario scenario = prePaidNonProRate();
    TestOrderChangeBuilder change;
    Expectation expected;

    change = scenario.getChangeBuilder().applicationDate("01/01/2015").quantity(2.0).price(5.0);
    scenario.addChange(change, AsDate(2015, 1, 1));
    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 2, 1))
            .nextInvoiceDate(AsDate(2015, 2, 1))
            .invoiceTotal(new BigDecimal("10.00"));
    scenario.addExpecation(expected, AsDate(2015, 1, 1));

    change = scenario.getChangeBuilder().applicationDate("01/15/2015").quantity(1.0).price(5.0);
    scenario.addChange(change, AsDate(2015, 2, 1));

    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 3, 1))
            .nextInvoiceDate(AsDate(2015, 3, 1))
            .invoiceTotal(new BigDecimal("20.00"));
    scenario.addExpecation(expected, AsDate(2015, 2, 1));

    return scenario;
  }
  private TestScenario buildTestScenarioPriceAndQuantityIncreaseForBIlledPeriod() {
    TestScenario scenario = postPaid();
    TestOrderChangeBuilder change;
    Expectation expected;

    change = scenario.getChangeBuilder().applicationDate("01/05/2015").quantity(10.0).price(5.0);
    scenario.addChange(change, AsDate(2015, 1, 1));
    expected =
        new Expectation().nextBillableDay(AsDate(2015, 1, 1)).nextInvoiceDate(AsDate(2015, 2, 1));
    scenario.addExpecation(expected, AsDate(2015, 1, 1));

    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 2, 1))
            .nextInvoiceDate(AsDate(2015, 3, 1))
            .invoiceTotal(new BigDecimal("43.55" /* "41.93" */));
    scenario.addExpecation(expected, AsDate(2015, 2, 1));

    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 3, 1))
            .nextInvoiceDate(AsDate(2015, 4, 1))
            .invoiceTotal(new BigDecimal("50.00"));
    scenario.addExpecation(expected, AsDate(2015, 3, 1));

    change = scenario.getChangeBuilder().applicationDate("01/15/2015").quantity(2.0).price(6.0);
    scenario.addChange(change, AsDate(2015, 4, 1));

    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 4, 1))
            .nextInvoiceDate(AsDate(2015, 5, 1))
            .invoiceTotal(new BigDecimal("106.06" /* "105.35" */));
    scenario.addExpecation(expected, AsDate(2015, 4, 1));

    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 5, 1))
            .nextInvoiceDate(AsDate(2015, 6, 1))
            .invoiceTotal(new BigDecimal("72.00"));
    scenario.addExpecation(expected, AsDate(2015, 5, 1));

    return scenario;
  }
  private TestScenario buildTestScenarioQuantityDecreaseForBIlledPeriod() {
    TestScenario scenario = postPaid();
    TestOrderChangeBuilder change;
    Expectation expected;

    change = scenario.getChangeBuilder().applicationDate("01/01/2015").quantity(10.0).price(5.0);
    scenario.addChange(change, AsDate(2015, 1, 1));
    expected =
        new Expectation().nextBillableDay(AsDate(2015, 1, 1)).nextInvoiceDate(AsDate(2015, 2, 1));
    scenario.addExpecation(expected, AsDate(2015, 1, 1));

    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 2, 1))
            .nextInvoiceDate(AsDate(2015, 3, 1))
            .invoiceTotal(new BigDecimal("50.00"));
    scenario.addExpecation(expected, AsDate(2015, 2, 1));

    change = scenario.getChangeBuilder().applicationDate("01/15/2015").quantity(-2.0).price(5.0);
    scenario.addChange(change, AsDate(2015, 3, 1));

    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 3, 1))
            .nextInvoiceDate(AsDate(2015, 4, 1))
            .invoiceTotal(new BigDecimal("34.52" /* "34.84" */));
    scenario.addExpecation(expected, AsDate(2015, 3, 1));

    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 4, 1))
            .nextInvoiceDate(AsDate(2015, 5, 1))
            .invoiceTotal(new BigDecimal("40.00"));
    scenario.addExpecation(expected, AsDate(2015, 4, 1));

    return scenario;
  }
  private TestScenario buildTestScenarioPriceIncreaseForUnbIlledPeriod() {
    TestScenario scenario = postPaid();
    TestOrderChangeBuilder change;
    Expectation expected;

    change = scenario.getChangeBuilder().applicationDate("01/05/2015").quantity(10.0).price(5.0);
    scenario.addChange(change, AsDate(2015, 1, 1));
    expected =
        new Expectation().nextBillableDay(AsDate(2015, 1, 1)).nextInvoiceDate(AsDate(2015, 2, 1));
    scenario.addExpecation(expected, AsDate(2015, 1, 1));

    change = scenario.getChangeBuilder().applicationDate("01/25/2015").quantity(0.0).price(7.0);
    scenario.addChange(change, AsDate(2015, 2, 1));
    change = scenario.getChangeBuilder().applicationDate("02/15/2015").quantity(0.0).price(9.0);
    scenario.addChange(change, AsDate(2015, 2, 1));

    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 2, 1))
            .nextInvoiceDate(AsDate(2015, 3, 1))
            .invoiceTotal(new BigDecimal("48.06" /* "45.80" */));
    scenario.addExpecation(expected, AsDate(2015, 2, 1));

    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 3, 1))
            .nextInvoiceDate(AsDate(2015, 4, 1))
            .invoiceTotal(new BigDecimal("80.00" /* "79.28" */));
    scenario.addExpecation(expected, AsDate(2015, 3, 1));

    expected =
        new Expectation()
            .nextBillableDay(AsDate(2015, 4, 1))
            .nextInvoiceDate(AsDate(2015, 5, 1))
            .invoiceTotal(new BigDecimal("90.00"));
    scenario.addExpecation(expected, AsDate(2015, 4, 1));

    return scenario;
  }
 @Override
 protected void afterTestClass() throws Exception {
   for (TestScenario scenario : scenarios) {
     scenario.tearDown();
   }
 }