コード例 #1
0
  @Test
  public void shouldCreateImbalanceAccountOnDemand() {
    assertThat(mAccountsDbAdapter.getRecordsCount()).isEqualTo(0);

    Currency usd = Currency.getInstance("USD");
    String imbalanceUID = mAccountsDbAdapter.getImbalanceAccountUID(usd);
    assertThat(imbalanceUID).isNull();
    assertThat(mAccountsDbAdapter.getRecordsCount()).isEqualTo(0);

    imbalanceUID = mAccountsDbAdapter.getOrCreateImbalanceAccountUID(usd);
    assertThat(imbalanceUID).isNotNull().isNotEmpty();
    assertThat(mAccountsDbAdapter.getRecordsCount()).isEqualTo(2);
  }
コード例 #2
0
  @Test
  public void shouldBalanceTransactionsOnSave() {
    Transaction transaction = new Transaction("Auto balance");
    Split split =
        new Split(
            new Money(BigDecimal.TEN, Currency.getInstance(Money.DEFAULT_CURRENCY_CODE)),
            alphaAccount.getUID());

    transaction.addSplit(split);

    mTransactionsDbAdapter.addRecord(transaction);

    Transaction trn = mTransactionsDbAdapter.getRecord(transaction.getUID());
    assertThat(trn.getSplits()).hasSize(2);

    String imbalanceAccountUID =
        mAccountsDbAdapter.getImbalanceAccountUID(
            Currency.getInstance(Money.DEFAULT_CURRENCY_CODE));
    assertThat(trn.getSplits()).extracting("mAccountUID").contains(imbalanceAccountUID);
  }