package org.xpdojo.bank;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

public class AccountTest {

    private Account account;

    @BeforeEach
    void setUp() {
        account = new Account();
    }

    @Test
    public void depositAnAmountToIncreaseTheBalance() {
        assertEquals(0, account.balance());
    }

    @Test
    public void depositAmountShouldIncreaseBalance() {
        account.deposit(10);
        assertThat(account.balance()).isEqualTo(10);
    }

    @Test
    public void depositMultipleAmountShouldIncreaseBalance() {
        account.deposit(10);
        account.deposit(3);
        assertThat(account.balance()).isEqualTo(13);
    }

    @Test
    public void withdrawInsufficientAmount() {
        assertThat(account.withdraw(5)).isFalse();
        assertThat(account.balance()).isEqualTo(0);
    }

    @Test
    public void withdrawAmount() {
        account.deposit(8);
        account.withdraw(5);
        assertThat(account.balance()).isEqualTo(3);
    }

    @Test
    public void transferMoneyBetweenAccounts() {
        Account accountSendTo = new Account();
        account.deposit(12);
        account.transfer(10, accountSendTo);
        assertThat(account.balance()).isEqualTo(2);
        assertThat(accountSendTo.balance()).isEqualTo(10);
    }

    @Test
    public void transferToAnotherAccountNoFunds() {
        Account accountSendTo = new Account();
        account.deposit(1);
        assertFalse(account.transfer(10, accountSendTo));
        assertThat(account.balance()).isEqualTo(1);
        assertThat(accountSendTo.balance()).isEqualTo(0);
    }

    @Test
    public void printBalance() {
        assertThat(account.balancePrint()).isEqualToIgnoringCase("Account Balance is : 0");
    }

    @Test
    public void printBalanceAccountWithMoney() {
        account.deposit(1000);
        account.withdraw(1);
        assertThat(account.balancePrint()).isEqualToIgnoringCase("Account Balance is : 999");
    }



}
