예제 #1
0
  @Test
  public void shouldClearAllTablesWhenDeletingAllAccounts() {
    Account account = new Account("Test");
    Transaction transaction = new Transaction("Test description");
    Split split = new Split(Money.getZeroInstance(), account.getUID());
    transaction.addSplit(split);
    Account account2 = new Account("Transfer account");
    transaction.addSplit(split.createPair(account2.getUID()));

    mAccountsDbAdapter.addRecord(account);
    mAccountsDbAdapter.addRecord(account2);

    ScheduledAction scheduledAction = new ScheduledAction(ScheduledAction.ActionType.BACKUP);
    scheduledAction.setActionUID("Test-uid");
    ScheduledActionDbAdapter scheduledActionDbAdapter = ScheduledActionDbAdapter.getInstance();

    scheduledActionDbAdapter.addRecord(scheduledAction);

    mAccountsDbAdapter.deleteAllRecords();

    assertThat(mAccountsDbAdapter.getRecordsCount()).isZero();
    assertThat(mTransactionsDbAdapter.getRecordsCount()).isZero();
    assertThat(mSplitsDbAdapter.getRecordsCount()).isZero();
    assertThat(scheduledActionDbAdapter.getRecordsCount()).isZero();
  }
예제 #2
0
  @Test
  public void shouldRecursivelyDeleteAccount() {
    Account account = new Account("Parent");
    Account account2 = new Account("Child");
    account2.setParentUID(account.getUID());

    Transaction transaction = new Transaction("Random");
    account2.addTransaction(transaction);

    Split split = new Split(Money.getZeroInstance(), account.getUID());
    transaction.addSplit(split);
    transaction.addSplit(split.createPair(account2.getUID()));

    mAccountsDbAdapter.addRecord(account);
    mAccountsDbAdapter.addRecord(account2);

    assertThat(mAccountsDbAdapter.getRecordsCount()).isEqualTo(3);
    assertThat(mTransactionsDbAdapter.getRecordsCount()).isEqualTo(1);
    assertThat(mSplitsDbAdapter.getRecordsCount()).isEqualTo(2);

    boolean result =
        mAccountsDbAdapter.recursiveDeleteAccount(mAccountsDbAdapter.getID(account.getUID()));
    assertThat(result).isTrue();

    assertThat(mAccountsDbAdapter.getRecordsCount()).isEqualTo(1); // the root account
    assertThat(mTransactionsDbAdapter.getRecordsCount()).isZero();
    assertThat(mSplitsDbAdapter.getRecordsCount()).isZero();
  }
예제 #3
0
  /** Test that the list of accounts is always returned sorted alphabetically */
  @Test
  public void shouldBeAlphabeticallySortedByDefault() {
    Account first = new Account(ALPHA_ACCOUNT_NAME);
    Account second = new Account(BRAVO_ACCOUNT_NAME);
    // purposefully added the second after the first
    mAccountsDbAdapter.addRecord(second);
    mAccountsDbAdapter.addRecord(first);

    List<Account> accountsList = mAccountsDbAdapter.getAllRecords();
    assertEquals(2, accountsList.size());
    // bravo was saved first, but alpha should be first alphabetically
    assertThat(accountsList).contains(first, Index.atIndex(0));
    assertThat(accountsList).contains(second, Index.atIndex(1));
  }
예제 #4
0
  @Test
  public void shouldAddAccountsToDatabase() {
    Account account1 = new Account("AlphaAccount");
    Account account2 = new Account("BetaAccount");
    Transaction transaction = new Transaction("MyTransaction");
    Split split = new Split(Money.getZeroInstance(), account1.getUID());
    transaction.addSplit(split);
    transaction.addSplit(split.createPair(account2.getUID()));
    account1.addTransaction(transaction);
    account2.addTransaction(transaction);

    mAccountsDbAdapter.addRecord(account1);
    mAccountsDbAdapter.addRecord(account2);

    Account firstAccount = mAccountsDbAdapter.getRecord(account1.getUID());
    assertThat(firstAccount).isNotNull();
    assertThat(firstAccount.getUID()).isEqualTo(account1.getUID());
    assertThat(firstAccount.getFullName()).isEqualTo(account1.getFullName());

    Account secondAccount = mAccountsDbAdapter.getRecord(account2.getUID());
    assertThat(secondAccount).isNotNull();
    assertThat(secondAccount.getUID()).isEqualTo(account2.getUID());

    assertThat(mTransactionsDbAdapter.getRecordsCount()).isEqualTo(1);
  }
예제 #5
0
  @Test
  public void simpleAccountListShouldNotContainTransactions() {
    Account account = new Account("Test");
    Transaction transaction = new Transaction("Test description");
    Split split = new Split(Money.getZeroInstance(), account.getUID());
    transaction.addSplit(split);
    Account account1 = new Account("Transfer");
    transaction.addSplit(split.createPair(account1.getUID()));

    mAccountsDbAdapter.addRecord(account);
    mAccountsDbAdapter.addRecord(account1);

    List<Account> accounts = mAccountsDbAdapter.getSimpleAccountList();
    for (Account testAcct : accounts) {
      assertThat(testAcct.getTransactionCount()).isZero();
    }
  }
예제 #6
0
  @Test
  public void shouldAddTransactionsAndSplitsWhenAddingAccounts() {
    Account account = new Account("Test");
    mAccountsDbAdapter.addRecord(account);

    Transaction transaction = new Transaction("Test description");
    Split split = new Split(Money.getZeroInstance(), account.getUID());
    transaction.addSplit(split);
    Account account1 = new Account("Transfer account");
    transaction.addSplit(split.createPair(account1.getUID()));
    account1.addTransaction(transaction);

    mAccountsDbAdapter.addRecord(account1);

    assertThat(mTransactionsDbAdapter.getRecordsCount()).isEqualTo(1);
    assertThat(mSplitsDbAdapter.getRecordsCount()).isEqualTo(2);
    assertThat(mAccountsDbAdapter.getRecordsCount())
        .isEqualTo(3); // ROOT account automatically added
  }
