// subscription withdrawal without and with penalty
  @Test
  public void testEarlyWithdraw() {
    Instant exp = now.plus(TimeService.WEEK * 10);
    TariffSpecification tariffSpec =
        new TariffSpecification(broker, PowerType.CONSUMPTION)
            .withExpiration(exp)
            .withMinDuration(TimeService.WEEK * 4)
            .withSignupPayment(-33.2)
            .withEarlyWithdrawPayment(42.1)
            .addRate(new Rate().withValue(0.121));
    tariff = new Tariff(tariffSpec);
    tariff.init();
    TariffSubscription tsub = tariffMarketService.subscribeToTariff(tariff, customer, 5);

    // move time forward 2 weeks, withdraw 2 customers
    Instant wk2 = now.plus(TimeService.WEEK * 2);
    timeService.setCurrentTime(wk2);
    tsub.unsubscribe(2);
    verify(mockAccounting)
        .addTariffTransaction(
            TariffTransaction.Type.WITHDRAW, tariff, customer.getCustomerInfo(), 2, 0.0, 42.1 * 2);
    // def txs = TariffTransaction.findAllByPostedTime(wk2)
    // assertEquals("one transaction", 1, txs.size())
    // assertEquals("correct txType", TariffTransactionType.WITHDRAW, txs[0].txType)
    // assertEquals("correct charge", 42.1*2, txs[0].charge)
    assertEquals("three customers committed", 3, tsub.getCustomersCommitted());

    // move time forward another week, add 4 customers and drop 1
    Instant wk3 = now.plus(TimeService.WEEK * 2 + TimeService.HOUR * 6);
    timeService.setCurrentTime(wk3);
    TariffSubscription tsub1 = tariffMarketService.subscribeToTariff(tariff, customer, 4);
    assertEquals("same subscription", tsub, tsub1);
    tsub1.unsubscribe(1);
    // txs = TariffTransaction.findAllByPostedTime(wk3)
    // assertEquals("two transactions", 2, txs.size())
    // TariffTransaction ttx = TariffTransaction.findByPostedTimeAndTxType(timeService.currentTime,
    //
    // TariffTransactionType.SIGNUP)
    // assertNotNull("found signup tx", ttx)
    // assertEquals("correct charge", -33.2 * 4, ttx.charge)
    // ttx = TariffTransaction.findByPostedTimeAndTxType(timeService.currentTime,
    //                                                  TariffTransactionType.WITHDRAW)
    // assertNotNull("found withdraw tx", ttx)
    // assertEquals("correct charge", 42.1, ttx.charge)
    assertEquals("six customers committed", 6, tsub1.getCustomersCommitted());
  }
  // subscription with non-zero signup bonus
  @Test
  public void testSignupBonus() {
    Instant exp = now.plus(TimeService.WEEK * 10);
    TariffSpecification tariffSpec =
        new TariffSpecification(broker, PowerType.CONSUMPTION)
            .withExpiration(exp)
            .withMinDuration(TimeService.WEEK * 4)
            .withSignupPayment(-33.2)
            .addRate(new Rate().withValue(0.121));
    tariff = new Tariff(tariffSpec);
    tariff.init();

    TariffSubscription tsub = tariffMarketService.subscribeToTariff(tariff, customer, 5);
    assertNotNull("non-null subscription", tsub);
    assertEquals("five customers committed", 5, tsub.getCustomersCommitted());
    verify(mockAccounting)
        .addTariffTransaction(
            TariffTransaction.Type.SIGNUP, tariff, customer.getCustomerInfo(), 5, 0.0, -33.2 * 5);
  }