/** Test charging a card with insufficient funds. */
  public void testChargeInsufficientFunds() {
    TEST_LOGGER.logTraceId();
    TEST_LOGGER.logInfo("Test charge insufficient funds.");

    final Calendar now = Calendar.getInstance();
    final Calendar startDate = (Calendar) now.clone();
    startDate.set(Calendar.MONTH, now.get(Calendar.MONTH) + 1);

    final Info info = newValidInfo();

    final Transaction transaction = newTransaction();

    final Payment payment = new Payment();
    payment.setAmount(newInsufficientFundsAmount());

    datum.provider.setClient(datum.client);
    datum.provider.setInfo(info);
    boolean didFailDeclined = false;
    try {
      datum.provider.charge(transaction, payment);
    } catch (final CardDeclinedException cdx) {
      didFailDeclined = true;
    } catch (final CardExpiredException cex) {
      fail(cex, "Could not charge.");
    } catch (final PaymentException px) {
      fail(px, "Could not charge.");
    }
    assertTrue(didFailDeclined, "Did not fail with declined.");
  }
  /** Test charge. */
  public void testCharge() {
    TEST_LOGGER.logTraceId();

    final Calendar now = Calendar.getInstance();
    final Calendar startDate = (Calendar) now.clone();
    startDate.set(Calendar.MONTH, now.get(Calendar.MONTH) + 1);

    final Info info = newValidInfo();

    final Transaction transaction = newTransaction();

    final Payment payment = new Payment();
    payment.setAmount(84L * 100L);

    datum.provider.setClient(datum.client);
    datum.provider.setInfo(info);
    try {
      datum.provider.charge(transaction, payment);
    } catch (final CardDeclinedException cdx) {
      fail(cdx, "Could not charge.");
    } catch (final CardExpiredException cex) {
      fail(cex, "Could not charge.");
    } catch (final PaymentException px) {
      fail(px, "Could not charge.");
    }
  }
  /** Test charge with an invalid number. */
  public void testChargeInvalidCardNumber() {
    TEST_LOGGER.logTraceId();

    final Calendar now = Calendar.getInstance();
    final Calendar startDate = (Calendar) now.clone();
    startDate.set(Calendar.MONTH, now.get(Calendar.MONTH) + 1);

    final Info info = newInvalidCardNumberInfo();

    final Transaction transaction = newTransaction();

    final Payment payment = new Payment();
    payment.setAmount(84L * 100L);

    datum.provider.setClient(datum.client);
    datum.provider.setInfo(info);
    boolean didThrow = false;
    try {
      datum.provider.charge(transaction, payment);
    } catch (final CardDeclinedException cdx) {
      fail(cdx, "Could not charge.");
    } catch (final CardExpiredException cex) {
      fail(cex, "Could not charge.");
    } catch (final PaymentException px) {
      didThrow = true;
    }
    assertTrue(didThrow, "Did not correctly identify invalid card number.");
  }