예제 #7
0
  @Test
  public void shouldUpdateFullNameAfterParentChange() {
    Account parent = new Account("Test");
    Account child = new Account("Child");

    mAccountsDbAdapter.addRecord(parent);
    mAccountsDbAdapter.addRecord(child);

    child.setParentUID(parent.getUID());
    mAccountsDbAdapter.addRecord(child);

    child = mAccountsDbAdapter.getRecord(child.getUID());
    parent = mAccountsDbAdapter.getRecord(parent.getUID());

    assertThat(mAccountsDbAdapter.getSubAccountCount(parent.getUID())).isEqualTo(1);
    assertThat(parent.getUID()).isEqualTo(child.getParentUID());

    assertThat(child.getFullName()).isEqualTo("Test:Child");
  }
예제 #8
0
  @Test
  public void shouldComputeAccountBalanceCorrectly() {
    Account account = new Account("Test", Commodity.USD);
    account.setAccountType(AccountType.ASSET); // debit normal account balance
    Account transferAcct = new Account("Transfer");

    mAccountsDbAdapter.addRecord(account);
    mAccountsDbAdapter.addRecord(transferAcct);

    Transaction transaction = new Transaction("Test description");
    mTransactionsDbAdapter.addRecord(transaction);
    Split split = new Split(new Money(BigDecimal.TEN, Commodity.USD), account.getUID());
    split.setTransactionUID(transaction.getUID());
    split.setType(TransactionType.DEBIT);
    mSplitsDbAdapter.addRecord(split);

    split = new Split(new Money("4.99", "USD"), account.getUID());
    split.setTransactionUID(transaction.getUID());
    split.setType(TransactionType.DEBIT);
    mSplitsDbAdapter.addRecord(split);

    split = new Split(new Money("1.19", "USD"), account.getUID());
    split.setTransactionUID(transaction.getUID());
    split.setType(TransactionType.CREDIT);
    mSplitsDbAdapter.addRecord(split);

    split = new Split(new Money("3.49", "EUR"), account.getUID());
    split.setTransactionUID(transaction.getUID());
    split.setType(TransactionType.DEBIT);
    mSplitsDbAdapter.addRecord(split);

    split = new Split(new Money("8.39", "USD"), transferAcct.getUID());
    split.setTransactionUID(transaction.getUID());
    mSplitsDbAdapter.addRecord(split);

    // balance computation ignores the currency of the split
    Money balance = mAccountsDbAdapter.getAccountBalance(account.getUID());
    Money expectedBalance = new Money("17.29", "USD"); // EUR splits should be ignored

    assertThat(balance).isEqualTo(expectedBalance);
  }
예제 #9
0
  /** Tests that a ROOT account will always be created in the system */
  @Test
  public void shouldCreateDefaultRootAccount() {
    Account account = new Account("Some account");
    mAccountsDbAdapter.addRecord(account);
    assertThat(mAccountsDbAdapter.getRecordsCount()).isEqualTo(2L);

    List<Account> accounts = mAccountsDbAdapter.getSimpleAccountList();
    assertThat(accounts).extracting("mAccountType").contains(AccountType.ROOT);

    String rootAccountUID = mAccountsDbAdapter.getOrCreateGnuCashRootAccountUID();
    assertThat(rootAccountUID).isEqualTo(accounts.get(1).getParentUID());
  }
  @Before
  public void setUp() throws Exception {
    mSplitsDbAdapter = SplitsDbAdapter.getInstance();
    mTransactionsDbAdapter = TransactionsDbAdapter.getInstance();
    mAccountsDbAdapter = AccountsDbAdapter.getInstance();

    alphaAccount = new Account(ALPHA_ACCOUNT_NAME);
    bravoAccount = new Account(BRAVO_ACCOUNT_NAME);

    mAccountsDbAdapter.addRecord(bravoAccount);
    mAccountsDbAdapter.addRecord(alphaAccount);

    mTestSplit = new Split(new Money(BigDecimal.TEN, DEFAULT_CURRENCY), alphaAccount.getUID());
  }
예제 #11
0
  /** Tests the foreign key constraint "ON DELETE CASCADE" between accounts and splits */
  @Test
  public void shouldDeleteSplitsWhenAccountDeleted() {
    Account first = new Account(ALPHA_ACCOUNT_NAME);
    first.setUID(ALPHA_ACCOUNT_NAME);
    Account second = new Account(BRAVO_ACCOUNT_NAME);
    second.setUID(BRAVO_ACCOUNT_NAME);

    mAccountsDbAdapter.addRecord(second);
    mAccountsDbAdapter.addRecord(first);

    Transaction transaction = new Transaction("TestTrn");
    Split split = new Split(Money.getZeroInstance(), ALPHA_ACCOUNT_NAME);
    transaction.addSplit(split);
    transaction.addSplit(split.createPair(BRAVO_ACCOUNT_NAME));

    mTransactionsDbAdapter.addRecord(transaction);

    mAccountsDbAdapter.deleteRecord(ALPHA_ACCOUNT_NAME);

    Transaction trxn = mTransactionsDbAdapter.getRecord(transaction.getUID());
    assertThat(trxn.getSplits().size()).isEqualTo(1);
    assertThat(trxn.getSplits().get(0).getAccountUID()).isEqualTo(BRAVO_ACCOUNT_NAME);
  }