Exemplo n.º 1
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));
  }
  @Test
  public void testTransactionsAreTimeSorted() {
    Transaction t1 = new Transaction("T800");
    t1.setTime(System.currentTimeMillis() - 10000);
    Split split = new Split(Money.getZeroInstance(), alphaAccount.getUID());
    t1.addSplit(split);
    t1.addSplit(split.createPair(bravoAccount.getUID()));

    Transaction t2 = new Transaction("T1000");
    t2.setTime(System.currentTimeMillis());
    Split split2 = new Split(new Money("23.50"), bravoAccount.getUID());
    t2.addSplit(split2);
    t2.addSplit(split2.createPair(alphaAccount.getUID()));

    mTransactionsDbAdapter.addRecord(t1);
    mTransactionsDbAdapter.addRecord(t2);

    List<Transaction> transactionsList =
        mTransactionsDbAdapter.getAllTransactionsForAccount(alphaAccount.getUID());
    assertThat(transactionsList).contains(t2, Index.atIndex(0));
    assertThat(transactionsList).contains(t1, Index.atIndex(1));
  }