001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.financial.bo;
017:
018: import org.kuali.core.util.KualiDecimal;
019: import org.kuali.kfs.context.KualiTestBase;
020:
021: public class CashDrawerTest extends KualiTestBase {
022: public enum CashDrawerAmountFixture {
023: GOOD_CASH_DRAWER(500.0, 250.0, 100.0, 50.0, 25.0, 10.0, 5.0,
024: 5.0, 5.0, 2.5, 1.25, 0.5, 0.25, 0.05, 0.5), ALL_FIVES_CASH_DRAWER(
025: 500.0, 500.0, 500.0, 500.0, 500.0, 500.0, 500.0, 500.0,
026: 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00), ALL_SEVENS_CASH_DRAWER(
027: 700.0, 700.0, 700.0, 700.0, 700.0, 700.0, 700.0, 700.0,
028: 7.00, 7.00, 7.00, 7.00, 7.00, 7.00, 7.00), ZERO_CASH_DRAWER(
029: 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
030: 0.0, 0.0, 0.0, 0.0), NULL_CASH_DRAWER;
031:
032: private KualiDecimal hundredDollarAmount;
033: private KualiDecimal fiftyDollarAmount;
034: private KualiDecimal twentyDollarAmount;
035: private KualiDecimal tenDollarAmount;
036: private KualiDecimal fiveDollarAmount;
037: private KualiDecimal twoDollarAmount;
038: private KualiDecimal oneDollarAmount;
039: private KualiDecimal otherDollarAmount;
040: private KualiDecimal hundredCentAmount;
041: private KualiDecimal fiftyCentAmount;
042: private KualiDecimal twentyFiveCentAmount;
043: private KualiDecimal tenCentAmount;
044: private KualiDecimal fiveCentAmount;
045: private KualiDecimal oneCentAmount;
046: private KualiDecimal otherCentAmount;
047:
048: private CashDrawerAmountFixture() {
049: }
050:
051: private CashDrawerAmountFixture(double hundredDollarAmount,
052: double fiftyDollarAmount, double twentyDollarAmount,
053: double tenDollarAmount, double fiveDollarAmount,
054: double twoDollarAmount, double oneDollarAmount,
055: double otherDollarAmount, double hundredCentAmount,
056: double fiftyCentAmount, double twentyFiveCentAmount,
057: double tenCentAmount, double fiveCentAmount,
058: double oneCentAmount, double otherCentAmount) {
059: this .hundredDollarAmount = new KualiDecimal(
060: hundredDollarAmount);
061: this .fiftyDollarAmount = new KualiDecimal(fiftyDollarAmount);
062: this .twentyDollarAmount = new KualiDecimal(
063: twentyDollarAmount);
064: this .tenDollarAmount = new KualiDecimal(tenDollarAmount);
065: this .fiveDollarAmount = new KualiDecimal(fiveDollarAmount);
066: this .twoDollarAmount = new KualiDecimal(twoDollarAmount);
067: this .oneDollarAmount = new KualiDecimal(oneDollarAmount);
068: this .otherDollarAmount = new KualiDecimal(otherDollarAmount);
069: this .hundredCentAmount = new KualiDecimal(hundredCentAmount);
070: this .fiftyCentAmount = new KualiDecimal(fiftyCentAmount);
071: this .twentyFiveCentAmount = new KualiDecimal(
072: twentyFiveCentAmount);
073: this .tenCentAmount = new KualiDecimal(tenCentAmount);
074: this .fiveCentAmount = new KualiDecimal(fiveCentAmount);
075: this .oneCentAmount = new KualiDecimal(oneCentAmount);
076: this .otherCentAmount = new KualiDecimal(otherCentAmount);
077: }
078:
079: public CashDrawer convertToCashDrawer() {
080: CashDrawer drawer = new CashDrawer();
081: drawer
082: .setFinancialDocumentHundredDollarAmount(this .hundredDollarAmount);
083: drawer
084: .setFinancialDocumentFiftyDollarAmount(this .fiftyDollarAmount);
085: drawer
086: .setFinancialDocumentTwentyDollarAmount(this .twentyDollarAmount);
087: drawer
088: .setFinancialDocumentTenDollarAmount(this .tenDollarAmount);
089: drawer
090: .setFinancialDocumentFiveDollarAmount(this .fiveDollarAmount);
091: drawer
092: .setFinancialDocumentTwoDollarAmount(this .twoDollarAmount);
093: drawer
094: .setFinancialDocumentOneDollarAmount(this .oneDollarAmount);
095: drawer
096: .setFinancialDocumentOtherDollarAmount(this .otherDollarAmount);
097: drawer
098: .setFinancialDocumentHundredCentAmount(this .hundredCentAmount);
099: drawer
100: .setFinancialDocumentFiftyCentAmount(this .fiftyCentAmount);
101: drawer
102: .setFinancialDocumentTwentyFiveCentAmount(this .twentyFiveCentAmount);
103: drawer
104: .setFinancialDocumentTenCentAmount(this .tenCentAmount);
105: drawer
106: .setFinancialDocumentFiveCentAmount(this .fiveCentAmount);
107: drawer
108: .setFinancialDocumentOneCentAmount(this .oneCentAmount);
109: drawer
110: .setFinancialDocumentOtherCentAmount(this .otherCentAmount);
111: return drawer;
112: }
113: }
114:
115: public enum CashDrawerCountFixture {
116: GOOD_CASH_DRAWER(new Integer(5), new Integer(10), new Integer(
117: 25), new Integer(50), new Integer(100),
118: new Integer(250), new Integer(500), new Integer(5),
119: new Integer(10), new Integer(20), new Integer(50),
120: new Integer(100), new Integer(500)), ALL_FIVES_CASH_DRAWER(
121: new Integer(5), new Integer(5), new Integer(5),
122: new Integer(5), new Integer(5), new Integer(5),
123: new Integer(5), new Integer(5), new Integer(5),
124: new Integer(5), new Integer(5), new Integer(5),
125: new Integer(5)), ZERO_CASH_DRAWER(new Integer(0),
126: new Integer(0), new Integer(0), new Integer(0),
127: new Integer(0), new Integer(0), new Integer(0),
128: new Integer(0), new Integer(0), new Integer(0),
129: new Integer(0), new Integer(0), new Integer(0)), NULL_CASH_DRAWER;
130:
131: private Integer hundredDollarCount;
132: private Integer fiftyDollarCount;
133: private Integer twentyDollarCount;
134: private Integer tenDollarCount;
135: private Integer fiveDollarCount;
136: private Integer twoDollarCount;
137: private Integer oneDollarCount;
138: private Integer hundredCentCount;
139: private Integer fiftyCentCount;
140: private Integer twentyFiveCentCount;
141: private Integer tenCentCount;
142: private Integer fiveCentCount;
143: private Integer oneCentCount;
144:
145: private CashDrawerCountFixture() {
146: }
147:
148: private CashDrawerCountFixture(Integer hundredDollarCount,
149: Integer fiftyDollarCount, Integer twentyDollarCount,
150: Integer tenDollarCount, Integer fiveDollarCount,
151: Integer twoDollarCount, Integer oneDollarCount,
152: Integer hundredCentCount, Integer fiftyCentCount,
153: Integer twentyFiveCentCount, Integer tenCentCount,
154: Integer fiveCentCount, Integer oneCentCount) {
155: this .hundredDollarCount = hundredDollarCount;
156: this .fiftyDollarCount = fiftyDollarCount;
157: this .twentyDollarCount = twentyDollarCount;
158: this .tenDollarCount = tenDollarCount;
159: this .fiveDollarCount = fiveDollarCount;
160: this .twoDollarCount = twoDollarCount;
161: this .oneDollarCount = oneDollarCount;
162: this .hundredCentCount = hundredCentCount;
163: this .fiftyCentCount = fiftyCentCount;
164: this .twentyFiveCentCount = twentyFiveCentCount;
165: this .tenCentCount = tenCentCount;
166: this .fiveCentCount = fiveCentCount;
167: this .oneCentCount = oneCentCount;
168: }
169:
170: public CashDrawer convertToCashDrawer() {
171: CashDrawer drawer = new CashDrawer();
172: drawer.setHundredDollarCount(this .hundredDollarCount);
173: drawer.setFiftyDollarCount(this .fiftyDollarCount);
174: drawer.setTwentyDollarCount(this .twentyDollarCount);
175: drawer.setTenDollarCount(this .tenDollarCount);
176: drawer.setFiveDollarCount(this .fiveDollarCount);
177: drawer.setTwoDollarCount(this .twoDollarCount);
178: drawer.setOneDollarCount(this .oneDollarCount);
179: drawer.setHundredCentCount(this .hundredCentCount);
180: drawer.setFiftyCentCount(this .fiftyCentCount);
181: drawer.setTwentyFiveCentCount(this .twentyFiveCentCount);
182: drawer.setTenCentCount(this .tenCentCount);
183: drawer.setFiveCentCount(this .fiveCentCount);
184: drawer.setOneCentCount(this .oneCentCount);
185: return drawer;
186: }
187: }
188:
189: public void testAmountToCount() {
190: CashDrawer drawer = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
191: .convertToCashDrawer();
192: assertEquals(drawer.getHundredDollarCount(), new Integer(5));
193: assertEquals(drawer.getFiftyDollarCount(), new Integer(10));
194: assertEquals(drawer.getTwentyDollarCount(), new Integer(25));
195: assertEquals(drawer.getTenDollarCount(), new Integer(50));
196: assertEquals(drawer.getFiveDollarCount(), new Integer(100));
197: assertEquals(drawer.getTwoDollarCount(), new Integer(250));
198: assertEquals(drawer.getOneDollarCount(), new Integer(500));
199: assertEquals(drawer.getHundredCentCount(), new Integer(5));
200: assertEquals(drawer.getFiftyCentCount(), new Integer(10));
201: assertEquals(drawer.getTwentyFiveCentCount(), new Integer(20));
202: assertEquals(drawer.getTenCentCount(), new Integer(50));
203: assertEquals(drawer.getFiveCentCount(), new Integer(100));
204: assertEquals(drawer.getOneCentCount(), new Integer(500));
205: }
206:
207: public void testCountToAmount() {
208: CashDrawer drawer = CashDrawerCountFixture.ALL_FIVES_CASH_DRAWER
209: .convertToCashDrawer();
210: assertEquals(drawer.getFinancialDocumentHundredDollarAmount(),
211: new KualiDecimal(500.0));
212: assertEquals(drawer.getFinancialDocumentFiftyDollarAmount(),
213: new KualiDecimal(250.0));
214: assertEquals(drawer.getFinancialDocumentTwentyDollarAmount(),
215: new KualiDecimal(100.0));
216: assertEquals(drawer.getFinancialDocumentTenDollarAmount(),
217: new KualiDecimal(50.0));
218: assertEquals(drawer.getFinancialDocumentFiveDollarAmount(),
219: new KualiDecimal(25.0));
220: assertEquals(drawer.getFinancialDocumentTwoDollarAmount(),
221: new KualiDecimal(10.0));
222: assertEquals(drawer.getFinancialDocumentOneDollarAmount(),
223: new KualiDecimal(5.0));
224: assertEquals(drawer.getFinancialDocumentHundredCentAmount(),
225: new KualiDecimal(5.0));
226: assertEquals(drawer.getFinancialDocumentFiftyCentAmount(),
227: new KualiDecimal(2.5));
228: assertEquals(drawer.getFinancialDocumentTwentyFiveCentAmount(),
229: new KualiDecimal(1.25));
230: assertEquals(drawer.getFinancialDocumentTenCentAmount(),
231: new KualiDecimal(0.5));
232: assertEquals(drawer.getFinancialDocumentFiveCentAmount(),
233: new KualiDecimal(0.25));
234: assertEquals(drawer.getFinancialDocumentOneCentAmount(),
235: new KualiDecimal(0.05));
236: }
237:
238: public void testCurrencyTotal() {
239: CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER
240: .convertToCashDrawer();
241: assertEquals(zeroDrawer.getCurrencyTotalAmount(),
242: new KualiDecimal(0));
243: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
244: .convertToCashDrawer();
245: assertEquals(nullDrawer.getCurrencyTotalAmount(),
246: new KualiDecimal(0));
247: CashDrawer goodDrawer = CashDrawerAmountFixture.GOOD_CASH_DRAWER
248: .convertToCashDrawer();
249: assertEquals(goodDrawer.getCurrencyTotalAmount(),
250: new KualiDecimal(945));
251: }
252:
253: public void testCoinTotal() {
254: CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER
255: .convertToCashDrawer();
256: assertEquals(zeroDrawer.getCoinTotalAmount(), new KualiDecimal(
257: 0));
258: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
259: .convertToCashDrawer();
260: assertEquals(nullDrawer.getCoinTotalAmount(), new KualiDecimal(
261: 0));
262: CashDrawer goodDrawer = CashDrawerAmountFixture.GOOD_CASH_DRAWER
263: .convertToCashDrawer();
264: assertEquals(goodDrawer.getCoinTotalAmount(), new KualiDecimal(
265: 10.05));
266: }
267:
268: public void testDrawerTotal() {
269: CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER
270: .convertToCashDrawer();
271: assertEquals(zeroDrawer.getTotalAmount(), new KualiDecimal(0));
272: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
273: .convertToCashDrawer();
274: assertEquals(nullDrawer.getTotalAmount(), new KualiDecimal(0));
275: CashDrawer goodDrawer = CashDrawerAmountFixture.GOOD_CASH_DRAWER
276: .convertToCashDrawer();
277: assertEquals(goodDrawer.getTotalAmount(), new KualiDecimal(
278: 955.05));
279: }
280:
281: public void testAddCurrency() {
282: CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER
283: .convertToCashDrawer();
284: zeroDrawer
285: .addCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
286: .convertToCurrencyDetail());
287: assertCurrencyAmountsEqual(
288: zeroDrawer,
289: CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
290: .convertToCurrencyDetail());
291:
292: CashDrawer nullDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER
293: .convertToCashDrawer();
294: nullDrawer
295: .addCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.GOOD_POSITIVE_AMOUNT
296: .convertToCurrencyDetail());
297: assertCurrencyAmountsEqual(
298: nullDrawer,
299: CurrencyDetailTest.CurrencyDetailAmountFixture.GOOD_POSITIVE_AMOUNT
300: .convertToCurrencyDetail());
301:
302: CashDrawer allFivesDrawerA = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
303: .convertToCashDrawer();
304: allFivesDrawerA
305: .addCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
306: .convertToCurrencyDetail());
307: assertCurrencyAmountsEqual(
308: allFivesDrawerA,
309: CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_FIVES_AMOUNT
310: .convertToCurrencyDetail());
311:
312: CashDrawer allFivesDrawerB = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
313: .convertToCashDrawer();
314: allFivesDrawerB
315: .addCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.NULL_AMOUNT
316: .convertToCurrencyDetail());
317: assertCurrencyAmountsEqual(
318: allFivesDrawerB,
319: CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_FIVES_AMOUNT
320: .convertToCurrencyDetail());
321:
322: CashDrawer allFivesDrawerC = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
323: .convertToCashDrawer();
324: allFivesDrawerC
325: .addCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_FIVES_AMOUNT
326: .convertToCurrencyDetail());
327: assertCurrencyAmountsEqual(
328: allFivesDrawerC,
329: CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_TENS_AMOUNT
330: .convertToCurrencyDetail());
331: }
332:
333: public void testAddCoin() {
334: CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER
335: .convertToCashDrawer();
336: zeroDrawer
337: .addCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
338: .convertToCoinDetail());
339: assertCoinAmountsEqual(zeroDrawer,
340: CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
341: .convertToCoinDetail());
342:
343: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
344: .convertToCashDrawer();
345: nullDrawer
346: .addCoin(CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT
347: .convertToCoinDetail());
348: assertCoinAmountsEqual(
349: nullDrawer,
350: CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT
351: .convertToCoinDetail());
352:
353: CashDrawer allFivesDrawerA = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
354: .convertToCashDrawer();
355: allFivesDrawerA
356: .addCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
357: .convertToCoinDetail());
358: assertCoinAmountsEqual(
359: allFivesDrawerA,
360: CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT
361: .convertToCoinDetail());
362:
363: CashDrawer allFivesDrawerB = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
364: .convertToCashDrawer();
365: allFivesDrawerB
366: .addCoin(CoinDetailTest.CoinDetailAmountFixture.NULL_COIN_AMOUNT
367: .convertToCoinDetail());
368: assertCoinAmountsEqual(
369: allFivesDrawerB,
370: CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT
371: .convertToCoinDetail());
372:
373: CashDrawer allFivesDrawerC = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
374: .convertToCashDrawer();
375: allFivesDrawerC
376: .addCoin(CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT
377: .convertToCoinDetail());
378: assertCoinAmountsEqual(
379: allFivesDrawerC,
380: CoinDetailTest.CoinDetailAmountFixture.ALL_TENS_COIN_AMOUNT
381: .convertToCoinDetail());
382: }
383:
384: public void testSubtractCurrency() {
385: boolean caught;
386:
387: CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER
388: .convertToCashDrawer();
389: zeroDrawer
390: .removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
391: .convertToCurrencyDetail());
392: assertCurrencyAmountsEqual(
393: zeroDrawer,
394: CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
395: .convertToCurrencyDetail());
396:
397: caught = false;
398: try {
399: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
400: .convertToCashDrawer();
401: nullDrawer
402: .removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
403: .convertToCurrencyDetail());
404: } catch (IllegalArgumentException iae) {
405: caught = true;
406: }
407: assertTrue("Null Drawer Hundred Dollar", caught);
408:
409: caught = false;
410: try {
411: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
412: .convertToCashDrawer();
413: nullDrawer
414: .setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
415: nullDrawer
416: .removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
417: .convertToCurrencyDetail());
418: } catch (IllegalArgumentException iae) {
419: caught = true;
420: }
421: assertTrue("Null Drawer Fifty Dollar", caught);
422:
423: caught = false;
424: try {
425: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
426: .convertToCashDrawer();
427: nullDrawer
428: .setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
429: nullDrawer
430: .setFinancialDocumentFiftyDollarAmount(KualiDecimal.ZERO);
431: nullDrawer
432: .removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
433: .convertToCurrencyDetail());
434: } catch (IllegalArgumentException iae) {
435: caught = true;
436: }
437: assertTrue("Null Drawer Twenty Dollar", caught);
438:
439: caught = false;
440: try {
441: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
442: .convertToCashDrawer();
443: nullDrawer
444: .setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
445: nullDrawer
446: .setFinancialDocumentFiftyDollarAmount(KualiDecimal.ZERO);
447: nullDrawer
448: .setFinancialDocumentTwentyDollarAmount(KualiDecimal.ZERO);
449: nullDrawer
450: .removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
451: .convertToCurrencyDetail());
452: } catch (IllegalArgumentException iae) {
453: caught = true;
454: }
455: assertTrue("Null Drawer Ten Dollar", caught);
456:
457: caught = false;
458: try {
459: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
460: .convertToCashDrawer();
461: nullDrawer
462: .setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
463: nullDrawer
464: .setFinancialDocumentFiftyDollarAmount(KualiDecimal.ZERO);
465: nullDrawer
466: .setFinancialDocumentTwentyDollarAmount(KualiDecimal.ZERO);
467: nullDrawer
468: .setFinancialDocumentTenDollarAmount(KualiDecimal.ZERO);
469: nullDrawer
470: .removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
471: .convertToCurrencyDetail());
472: } catch (IllegalArgumentException iae) {
473: caught = true;
474: }
475: assertTrue("Null Drawer Five Dollar", caught);
476:
477: caught = false;
478: try {
479: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
480: .convertToCashDrawer();
481: nullDrawer
482: .setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
483: nullDrawer
484: .setFinancialDocumentFiftyDollarAmount(KualiDecimal.ZERO);
485: nullDrawer
486: .setFinancialDocumentTwentyDollarAmount(KualiDecimal.ZERO);
487: nullDrawer
488: .setFinancialDocumentTenDollarAmount(KualiDecimal.ZERO);
489: nullDrawer
490: .setFinancialDocumentFiveDollarAmount(KualiDecimal.ZERO);
491: nullDrawer
492: .removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
493: .convertToCurrencyDetail());
494: } catch (IllegalArgumentException iae) {
495: caught = true;
496: }
497: assertTrue("Null Drawer Two Dollar", caught);
498:
499: caught = false;
500: try {
501: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
502: .convertToCashDrawer();
503: nullDrawer
504: .setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
505: nullDrawer
506: .setFinancialDocumentFiftyDollarAmount(KualiDecimal.ZERO);
507: nullDrawer
508: .setFinancialDocumentTwentyDollarAmount(KualiDecimal.ZERO);
509: nullDrawer
510: .setFinancialDocumentTenDollarAmount(KualiDecimal.ZERO);
511: nullDrawer
512: .setFinancialDocumentFiveDollarAmount(KualiDecimal.ZERO);
513: nullDrawer
514: .setFinancialDocumentTwoDollarAmount(KualiDecimal.ZERO);
515: nullDrawer
516: .removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
517: .convertToCurrencyDetail());
518: } catch (IllegalArgumentException iae) {
519: caught = true;
520: }
521: assertTrue("Null Drawer One Dollar", caught);
522:
523: caught = false;
524: try {
525: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
526: .convertToCashDrawer();
527: nullDrawer
528: .setFinancialDocumentHundredDollarAmount(KualiDecimal.ZERO);
529: nullDrawer
530: .setFinancialDocumentFiftyDollarAmount(KualiDecimal.ZERO);
531: nullDrawer
532: .setFinancialDocumentTwentyDollarAmount(KualiDecimal.ZERO);
533: nullDrawer
534: .setFinancialDocumentTenDollarAmount(KualiDecimal.ZERO);
535: nullDrawer
536: .setFinancialDocumentFiveDollarAmount(KualiDecimal.ZERO);
537: nullDrawer
538: .setFinancialDocumentTwoDollarAmount(KualiDecimal.ZERO);
539: nullDrawer
540: .setFinancialDocumentOneDollarAmount(KualiDecimal.ZERO);
541: nullDrawer
542: .setFinancialDocumentOtherDollarAmount(KualiDecimal.ZERO);
543: nullDrawer
544: .removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
545: .convertToCurrencyDetail());
546: } catch (IllegalArgumentException iae) {
547: caught = true;
548: }
549: assertFalse("Null Drawer now all zeroes", caught);
550:
551: CashDrawer allFivesDrawerA = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
552: .convertToCashDrawer();
553: allFivesDrawerA
554: .removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
555: .convertToCurrencyDetail());
556: assertCurrencyAmountsEqual(
557: allFivesDrawerA,
558: CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_FIVES_AMOUNT
559: .convertToCurrencyDetail());
560:
561: CashDrawer allFivesDrawerB = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
562: .convertToCashDrawer();
563: allFivesDrawerB
564: .removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.NULL_AMOUNT
565: .convertToCurrencyDetail());
566: assertCurrencyAmountsEqual(
567: allFivesDrawerB,
568: CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_FIVES_AMOUNT
569: .convertToCurrencyDetail());
570:
571: CashDrawer allFivesDrawerC = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
572: .convertToCashDrawer();
573: allFivesDrawerC
574: .removeCurrency(CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_FIVES_AMOUNT
575: .convertToCurrencyDetail());
576: assertCurrencyAmountsEqual(
577: allFivesDrawerC,
578: CurrencyDetailTest.CurrencyDetailAmountFixture.ZERO_AMOUNT
579: .convertToCurrencyDetail());
580: // test excessive currency (more currency requested than in drawer)
581:
582: CashDrawer allFivesDrawerD = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
583: .convertToCashDrawer();
584: CurrencyDetail excessiveDetail = CurrencyDetailTest.CurrencyDetailAmountFixture.ALL_TENS_AMOUNT
585: .convertToCurrencyDetail();
586:
587: caught = false;
588: try {
589: allFivesDrawerD.removeCurrency(excessiveDetail);
590: } catch (IllegalArgumentException iae) {
591: caught = true;
592: }
593: assertTrue("Hundred Dollar", caught);
594: excessiveDetail
595: .setFinancialDocumentHundredDollarAmount(new KualiDecimal(
596: 0));
597:
598: caught = false;
599: try {
600: allFivesDrawerD.removeCurrency(excessiveDetail);
601: } catch (IllegalArgumentException iae) {
602: caught = true;
603: }
604: assertTrue("Fifty Dollar", caught);
605: excessiveDetail
606: .setFinancialDocumentFiftyDollarAmount(new KualiDecimal(
607: 0));
608:
609: caught = false;
610: try {
611: allFivesDrawerD.removeCurrency(excessiveDetail);
612: } catch (IllegalArgumentException iae) {
613: caught = true;
614: }
615: assertTrue("Twenty Dollar", caught);
616: excessiveDetail
617: .setFinancialDocumentTwentyDollarAmount(new KualiDecimal(
618: 0));
619:
620: caught = false;
621: try {
622: allFivesDrawerD.removeCurrency(excessiveDetail);
623: } catch (IllegalArgumentException iae) {
624: caught = true;
625: }
626: assertTrue("Ten Dollar", caught);
627: excessiveDetail
628: .setFinancialDocumentTenDollarAmount(new KualiDecimal(0));
629:
630: caught = false;
631: try {
632: allFivesDrawerD.removeCurrency(excessiveDetail);
633: } catch (IllegalArgumentException iae) {
634: caught = true;
635: }
636: assertTrue("Five Dollar", caught);
637: excessiveDetail
638: .setFinancialDocumentFiveDollarAmount(new KualiDecimal(
639: 0));
640:
641: caught = false;
642: try {
643: allFivesDrawerD.removeCurrency(excessiveDetail);
644: } catch (IllegalArgumentException iae) {
645: caught = true;
646: }
647: assertTrue("Two Dollar", caught);
648: excessiveDetail
649: .setFinancialDocumentTwoDollarAmount(new KualiDecimal(0));
650:
651: caught = false;
652: try {
653: allFivesDrawerD.removeCurrency(excessiveDetail);
654: } catch (IllegalArgumentException iae) {
655: caught = true;
656: }
657: assertTrue("One Dollar", caught);
658: excessiveDetail
659: .setFinancialDocumentOneDollarAmount(new KualiDecimal(0));
660:
661: caught = false;
662: try {
663: allFivesDrawerD.removeCurrency(excessiveDetail);
664: } catch (IllegalArgumentException iae) {
665: caught = true;
666: }
667: assertFalse("We should be good...", caught);
668: }
669:
670: public void testSubtractCoin() {
671: boolean caught;
672:
673: CashDrawer zeroDrawer = CashDrawerAmountFixture.ZERO_CASH_DRAWER
674: .convertToCashDrawer();
675: zeroDrawer
676: .removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
677: .convertToCoinDetail());
678: assertCoinAmountsEqual(zeroDrawer,
679: CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
680: .convertToCoinDetail());
681:
682: caught = false;
683: try {
684: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
685: .convertToCashDrawer();
686: nullDrawer
687: .removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
688: .convertToCoinDetail());
689: } catch (IllegalArgumentException iae) {
690: caught = true;
691: }
692: assertTrue("null drawer hundred cent amount", caught);
693:
694: caught = false;
695: try {
696: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
697: .convertToCashDrawer();
698: nullDrawer
699: .setFinancialDocumentHundredCentAmount(KualiDecimal.ZERO);
700: nullDrawer
701: .removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
702: .convertToCoinDetail());
703: } catch (IllegalArgumentException iae) {
704: caught = true;
705: }
706: assertTrue("null drawer fifty cent amount", caught);
707:
708: caught = false;
709: try {
710: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
711: .convertToCashDrawer();
712: nullDrawer
713: .setFinancialDocumentHundredCentAmount(KualiDecimal.ZERO);
714: nullDrawer
715: .setFinancialDocumentFiftyCentAmount(KualiDecimal.ZERO);
716: nullDrawer
717: .removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
718: .convertToCoinDetail());
719: } catch (IllegalArgumentException iae) {
720: caught = true;
721: }
722: assertTrue("null drawer twenty five cent amount", caught);
723:
724: caught = false;
725: try {
726: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
727: .convertToCashDrawer();
728: nullDrawer
729: .setFinancialDocumentHundredCentAmount(KualiDecimal.ZERO);
730: nullDrawer
731: .setFinancialDocumentFiftyCentAmount(KualiDecimal.ZERO);
732: nullDrawer
733: .setFinancialDocumentTwentyFiveCentAmount(KualiDecimal.ZERO);
734: nullDrawer
735: .removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
736: .convertToCoinDetail());
737: } catch (IllegalArgumentException iae) {
738: caught = true;
739: }
740: assertTrue("null drawer ten cent amount", caught);
741:
742: caught = false;
743: try {
744: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
745: .convertToCashDrawer();
746: nullDrawer
747: .setFinancialDocumentHundredCentAmount(KualiDecimal.ZERO);
748: nullDrawer
749: .setFinancialDocumentFiftyCentAmount(KualiDecimal.ZERO);
750: nullDrawer
751: .setFinancialDocumentTwentyFiveCentAmount(KualiDecimal.ZERO);
752: nullDrawer
753: .setFinancialDocumentTenCentAmount(KualiDecimal.ZERO);
754: nullDrawer
755: .removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
756: .convertToCoinDetail());
757: } catch (IllegalArgumentException iae) {
758: caught = true;
759: }
760: assertTrue("null drawer five cent amount", caught);
761:
762: caught = false;
763: try {
764: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
765: .convertToCashDrawer();
766: nullDrawer
767: .setFinancialDocumentHundredCentAmount(KualiDecimal.ZERO);
768: nullDrawer
769: .setFinancialDocumentFiftyCentAmount(KualiDecimal.ZERO);
770: nullDrawer
771: .setFinancialDocumentTwentyFiveCentAmount(KualiDecimal.ZERO);
772: nullDrawer
773: .setFinancialDocumentTenCentAmount(KualiDecimal.ZERO);
774: nullDrawer
775: .setFinancialDocumentFiveCentAmount(KualiDecimal.ZERO);
776: nullDrawer
777: .removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
778: .convertToCoinDetail());
779: } catch (IllegalArgumentException iae) {
780: caught = true;
781: }
782: assertTrue("null drawer one cent amount", caught);
783:
784: caught = false;
785: try {
786: CashDrawer nullDrawer = CashDrawerAmountFixture.NULL_CASH_DRAWER
787: .convertToCashDrawer();
788: nullDrawer
789: .setFinancialDocumentHundredCentAmount(KualiDecimal.ZERO);
790: nullDrawer
791: .setFinancialDocumentFiftyCentAmount(KualiDecimal.ZERO);
792: nullDrawer
793: .setFinancialDocumentTwentyFiveCentAmount(KualiDecimal.ZERO);
794: nullDrawer
795: .setFinancialDocumentTenCentAmount(KualiDecimal.ZERO);
796: nullDrawer
797: .setFinancialDocumentFiveCentAmount(KualiDecimal.ZERO);
798: nullDrawer
799: .setFinancialDocumentOneCentAmount(KualiDecimal.ZERO);
800: nullDrawer
801: .setFinancialDocumentOtherCentAmount(KualiDecimal.ZERO);
802: nullDrawer
803: .removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
804: .convertToCoinDetail());
805: } catch (IllegalArgumentException iae) {
806: caught = true;
807: iae.printStackTrace();
808: }
809: assertFalse("null drawer all is now zero", caught);
810:
811: CashDrawer allFivesDrawerA = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
812: .convertToCashDrawer();
813: allFivesDrawerA
814: .removeCoin(CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
815: .convertToCoinDetail());
816: assertCoinAmountsEqual(
817: allFivesDrawerA,
818: CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT
819: .convertToCoinDetail());
820:
821: CashDrawer allFivesDrawerB = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
822: .convertToCashDrawer();
823: allFivesDrawerB
824: .removeCoin(CoinDetailTest.CoinDetailAmountFixture.NULL_COIN_AMOUNT
825: .convertToCoinDetail());
826: assertCoinAmountsEqual(
827: allFivesDrawerB,
828: CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT
829: .convertToCoinDetail());
830:
831: CashDrawer allFivesDrawerC = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
832: .convertToCashDrawer();
833: allFivesDrawerC
834: .removeCoin(CoinDetailTest.CoinDetailAmountFixture.ALL_FIVES_COIN_AMOUNT
835: .convertToCoinDetail());
836: assertCoinAmountsEqual(allFivesDrawerC,
837: CoinDetailTest.CoinDetailAmountFixture.ZERO_COIN_AMOUNT
838: .convertToCoinDetail());
839:
840: // test excessive coin (more coin requested than in drawer)
841: CoinDetail excessiveDetail = CoinDetailTest.CoinDetailAmountFixture.ALL_TENS_COIN_AMOUNT
842: .convertToCoinDetail();
843: CashDrawer allFivesDrawerD = CashDrawerAmountFixture.ALL_FIVES_CASH_DRAWER
844: .convertToCashDrawer();
845:
846: caught = false;
847: try {
848: allFivesDrawerD.removeCoin(excessiveDetail);
849: } catch (IllegalArgumentException iae) {
850: caught = true;
851: }
852: assertTrue("Hundred Cent", caught);
853: excessiveDetail
854: .setFinancialDocumentHundredCentAmount(new KualiDecimal(
855: 0));
856:
857: caught = false;
858: try {
859: allFivesDrawerD.removeCoin(excessiveDetail);
860: } catch (IllegalArgumentException iae) {
861: caught = true;
862: }
863: assertTrue("Fifty Cent", caught);
864: excessiveDetail
865: .setFinancialDocumentFiftyCentAmount(new KualiDecimal(0));
866:
867: caught = false;
868: try {
869: allFivesDrawerD.removeCoin(excessiveDetail);
870: } catch (IllegalArgumentException iae) {
871: caught = true;
872: }
873: assertTrue("Twenty Five Cent", caught);
874: excessiveDetail
875: .setFinancialDocumentTwentyFiveCentAmount(new KualiDecimal(
876: 0));
877:
878: caught = false;
879: try {
880: allFivesDrawerD.removeCoin(excessiveDetail);
881: } catch (IllegalArgumentException iae) {
882: caught = true;
883: }
884: assertTrue("Ten Cent", caught);
885: excessiveDetail
886: .setFinancialDocumentTenCentAmount(new KualiDecimal(0));
887:
888: caught = false;
889: try {
890: allFivesDrawerD.removeCoin(excessiveDetail);
891: } catch (IllegalArgumentException iae) {
892: caught = true;
893: }
894: assertTrue("Five Cent", caught);
895: excessiveDetail
896: .setFinancialDocumentFiveCentAmount(new KualiDecimal(0));
897:
898: caught = false;
899: try {
900: allFivesDrawerD.removeCoin(excessiveDetail);
901: } catch (IllegalArgumentException iae) {
902: caught = true;
903: }
904: assertTrue("One Cent", caught);
905: excessiveDetail
906: .setFinancialDocumentOneCentAmount(new KualiDecimal(0));
907:
908: caught = false;
909: try {
910: allFivesDrawerD.removeCoin(excessiveDetail);
911: } catch (IllegalArgumentException iae) {
912: caught = true;
913: }
914: assertFalse("We should be good....", caught);
915: }
916:
917: private void assertCurrencyAmountsEqual(CashDrawer drawer,
918: CurrencyDetail detail) {
919: assertEquals(drawer.getFinancialDocumentHundredDollarAmount(),
920: detail.getFinancialDocumentHundredDollarAmount());
921: assertEquals(drawer.getFinancialDocumentFiftyDollarAmount(),
922: detail.getFinancialDocumentFiftyDollarAmount());
923: assertEquals(drawer.getFinancialDocumentTwentyDollarAmount(),
924: detail.getFinancialDocumentTwentyDollarAmount());
925: assertEquals(drawer.getFinancialDocumentTenDollarAmount(),
926: detail.getFinancialDocumentTenDollarAmount());
927: assertEquals(drawer.getFinancialDocumentFiveDollarAmount(),
928: detail.getFinancialDocumentFiveDollarAmount());
929: assertEquals(drawer.getFinancialDocumentTwoDollarAmount(),
930: detail.getFinancialDocumentTwoDollarAmount());
931: assertEquals(drawer.getFinancialDocumentOneDollarAmount(),
932: detail.getFinancialDocumentOneDollarAmount());
933: }
934:
935: private void assertCoinAmountsEqual(CashDrawer drawer,
936: CoinDetail detail) {
937: assertEquals(drawer.getFinancialDocumentHundredCentAmount(),
938: detail.getFinancialDocumentHundredCentAmount());
939: assertEquals(drawer.getFinancialDocumentFiftyCentAmount(),
940: detail.getFinancialDocumentFiftyCentAmount());
941: assertEquals(drawer.getFinancialDocumentTwentyFiveCentAmount(),
942: detail.getFinancialDocumentTwentyFiveCentAmount());
943: assertEquals(drawer.getFinancialDocumentTenCentAmount(), detail
944: .getFinancialDocumentTenCentAmount());
945: assertEquals(drawer.getFinancialDocumentFiveCentAmount(),
946: detail.getFinancialDocumentFiveCentAmount());
947: assertEquals(drawer.getFinancialDocumentOneCentAmount(), detail
948: .getFinancialDocumentOneCentAmount());
949: }
950: }
|