View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.fp.businessobject;
20  
21  import org.kuali.kfs.sys.context.KualiTestBase;
22  import org.kuali.rice.core.api.util.type.KualiDecimal;
23  
24  public class CashDrawerTest extends KualiTestBase {
25      public enum CashDrawerAmountFixture {
26          GOOD_CASH_DRAWER(500.0, 250.0, 100.0, 50.0, 25.0, 10.0, 5.0, 5.0, 5.0, 2.5, 1.25, 0.5, 0.25, 0.05, 0.5), ALL_FIVES_CASH_DRAWER(500.0, 500.0, 500.0, 500.0, 500.0, 500.0, 500.0, 500.0, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00), ALL_SEVENS_CASH_DRAWER(700.0, 700.0, 700.0, 700.0, 700.0, 700.0, 700.0, 700.0, 7.00, 7.00, 7.00, 7.00, 7.00, 7.00, 7.00), ZERO_CASH_DRAWER(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), NULL_CASH_DRAWER;
27  
28          private KualiDecimal hundredDollarAmount;
29          private KualiDecimal fiftyDollarAmount;
30          private KualiDecimal twentyDollarAmount;
31          private KualiDecimal tenDollarAmount;
32          private KualiDecimal fiveDollarAmount;
33          private KualiDecimal twoDollarAmount;
34          private KualiDecimal oneDollarAmount;
35          private KualiDecimal otherDollarAmount;
36          private KualiDecimal hundredCentAmount;
37          private KualiDecimal fiftyCentAmount;
38          private KualiDecimal twentyFiveCentAmount;
39          private KualiDecimal tenCentAmount;
40          private KualiDecimal fiveCentAmount;
41          private KualiDecimal oneCentAmount;
42          private KualiDecimal otherCentAmount;
43  
44          private CashDrawerAmountFixture() {
45          }
46  
47          private CashDrawerAmountFixture(double hundredDollarAmount, double fiftyDollarAmount, double twentyDollarAmount, double tenDollarAmount, double fiveDollarAmount, double twoDollarAmount, double oneDollarAmount, double otherDollarAmount, double hundredCentAmount, double fiftyCentAmount, double twentyFiveCentAmount, double tenCentAmount, double fiveCentAmount, double oneCentAmount, double otherCentAmount) {
48              this.hundredDollarAmount = new KualiDecimal(hundredDollarAmount);
49              this.fiftyDollarAmount = new KualiDecimal(fiftyDollarAmount);
50              this.twentyDollarAmount = new KualiDecimal(twentyDollarAmount);
51              this.tenDollarAmount = new KualiDecimal(tenDollarAmount);
52              this.fiveDollarAmount = new KualiDecimal(fiveDollarAmount);
53              this.twoDollarAmount = new KualiDecimal(twoDollarAmount);
54              this.oneDollarAmount = new KualiDecimal(oneDollarAmount);
55              this.otherDollarAmount = new KualiDecimal(otherDollarAmount);
56              this.hundredCentAmount = new KualiDecimal(hundredCentAmount);
57              this.fiftyCentAmount = new KualiDecimal(fiftyCentAmount);
58              this.twentyFiveCentAmount = new KualiDecimal(twentyFiveCentAmount);
59              this.tenCentAmount = new KualiDecimal(tenCentAmount);
60              this.fiveCentAmount = new KualiDecimal(fiveCentAmount);
61              this.oneCentAmount = new KualiDecimal(oneCentAmount);
62              this.otherCentAmount = new KualiDecimal(otherCentAmount);
63          }
64  
65          public CashDrawer convertToCashDrawer() {
66              CashDrawer drawer = new CashDrawer();
67              drawer.setFinancialDocumentHundredDollarAmount(this.hundredDollarAmount);
68              drawer.setFinancialDocumentFiftyDollarAmount(this.fiftyDollarAmount);
69              drawer.setFinancialDocumentTwentyDollarAmount(this.twentyDollarAmount);
70              drawer.setFinancialDocumentTenDollarAmount(this.tenDollarAmount);
71              drawer.setFinancialDocumentFiveDollarAmount(this.fiveDollarAmount);
72              drawer.setFinancialDocumentTwoDollarAmount(this.twoDollarAmount);
73              drawer.setFinancialDocumentOneDollarAmount(this.oneDollarAmount);
74              drawer.setFinancialDocumentOtherDollarAmount(this.otherDollarAmount);
75              drawer.setFinancialDocumentHundredCentAmount(this.hundredCentAmount);
76              drawer.setFinancialDocumentFiftyCentAmount(this.fiftyCentAmount);
77              drawer.setFinancialDocumentTwentyFiveCentAmount(this.twentyFiveCentAmount);
78              drawer.setFinancialDocumentTenCentAmount(this.tenCentAmount);
79              drawer.setFinancialDocumentFiveCentAmount(this.fiveCentAmount);
80              drawer.setFinancialDocumentOneCentAmount(this.oneCentAmount);
81              drawer.setFinancialDocumentOtherCentAmount(this.otherCentAmount);
82              return drawer;
83          }
84      }
85  
86      public enum CashDrawerCountFixture {
87          GOOD_CASH_DRAWER(new Integer(5), new Integer(10), new Integer(25), new Integer(50), new Integer(100), new Integer(250), new Integer(500), new Integer(5), new Integer(10), new Integer(20), new Integer(50), new Integer(100), new Integer(500)), ALL_FIVES_CASH_DRAWER(new Integer(5), new Integer(5), new Integer(5), new Integer(5), new Integer(5), new Integer(5), new Integer(5), new Integer(5), new Integer(5), new Integer(5), new Integer(5), new Integer(5), new Integer(5)), ZERO_CASH_DRAWER(new Integer(0), new Integer(0), new Integer(0), new Integer(0), new Integer(0), new Integer(0), new Integer(0), new Integer(0), new Integer(0), new Integer(0), new Integer(0), new Integer(0), new Integer(0)), NULL_CASH_DRAWER;
88  
89          private Integer hundredDollarCount;
90          private Integer fiftyDollarCount;
91          private Integer twentyDollarCount;
92          private Integer tenDollarCount;
93          private Integer fiveDollarCount;
94          private Integer twoDollarCount;
95          private Integer oneDollarCount;
96          private Integer hundredCentCount;
97          private Integer fiftyCentCount;
98          private Integer twentyFiveCentCount;
99          private Integer tenCentCount;
100         private Integer fiveCentCount;
101         private Integer oneCentCount;
102 
103         private CashDrawerCountFixture() {
104         }
105 
106         private CashDrawerCountFixture(Integer hundredDollarCount, Integer fiftyDollarCount, Integer twentyDollarCount, Integer tenDollarCount, Integer fiveDollarCount, Integer twoDollarCount, Integer oneDollarCount, Integer hundredCentCount, Integer fiftyCentCount, Integer twentyFiveCentCount, Integer tenCentCount, Integer fiveCentCount, Integer oneCentCount) {
107             this.hundredDollarCount = hundredDollarCount;
108             this.fiftyDollarCount = fiftyDollarCount;
109             this.twentyDollarCount = twentyDollarCount;
110             this.tenDollarCount = tenDollarCount;
111             this.fiveDollarCount = fiveDollarCount;
112             this.twoDollarCount = twoDollarCount;
113             this.oneDollarCount = oneDollarCount;
114             this.hundredCentCount = hundredCentCount;
115             this.fiftyCentCount = fiftyCentCount;
116             this.twentyFiveCentCount = twentyFiveCentCount;
117             this.tenCentCount = tenCentCount;
118             this.fiveCentCount = fiveCentCount;
119             this.oneCentCount = oneCentCount;
120         }
121 
122         public CashDrawer convertToCashDrawer() {
123             CashDrawer drawer = new CashDrawer();
124             drawer.setHundredDollarCount(this.hundredDollarCount);
125             drawer.setFiftyDollarCount(this.fiftyDollarCount);
126             drawer.setTwentyDollarCount(this.twentyDollarCount);
127             drawer.setTenDollarCount(this.tenDollarCount);
128             drawer.setFiveDollarCount(this.fiveDollarCount);
129             drawer.setTwoDollarCount(this.twoDollarCount);
130             drawer.setOneDollarCount(this.oneDollarCount);
131             drawer.setHundredCentCount(this.hundredCentCount);
132             drawer.setFiftyCentCount(this.fiftyCentCount);
133             drawer.setTwentyFiveCentCount(this.twentyFiveCentCount);
134             drawer.setTenCentCount(this.tenCentCount);
135             drawer.setFiveCentCount(this.fiveCentCount);
136             drawer.setOneCentCount(this.oneCentCount);
137             return drawer;
138         }
139     }
140 
141     public void testAmountToCount() {
142         CashDrawer drawer = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
143         assertEquals(drawer.getHundredDollarCount(), new Integer(5));
144         assertEquals(drawer.getFiftyDollarCount(), new Integer(10));
145         assertEquals(drawer.getTwentyDollarCount(), new Integer(25));
146         assertEquals(drawer.getTenDollarCount(), new Integer(50));
147         assertEquals(drawer.getFiveDollarCount(), new Integer(100));
148         assertEquals(drawer.getTwoDollarCount(), new Integer(250));
149         assertEquals(drawer.getOneDollarCount(), new Integer(500));
150         assertEquals(drawer.getHundredCentCount(), new Integer(5));
151         assertEquals(drawer.getFiftyCentCount(), new Integer(10));
152         assertEquals(drawer.getTwentyFiveCentCount(), new Integer(20));
153         assertEquals(drawer.getTenCentCount(), new Integer(50));
154         assertEquals(drawer.getFiveCentCount(), new Integer(100));
155         assertEquals(drawer.getOneCentCount(), new Integer(500));
156     }
157 
158     public void testCountToAmount() {
159         CashDrawer drawer = CashDrawerCountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
160         assertEquals(drawer.getFinancialDocumentHundredDollarAmount(), new KualiDecimal(500.0));
161         assertEquals(drawer.getFinancialDocumentFiftyDollarAmount(), new KualiDecimal(250.0));
162         assertEquals(drawer.getFinancialDocumentTwentyDollarAmount(), new KualiDecimal(100.0));
163         assertEquals(drawer.getFinancialDocumentTenDollarAmount(), new KualiDecimal(50.0));
164         assertEquals(drawer.getFinancialDocumentFiveDollarAmount(), new KualiDecimal(25.0));
165         assertEquals(drawer.getFinancialDocumentTwoDollarAmount(), new KualiDecimal(10.0));
166         assertEquals(drawer.getFinancialDocumentOneDollarAmount(), new KualiDecimal(5.0));
167         assertEquals(drawer.getFinancialDocumentHundredCentAmount(), new KualiDecimal(5.0));
168         assertEquals(drawer.getFinancialDocumentFiftyCentAmount(), new KualiDecimal(2.5));
169         assertEquals(drawer.getFinancialDocumentTwentyFiveCentAmount(), new KualiDecimal(1.25));
170         assertEquals(drawer.getFinancialDocumentTenCentAmount(), new KualiDecimal(0.5));
171         assertEquals(drawer.getFinancialDocumentFiveCentAmount(), new KualiDecimal(0.25));
172         assertEquals(drawer.getFinancialDocumentOneCentAmount(), new KualiDecimal(0.05));
173     }
174 
175     public void testCurrencyTotal() {
176         CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER.convertToCashDrawer();
177         assertEquals(zeroDrawer.getCurrencyTotalAmount(), KualiDecimal.ZERO);
178         CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
179         assertEquals(nullDrawer.getCurrencyTotalAmount(), KualiDecimal.ZERO);
180         CashDrawer goodDrawer = CashDrawerAmountFixture.GOOD_CASH_DRAWER.convertToCashDrawer();
181         assertEquals(goodDrawer.getCurrencyTotalAmount(), new KualiDecimal(945));
182     }
183 
184     public void testCoinTotal() {
185         CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER.convertToCashDrawer();
186         assertEquals(zeroDrawer.getCoinTotalAmount(), KualiDecimal.ZERO);
187         CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
188         assertEquals(nullDrawer.getCoinTotalAmount(), KualiDecimal.ZERO);
189         CashDrawer goodDrawer = CashDrawerAmountFixture.GOOD_CASH_DRAWER.convertToCashDrawer();
190         assertEquals(goodDrawer.getCoinTotalAmount(), new KualiDecimal(10.05));
191     }
192 
193     public void testDrawerTotal() {
194         CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER.convertToCashDrawer();
195         assertEquals(zeroDrawer.getTotalAmount(), KualiDecimal.ZERO);
196         CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
197         assertEquals(nullDrawer.getTotalAmount(), KualiDecimal.ZERO);
198         CashDrawer goodDrawer = CashDrawerAmountFixture.GOOD_CASH_DRAWER.convertToCashDrawer();
199         assertEquals(goodDrawer.getTotalAmount(), new KualiDecimal(955.05));
200     }
201 
202     public void testAddCurrency() {
203         CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER.convertToCashDrawer();
204         zeroDrawer.addCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
205         assertCurrencyAmountsEqual(zeroDrawer, CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
206 
207         CashDrawer nullDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER.convertToCashDrawer();
208         nullDrawer.addCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.GOOD_POSITIVE_AMOUNT.convertToCurrencyDetail());
209         assertCurrencyAmountsEqual(nullDrawer, CurrencyDetailTest.CurrencyDetailAmountFixture.GOOD_POSITIVE_AMOUNT.convertToCurrencyDetail());
210 
211         CashDrawer allFivesDrawerA = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
212         allFivesDrawerA.addCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
213         assertCurrencyAmountsEqual(allFivesDrawerA, CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_FIVES_AMOUNT.convertToCurrencyDetail());
214 
215         CashDrawer allFivesDrawerB = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
216         allFivesDrawerB.addCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.NULL_AMOUNT.convertToCurrencyDetail());
217         assertCurrencyAmountsEqual(allFivesDrawerB, CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_FIVES_AMOUNT.convertToCurrencyDetail());
218 
219         CashDrawer allFivesDrawerC = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
220         allFivesDrawerC.addCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_FIVES_AMOUNT.convertToCurrencyDetail());
221         assertCurrencyAmountsEqual(allFivesDrawerC, CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_TENS_AMOUNT.convertToCurrencyDetail());
222     }
223 
224     public void testAddCoin() {
225         CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER.convertToCashDrawer();
226         zeroDrawer.addCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
227         assertCoinAmountsEqual(zeroDrawer, CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
228 
229         CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
230         nullDrawer.addCoin(CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT.convertToCoinDetail());
231         assertCoinAmountsEqual(nullDrawer, CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT.convertToCoinDetail());
232 
233         CashDrawer allFivesDrawerA = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
234         allFivesDrawerA.addCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
235         assertCoinAmountsEqual(allFivesDrawerA, CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT.convertToCoinDetail());
236 
237         CashDrawer allFivesDrawerB = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
238         allFivesDrawerB.addCoin(CoinDetailTest.CoinDetailAmountFixture.NULL_COIN_AMOUNT.convertToCoinDetail());
239         assertCoinAmountsEqual(allFivesDrawerB, CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT.convertToCoinDetail());
240 
241         CashDrawer allFivesDrawerC = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
242         allFivesDrawerC.addCoin(CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT.convertToCoinDetail());
243         assertCoinAmountsEqual(allFivesDrawerC, CoinDetailTest.CoinDetailAmountFixture.ALL_TENS_COIN_AMOUNT.convertToCoinDetail());
244     }
245 
246     public void testSubtractCurrency() {
247         boolean caught;
248 
249         CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER.convertToCashDrawer();
250         zeroDrawer.removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
251         assertCurrencyAmountsEqual(zeroDrawer, CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
252 
253         caught = false;
254         try {
255             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
256             nullDrawer.removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
257         }
258         catch (IllegalArgumentException iae) {
259             caught = true;
260         }
261         assertTrue("Null Drawer Hundred Dollar", caught);
262 
263         caught = false;
264         try {
265             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
266             nullDrawer.setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
267             nullDrawer.removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
268         }
269         catch (IllegalArgumentException iae) {
270             caught = true;
271         }
272         assertTrue("Null Drawer Fifty Dollar", caught);
273 
274         caught = false;
275         try {
276             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
277             nullDrawer.setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
278             nullDrawer.setFinancialDocumentFiftyDollarAmount(KualiDecimal.ZERO);
279             nullDrawer.removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
280         }
281         catch (IllegalArgumentException iae) {
282             caught = true;
283         }
284         assertTrue("Null Drawer Twenty Dollar", caught);
285 
286         caught = false;
287         try {
288             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
289             nullDrawer.setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
290             nullDrawer.setFinancialDocumentFiftyDollarAmount(KualiDecimal.ZERO);
291             nullDrawer.setFinancialDocumentTwentyDollarAmount(KualiDecimal.ZERO);
292             nullDrawer.removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
293         }
294         catch (IllegalArgumentException iae) {
295             caught = true;
296         }
297         assertTrue("Null Drawer Ten Dollar", caught);
298 
299         caught = false;
300         try {
301             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
302             nullDrawer.setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
303             nullDrawer.setFinancialDocumentFiftyDollarAmount(KualiDecimal.ZERO);
304             nullDrawer.setFinancialDocumentTwentyDollarAmount(KualiDecimal.ZERO);
305             nullDrawer.setFinancialDocumentTenDollarAmount(KualiDecimal.ZERO);
306             nullDrawer.removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
307         }
308         catch (IllegalArgumentException iae) {
309             caught = true;
310         }
311         assertTrue("Null Drawer Five Dollar", caught);
312 
313         caught = false;
314         try {
315             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
316             nullDrawer.setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
317             nullDrawer.setFinancialDocumentFiftyDollarAmount(KualiDecimal.ZERO);
318             nullDrawer.setFinancialDocumentTwentyDollarAmount(KualiDecimal.ZERO);
319             nullDrawer.setFinancialDocumentTenDollarAmount(KualiDecimal.ZERO);
320             nullDrawer.setFinancialDocumentFiveDollarAmount(KualiDecimal.ZERO);
321             nullDrawer.removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
322         }
323         catch (IllegalArgumentException iae) {
324             caught = true;
325         }
326         assertTrue("Null Drawer Two Dollar", caught);
327 
328         caught = false;
329         try {
330             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
331             nullDrawer.setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
332             nullDrawer.setFinancialDocumentFiftyDollarAmount(KualiDecimal.ZERO);
333             nullDrawer.setFinancialDocumentTwentyDollarAmount(KualiDecimal.ZERO);
334             nullDrawer.setFinancialDocumentTenDollarAmount(KualiDecimal.ZERO);
335             nullDrawer.setFinancialDocumentFiveDollarAmount(KualiDecimal.ZERO);
336             nullDrawer.setFinancialDocumentTwoDollarAmount(KualiDecimal.ZERO);
337             nullDrawer.removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
338         }
339         catch (IllegalArgumentException iae) {
340             caught = true;
341         }
342         assertTrue("Null Drawer One Dollar", caught);
343 
344         caught = false;
345         try {
346             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
347             nullDrawer.setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
348             nullDrawer.setFinancialDocumentFiftyDollarAmount(KualiDecimal.ZERO);
349             nullDrawer.setFinancialDocumentTwentyDollarAmount(KualiDecimal.ZERO);
350             nullDrawer.setFinancialDocumentTenDollarAmount(KualiDecimal.ZERO);
351             nullDrawer.setFinancialDocumentFiveDollarAmount(KualiDecimal.ZERO);
352             nullDrawer.setFinancialDocumentTwoDollarAmount(KualiDecimal.ZERO);
353             nullDrawer.setFinancialDocumentOneDollarAmount(KualiDecimal.ZERO);
354             nullDrawer.setFinancialDocumentOtherDollarAmount(KualiDecimal.ZERO);
355             nullDrawer.removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
356         }
357         catch (IllegalArgumentException iae) {
358             caught = true;
359         }
360         assertFalse("Null Drawer now all zeroes", caught);
361 
362         CashDrawer allFivesDrawerA = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
363         allFivesDrawerA.removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
364         assertCurrencyAmountsEqual(allFivesDrawerA, CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_FIVES_AMOUNT.convertToCurrencyDetail());
365 
366         CashDrawer allFivesDrawerB = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
367         allFivesDrawerB.removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.NULL_AMOUNT.convertToCurrencyDetail());
368         assertCurrencyAmountsEqual(allFivesDrawerB, CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_FIVES_AMOUNT.convertToCurrencyDetail());
369 
370         CashDrawer allFivesDrawerC = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
371         allFivesDrawerC.removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_FIVES_AMOUNT.convertToCurrencyDetail());
372         assertCurrencyAmountsEqual(allFivesDrawerC, CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT.convertToCurrencyDetail());
373         // test excessive currency (more currency requested than in drawer)
374 
375         CashDrawer allFivesDrawerD = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
376         CurrencyDetail excessiveDetail = CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_TENS_AMOUNT.convertToCurrencyDetail();
377 
378         caught = false;
379         try {
380             allFivesDrawerD.removeCurrency(excessiveDetail);
381         }
382         catch (IllegalArgumentException iae) {
383             caught = true;
384         }
385         assertTrue("Hundred Dollar", caught);
386         excessiveDetail.setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
387 
388         caught = false;
389         try {
390             allFivesDrawerD.removeCurrency(excessiveDetail);
391         }
392         catch (IllegalArgumentException iae) {
393             caught = true;
394         }
395         assertTrue("Fifty Dollar", caught);
396         excessiveDetail.setFinancialDocumentFiftyDollarAmount(KualiDecimal.ZERO);
397 
398         caught = false;
399         try {
400             allFivesDrawerD.removeCurrency(excessiveDetail);
401         }
402         catch (IllegalArgumentException iae) {
403             caught = true;
404         }
405         assertTrue("Twenty Dollar", caught);
406         excessiveDetail.setFinancialDocumentTwentyDollarAmount(KualiDecimal.ZERO);
407 
408         caught = false;
409         try {
410             allFivesDrawerD.removeCurrency(excessiveDetail);
411         }
412         catch (IllegalArgumentException iae) {
413             caught = true;
414         }
415         assertTrue("Ten Dollar", caught);
416         excessiveDetail.setFinancialDocumentTenDollarAmount(KualiDecimal.ZERO);
417 
418         caught = false;
419         try {
420             allFivesDrawerD.removeCurrency(excessiveDetail);
421         }
422         catch (IllegalArgumentException iae) {
423             caught = true;
424         }
425         assertTrue("Five Dollar", caught);
426         excessiveDetail.setFinancialDocumentFiveDollarAmount(KualiDecimal.ZERO);
427 
428         caught = false;
429         try {
430             allFivesDrawerD.removeCurrency(excessiveDetail);
431         }
432         catch (IllegalArgumentException iae) {
433             caught = true;
434         }
435         assertTrue("Two Dollar", caught);
436         excessiveDetail.setFinancialDocumentTwoDollarAmount(KualiDecimal.ZERO);
437 
438         caught = false;
439         try {
440             allFivesDrawerD.removeCurrency(excessiveDetail);
441         }
442         catch (IllegalArgumentException iae) {
443             caught = true;
444         }
445         assertTrue("One Dollar", caught);
446         excessiveDetail.setFinancialDocumentOneDollarAmount(KualiDecimal.ZERO);
447 
448         caught = false;
449         try {
450             allFivesDrawerD.removeCurrency(excessiveDetail);
451         }
452         catch (IllegalArgumentException iae) {
453             caught = true;
454         }
455         assertFalse("We should be good...", caught);
456     }
457 
458     public void testSubtractCoin() {
459         boolean caught;
460 
461         CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER.convertToCashDrawer();
462         zeroDrawer.removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
463         assertCoinAmountsEqual(zeroDrawer, CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
464 
465         caught = false;
466         try {
467             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
468             nullDrawer.removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
469         }
470         catch (IllegalArgumentException iae) {
471             caught = true;
472         }
473         assertTrue("null drawer hundred cent amount", caught);
474 
475         caught = false;
476         try {
477             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
478             nullDrawer.setFinancialDocumentHundredCentAmount(KualiDecimal.ZERO);
479             nullDrawer.removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
480         }
481         catch (IllegalArgumentException iae) {
482             caught = true;
483         }
484         assertTrue("null drawer fifty cent amount", caught);
485 
486         caught = false;
487         try {
488             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
489             nullDrawer.setFinancialDocumentHundredCentAmount(KualiDecimal.ZERO);
490             nullDrawer.setFinancialDocumentFiftyCentAmount(KualiDecimal.ZERO);
491             nullDrawer.removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
492         }
493         catch (IllegalArgumentException iae) {
494             caught = true;
495         }
496         assertTrue("null drawer twenty five cent amount", caught);
497 
498         caught = false;
499         try {
500             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
501             nullDrawer.setFinancialDocumentHundredCentAmount(KualiDecimal.ZERO);
502             nullDrawer.setFinancialDocumentFiftyCentAmount(KualiDecimal.ZERO);
503             nullDrawer.setFinancialDocumentTwentyFiveCentAmount(KualiDecimal.ZERO);
504             nullDrawer.removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
505         }
506         catch (IllegalArgumentException iae) {
507             caught = true;
508         }
509         assertTrue("null drawer ten cent amount", caught);
510 
511         caught = false;
512         try {
513             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
514             nullDrawer.setFinancialDocumentHundredCentAmount(KualiDecimal.ZERO);
515             nullDrawer.setFinancialDocumentFiftyCentAmount(KualiDecimal.ZERO);
516             nullDrawer.setFinancialDocumentTwentyFiveCentAmount(KualiDecimal.ZERO);
517             nullDrawer.setFinancialDocumentTenCentAmount(KualiDecimal.ZERO);
518             nullDrawer.removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
519         }
520         catch (IllegalArgumentException iae) {
521             caught = true;
522         }
523         assertTrue("null drawer five cent amount", caught);
524 
525         caught = false;
526         try {
527             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
528             nullDrawer.setFinancialDocumentHundredCentAmount(KualiDecimal.ZERO);
529             nullDrawer.setFinancialDocumentFiftyCentAmount(KualiDecimal.ZERO);
530             nullDrawer.setFinancialDocumentTwentyFiveCentAmount(KualiDecimal.ZERO);
531             nullDrawer.setFinancialDocumentTenCentAmount(KualiDecimal.ZERO);
532             nullDrawer.setFinancialDocumentFiveCentAmount(KualiDecimal.ZERO);
533             nullDrawer.removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
534         }
535         catch (IllegalArgumentException iae) {
536             caught = true;
537         }
538         assertTrue("null drawer one cent amount", caught);
539 
540         caught = false;
541         try {
542             CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER.convertToCashDrawer();
543             nullDrawer.setFinancialDocumentHundredCentAmount(KualiDecimal.ZERO);
544             nullDrawer.setFinancialDocumentFiftyCentAmount(KualiDecimal.ZERO);
545             nullDrawer.setFinancialDocumentTwentyFiveCentAmount(KualiDecimal.ZERO);
546             nullDrawer.setFinancialDocumentTenCentAmount(KualiDecimal.ZERO);
547             nullDrawer.setFinancialDocumentFiveCentAmount(KualiDecimal.ZERO);
548             nullDrawer.setFinancialDocumentOneCentAmount(KualiDecimal.ZERO);
549             nullDrawer.setFinancialDocumentOtherCentAmount(KualiDecimal.ZERO);
550             nullDrawer.removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
551         }
552         catch (IllegalArgumentException iae) {
553             caught = true;
554             iae.printStackTrace();
555         }
556         assertFalse("null drawer all is now zero", caught);
557 
558         CashDrawer allFivesDrawerA = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
559         allFivesDrawerA.removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
560         assertCoinAmountsEqual(allFivesDrawerA, CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT.convertToCoinDetail());
561 
562         CashDrawer allFivesDrawerB = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
563         allFivesDrawerB.removeCoin(CoinDetailTest.CoinDetailAmountFixture.NULL_COIN_AMOUNT.convertToCoinDetail());
564         assertCoinAmountsEqual(allFivesDrawerB, CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT.convertToCoinDetail());
565 
566         CashDrawer allFivesDrawerC = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
567         allFivesDrawerC.removeCoin(CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT.convertToCoinDetail());
568         assertCoinAmountsEqual(allFivesDrawerC, CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT.convertToCoinDetail());
569 
570         // test excessive coin (more coin requested than in drawer)
571         CoinDetail excessiveDetail = CoinDetailTest.CoinDetailAmountFixture.ALL_TENS_COIN_AMOUNT.convertToCoinDetail();
572         CashDrawer allFivesDrawerD = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER.convertToCashDrawer();
573 
574         caught = false;
575         try {
576             allFivesDrawerD.removeCoin(excessiveDetail);
577         }
578         catch (IllegalArgumentException iae) {
579             caught = true;
580         }
581         assertTrue("Hundred Cent", caught);
582         excessiveDetail.setFinancialDocumentHundredCentAmount(KualiDecimal.ZERO);
583 
584         caught = false;
585         try {
586             allFivesDrawerD.removeCoin(excessiveDetail);
587         }
588         catch (IllegalArgumentException iae) {
589             caught = true;
590         }
591         assertTrue("Fifty Cent", caught);
592         excessiveDetail.setFinancialDocumentFiftyCentAmount(KualiDecimal.ZERO);
593 
594         caught = false;
595         try {
596             allFivesDrawerD.removeCoin(excessiveDetail);
597         }
598         catch (IllegalArgumentException iae) {
599             caught = true;
600         }
601         assertTrue("Twenty Five Cent", caught);
602         excessiveDetail.setFinancialDocumentTwentyFiveCentAmount(KualiDecimal.ZERO);
603 
604         caught = false;
605         try {
606             allFivesDrawerD.removeCoin(excessiveDetail);
607         }
608         catch (IllegalArgumentException iae) {
609             caught = true;
610         }
611         assertTrue("Ten Cent", caught);
612         excessiveDetail.setFinancialDocumentTenCentAmount(KualiDecimal.ZERO);
613 
614         caught = false;
615         try {
616             allFivesDrawerD.removeCoin(excessiveDetail);
617         }
618         catch (IllegalArgumentException iae) {
619             caught = true;
620         }
621         assertTrue("Five Cent", caught);
622         excessiveDetail.setFinancialDocumentFiveCentAmount(KualiDecimal.ZERO);
623 
624         caught = false;
625         try {
626             allFivesDrawerD.removeCoin(excessiveDetail);
627         }
628         catch (IllegalArgumentException iae) {
629             caught = true;
630         }
631         assertTrue("One Cent", caught);
632         excessiveDetail.setFinancialDocumentOneCentAmount(KualiDecimal.ZERO);
633 
634         caught = false;
635         try {
636             allFivesDrawerD.removeCoin(excessiveDetail);
637         }
638         catch (IllegalArgumentException iae) {
639             caught = true;
640         }
641         assertFalse("We should be good....", caught);
642     }
643 
644     private void assertCurrencyAmountsEqual(CashDrawer drawer, CurrencyDetail detail) {
645         assertEquals(drawer.getFinancialDocumentHundredDollarAmount(), detail.getFinancialDocumentHundredDollarAmount());
646         assertEquals(drawer.getFinancialDocumentFiftyDollarAmount(), detail.getFinancialDocumentFiftyDollarAmount());
647         assertEquals(drawer.getFinancialDocumentTwentyDollarAmount(), detail.getFinancialDocumentTwentyDollarAmount());
648         assertEquals(drawer.getFinancialDocumentTenDollarAmount(), detail.getFinancialDocumentTenDollarAmount());
649         assertEquals(drawer.getFinancialDocumentFiveDollarAmount(), detail.getFinancialDocumentFiveDollarAmount());
650         assertEquals(drawer.getFinancialDocumentTwoDollarAmount(), detail.getFinancialDocumentTwoDollarAmount());
651         assertEquals(drawer.getFinancialDocumentOneDollarAmount(), detail.getFinancialDocumentOneDollarAmount());
652     }
653 
654     private void assertCoinAmountsEqual(CashDrawer drawer, CoinDetail detail) {
655         assertEquals(drawer.getFinancialDocumentHundredCentAmount(), detail.getFinancialDocumentHundredCentAmount());
656         assertEquals(drawer.getFinancialDocumentFiftyCentAmount(), detail.getFinancialDocumentFiftyCentAmount());
657         assertEquals(drawer.getFinancialDocumentTwentyFiveCentAmount(), detail.getFinancialDocumentTwentyFiveCentAmount());
658         assertEquals(drawer.getFinancialDocumentTenCentAmount(), detail.getFinancialDocumentTenCentAmount());
659         assertEquals(drawer.getFinancialDocumentFiveCentAmount(), detail.getFinancialDocumentFiveCentAmount());
660         assertEquals(drawer.getFinancialDocumentOneCentAmount(), detail.getFinancialDocumentOneCentAmount());
661     }
662 }