Package com.wesabe.api.accounts.entities

Examples of com.wesabe.api.accounts.entities.TxactionBalanceCalculator


    }
   
    public TxactionBalanceCalculator calculator(Currency targetCurrency) throws Exception {
      inject(Account.class, account, "accountBalances", accountBalances);
      inject(Account.class, account, "txactions", Sets.newHashSet(txactions));
      return new TxactionBalanceCalculator(accounts, txactions, targetCurrency, exchangeRates);
    }
View Full Code Here


    @Test
    public void itIncludesTxactionsAfterTheMostRecentAccountBalance() throws Exception {
      Txaction firstTxaction = new Txaction(account, decimal("-5.00"), now());
      txactions.add(firstTxaction);
     
      TxactionBalanceCalculator calculator = calculator();
      assertEquals(money("95.00", USD), calculator.getBalance(firstTxaction));
      assertEquals(money("100.00", USD), calculator.getBalance(txaction));
    }
View Full Code Here

        txactions.add(new Txaction(account, decimal("-5.00"), now().minusDays(20+i)));
      }
      // create a balance in the middle of those txactions
      accountBalances.add(new AccountBalance(account, decimal("5000"), now().minusDays(25)));
     
      TxactionBalanceCalculator calculator = calculator();
      assertEquals(money("100.00", USD), calculator.getBalance(txactions.get(0)));
      assertEquals(money("110.00", USD), calculator.getBalance(txactions.get(1)));
      assertEquals(money("115.00", USD), calculator.getBalance(txactions.get(2)));
      assertEquals(money("120.00", USD), calculator.getBalance(txactions.get(3)));
      assertEquals(money("125.00", USD), calculator.getBalance(txactions.get(4)));
      assertEquals(money("130.00", USD), calculator.getBalance(txactions.get(5)));
      assertEquals(money("135.00", USD), calculator.getBalance(txactions.get(6)));
      assertEquals(money("140.00", USD), calculator.getBalance(txactions.get(7)));
      assertEquals(money("145.00", USD), calculator.getBalance(txactions.get(8)));
      assertEquals(money("150.00", USD), calculator.getBalance(txactions.get(9)));
      assertEquals(money("155.00", USD), calculator.getBalance(txactions.get(10)));
    }
View Full Code Here

      inject(Account.class, cash, "accountBalances", Sets.newHashSet());
      inject(Account.class, cash, "txactions", Sets.newHashSet(cashTxactions));
      inject(Account.class, savings, "accountBalances", savingsBalances);
      inject(Account.class, savings, "txactions", Sets.newHashSet(savingsTxactions));
     
      return new TxactionBalanceCalculator(accounts, txactions, USD, exchangeRates);
    }
View Full Code Here

      return new TxactionBalanceCalculator(accounts, txactions, USD, exchangeRates);
    }
   
    @Test
    public void itHasABalanceForEachTxaction() throws Exception {
      TxactionBalanceCalculator calculator = calculator();
     
      for (Txaction txaction : txactions) {
        assertNotNull(calculator.getBalance(txaction));
      }
    }
View Full Code Here

      }
    }
   
    @Test
    public void itHasTheCorrectBalancesForAllTxactions() throws Exception {
      TxactionBalanceCalculator calculator = calculator();
     
      // initial balances:
      //   checking =   90 USD
      //   credit   =  -50 USD
      //   cash     =  n/a
      //   savings  =  800 USD (1000 EUR * 0.8 USD / EUR)
      //   total    =  840 USD
     
      assertEquals(money("840.00", USD), calculator.getBalance(newerThanFirstBalance));
      // adjust checking balance: 90 - (-10) => 100 (total 850)
     
      assertEquals(money("850.00", USD), calculator.getBalance(firstTxactionPastFirstBalance));
      // adjust checking balance: 100 - (-10) => 110 (total 860)
     
      assertEquals(money("860.00", USD), calculator.getBalance(secondTxactionPastFirstBalance));
      // adjust credit balance: -50 - (-20) => -30 (total 880)
     
      assertEquals(money("880.00", USD), calculator.getBalance(thirdTxactionPastFirstBalance));
      // adjust credit balance: -30 - (-20) => -10 (total 900)
     
      assertEquals(money("900.00", USD), calculator.getBalance(cashTxaction));
      // REVIEW <brian@wesabe.com> 2009-04-08: Should the balance for cash transactions be null?
      // no adjustment of balance (total 900)
     
      assertEquals(money("900.00", USD), calculator.getBalance(fifthTxactionPastFirstBalance));
      // adjust savings balance: 1000 EUR - (100 EUR) => 900 EUR => 720 USD (total 820)
     
      assertEquals(money("820.00", USD), calculator.getBalance(sixthTxactionPastFirstBalance));
      // adjust savings balance: 900 EUR - (100 EUR) => 800 EUR => 640 USD (total 740)
     
      assertEquals(money("740.00", USD), calculator.getBalance(firstTxactionAfterCreditIsReset));
      // adjust credit balance: 0 - (400) => -400 (total 340)
     
      assertEquals(money("340.00", USD), calculator.getBalance(lastTxaction));
      // adjust savings balance: 800 EUR - (100 EUR) => 700 EUR => 560 USD (total 260)
    }
View Full Code Here

TOP

Related Classes of com.wesabe.api.accounts.entities.TxactionBalanceCalculator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.