package fr.bellingard.accountmanager.model;

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

import static org.assertj.core.api.Assertions.assertThat;

/**
 *
 */
public class AccountTest {

    private Account account;
    private Account parentAccount;
    private Account subAccount1;
    private Account subAccount2;

    @Before
    public void init() {
        account = new Account("A001", "An Account");
        account.setInstitution(new Institution("I001", ""));
        account.setAccountNumber("123456");

        parentAccount = new Account("A00P", "Parent");
        account.setParent(parentAccount);

        subAccount1 = new Account("A00S1", "Sub1");
        subAccount1.setParent(account);
        subAccount2 = new Account("A00S2", "Sub2");
        subAccount2.setParent(account);
    }

    @Test
    public void should_read() throws Exception {
        assertThat(account.getId()).isEqualTo("A001");
        assertThat(account.getName()).isEqualTo("An Account");
        assertThat(account.getAccountNumber().get()).isEqualTo("123456");
        assertThat(account.getInstitution().get()).isEqualTo(new Institution("I001", ""));
    }

    @Test
    public void should_check_equals() throws Exception {
        assertThat(account).isEqualTo(new Account("A001", ""));
        assertThat(account).isNotEqualTo(new Account("", ""));
    }

    @Test
    public void should_update() throws Exception {
        account.setName("Foo");
        assertThat(account.getName()).isEqualTo("Foo");
    }

    @Test
    public void should_check_to_string() throws Exception {
        String message = account.toString();

        assertThat(message).contains("A001");
        assertThat(message).contains("An Account");
    }

    @Test
    public void should_have_parent_or_not() throws Exception {
        assertThat(parentAccount.getParent().isPresent()).isFalse();
        assertThat(account.getParent().get()).isEqualTo(parentAccount);
        assertThat(subAccount1.getParent().get()).isEqualTo(account);
    }

    @Test
    public void should_have_sub_accounts_or_not() throws Exception {
        assertThat(parentAccount.listSubAccount()).containsExactly(account);
        assertThat(account.listSubAccount()).containsExactly(subAccount1, subAccount2);
        assertThat(subAccount1.listSubAccount().size()).isEqualTo(0);
    }

    @Test
    public void should_move_account_to_another_parent() throws Exception {
        subAccount2.setParent(parentAccount);

        assertThat(parentAccount.listSubAccount()).containsExactly(account, subAccount2);
        assertThat(account.listSubAccount()).containsExactly(subAccount1);
    }

}

@@ -67,38 +67,8 @@
 re;%0A
-import org.junit.BeforeClass;%0A
 impo
@@ -2644,10 +2644,557 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void should_compute_balance() throws Exception %7B%0A        // standard transactions%0A        new Transaction(%22T1%22, subAccount1, new Account(%22A1%22, %22%22), %22%22, 1200L);%0A        new Transaction(%22T2%22, subAccount1, new Account(%22A1%22, %22%22), %22%22, -1000L);%0A        new Transaction(%22T3%22, subAccount1, new Account(%22A1%22, %22%22), %22%22, 2000L);%0A        // and a transfer of 500 to another account%0A        new Transaction(%22T4%22, subAccount2, subAccount1, %22%22, 500L);%0A%0A        assertThat(subAccount1.getBalance()).isEqualTo(1200 - 1000 + 2000 - 500);%0A    %7D%0A%0A
 %7D%0A

Add more tests