@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(); }
@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); }
@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(); }
/** 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()); }
@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 }