001 /*
002 * Created on Aug 29, 2007
003 *
004 */
005 package com.x8ing.mc.bp;
006
007 import java.util.GregorianCalendar;
008
009 import junit.framework.TestCase;
010
011 /**
012 * @author Patrick Heusser
013 */
014 public class BalanceSheetTest extends TestCase {
015
016 public void test1() {
017
018 BalanceSheet balanceSheet = new BalanceSheet();
019
020 assertTrue(balanceSheet.calculateCurrentBalance() == 0);
021
022 double t1 = +1.2;
023 double t2 = +10;
024 double t3 = +100;
025 double t4 = -1000;
026 double t5 = +10000;
027 double t6 = +44;
028 double t7 = 444;
029
030 // make sure we start with 0
031 assertTrue(0 == balanceSheet.calculateCurrentBalance());
032
033 // add transactions
034 balanceSheet.addTransaction("booking1", t1, GregorianCalendar.getInstance(),
035 BalanceAccount.BUG_ANALYZING);
036 balanceSheet.addTransaction("booking2", t2, GregorianCalendar.getInstance(),
037 BalanceAccount.DEPLOYMENT);
038 balanceSheet.addTransaction("booking3", t3, GregorianCalendar.getInstance(), BalanceAccount.DEVELOP);
039
040 // check grand total
041 assertTrue(t1 + t2 + t3 == balanceSheet.calculateCurrentBalance());
042
043 // check accounts total
044 assertTrue(t1 == balanceSheet
045 .calculateCurrentBalanceForAccounts(new BalanceAccount[] { BalanceAccount.BUG_ANALYZING }));
046 assertTrue(t1 + t3 == balanceSheet.calculateCurrentBalanceForAccounts(new BalanceAccount[] {
047 BalanceAccount.BUG_ANALYZING, BalanceAccount.DEVELOP }));
048
049 // more transactions
050 balanceSheet.addTransaction("booking4", t4, GregorianCalendar.getInstance(),
051 BalanceAccount.BUG_ANALYZING);
052 balanceSheet.addTransaction("booking5", t5, GregorianCalendar.getInstance(),
053 BalanceAccount.BUG_ANALYZING);
054
055 // check grand total
056 assertTrue(t1 + t2 + t3 + t4 + t5 == balanceSheet.calculateCurrentBalance());
057
058 // check account total
059 assertTrue(t1 + t4 + t5 == balanceSheet
060 .calculateCurrentBalanceForAccounts(new BalanceAccount[] { BalanceAccount.BUG_ANALYZING }));
061 assertTrue(t3 == balanceSheet
062 .calculateCurrentBalanceForAccounts(new BalanceAccount[] { BalanceAccount.DEVELOP }));
063
064 // check for non existing zero value
065 assertTrue(0 == balanceSheet
066 .calculateCurrentBalanceForAccounts(new BalanceAccount[] { BalanceAccount.TESTING }));
067 assertTrue(0 == balanceSheet
068 .calculateCurrentBalanceForAccounts(new BalanceAccount[] { BalanceAccount.PRODUCTION }));
069 assertTrue(0 == balanceSheet.calculateCurrentBalanceForAccounts(new BalanceAccount[] {
070 BalanceAccount.TESTING, BalanceAccount.PRODUCTION }));
071
072 // more transactions
073 balanceSheet.addTransaction("booking6", t6, GregorianCalendar.getInstance(),
074 BalanceAccount.DEPLOYMENT);
075 balanceSheet.addTransaction("booking7", t7, GregorianCalendar.getInstance(),
076 BalanceAccount.DEPLOYMENT);
077
078 // check grand total
079 assertTrue(t1 + t2 + t3 + t4 + t5 + t6 + t7 == balanceSheet.calculateCurrentBalance());
080
081 // check account total
082 assertTrue(0 == balanceSheet
083 .calculateCurrentBalanceForAccounts(new BalanceAccount[] { BalanceAccount.TESTING }));
084 assertTrue(0 == balanceSheet
085 .calculateCurrentBalanceForAccounts(new BalanceAccount[] { BalanceAccount.PRODUCTION }));
086 assertTrue(0 == balanceSheet.calculateCurrentBalanceForAccounts(new BalanceAccount[] {
087 BalanceAccount.TESTING, BalanceAccount.PRODUCTION }));
088
089 // check accounts
090 assertTrue(t2 + t6 + t7 == balanceSheet
091 .calculateCurrentBalanceForAccounts(new BalanceAccount[] { BalanceAccount.DEPLOYMENT }));
092 assertTrue(t2 + t6 + t7 + t1 + t4 + t5 == balanceSheet
093 .calculateCurrentBalanceForAccounts(new BalanceAccount[] { BalanceAccount.DEPLOYMENT,
094 BalanceAccount.BUG_ANALYZING }));
095
096 // test if print generally works without error
097 String print1 = balanceSheet.printBalanceSheetByAccount(false);
098 assertNotNull(print1);
099 assertTrue(print1.length() > 0);
100 System.out.println(print1);
101
102 String print2 = balanceSheet.printBalanceSheetByDate(false);
103 assertNotNull(print2);
104 assertTrue(print2.length() > 0);
105 System.out.println(print2);
106
107 String print3 = balanceSheet.printBalanceSheetAccountOverview();
108 assertNotNull(print3);
109 assertTrue(print3.length() > 0);
110 System.out.println(print3);
111
112
113 }
114 }
|