Exemplo n.º 1
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();
  }
Exemplo n.º 2
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();
  }
Exemplo n.º 3
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);
  }
Exemplo n.º 4
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
  }