package com.github.cstroe.spendhawk.entity;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class AccountTest {

    private EntityTestScenario scenario;

    @Before
    public void setUp() {
        String[] accountsTemplate = new String[] {
                // Account ID, Account Name
                "1", "Account1"
        };
        String[] transactionsTemplate = new String[] {
                // Transaction ID, Account ID, Amount, Date ("yyMMddHHmmss"), Description
                "1", "1", "10.99", "010101000000", "Transaction 1",
                "1", "1", "11.40", "010101000000", "Transaction 2"
        };
        scenario = new EntityTestScenario(accountsTemplate, transactionsTemplate);
    }

    @Test
    public void balance() {
        Account a1 = scenario.getAccountsList().stream().filter(a -> a.getId() == 1).findFirst().get();
        assertEquals(new Double(22.39d), a1.getBalance());
        assertEquals(2, a1.getTransactions().size());
    }

    @Test
    public void balanceWithoutAnyTransactions() {
        Account a1 = new Account();
        a1.setName("Test Account");
        assertEquals(new Double(0d), a1.getBalance());
    }
}

@@ -87,16 +87,191 @@
 .Test;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0Aimport static org.hamcrest.MatcherAssert.assertThat;%0Aimport static org.hamcrest.Matchers.is;%0A
 import s
@@ -1389,11 +1389,968 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void compare() %7B%0A        char c = 'z';%0A%0A        List%3CAccount%3E accountList = new ArrayList%3C%3E();%0A        for (long i = 0; i %3C= 'z' - 'a'; i++) %7B%0A            Account currentAccount = new Account();%0A            currentAccount.setId(i);%0A            currentAccount.setName(%22Account %22 + Character.toString((char) (c - i)));%0A            accountList.add(currentAccount);%0A        %7D%0A%0A        Collections.shuffle(accountList);%0A        Collections.sort(accountList);%0A%0A        for (int i = 0; i %3C accountList.size() - 1; i++) %7B%0A            Account currentAccount = accountList.get(i);%0A            Account nextAccount = accountList.get(i + 1);%0A            assertThat(%22A current account should be before the next account%22,%0A                    currentAccount.compareTo(nextAccount), is(-1));%0A            assertThat(%22A next account should be after the current account%22,%0A                    nextAccount.compareTo(currentAccount), is(1));%0A        %7D%0A    %7D
 %0A%7D%0A

Test the comparator on Accounts.