View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kns.util;
17  
18  import java.math.BigDecimal;
19  
20  import org.junit.Test;
21  import org.kuali.rice.kns.util.AbstractKualiDecimal;
22  import org.kuali.rice.kns.util.KualiDecimal;
23  import org.kuali.rice.kns.web.format.CurrencyFormatter;
24  import org.kuali.rice.kns.web.format.FormatException;
25  import org.kuali.rice.kns.web.format.Formatter;
26  import org.kuali.rice.test.BaseRiceTestCase;
27  
28  /**
29   * This class tests the KualiDecimal methods.
30   */
31  public class KualiDecimalTest extends BaseRiceTestCase {
32      private static final int OPERAND_VALUE = 25;
33  
34      private KualiDecimal decimalValue1;
35      private KualiDecimal decimalValue2;  
36      private KualiDecimal result;
37  
38      private KualiDecimal operand;
39  
40      @Override
41      public void setUp() throws Exception {
42          super.setUp();
43  
44          decimalValue1 = new KualiDecimal("15.97"); 
45          decimalValue2 = new KualiDecimal("11.23");
46          operand = new KualiDecimal(OPERAND_VALUE);
47      }
48  
49      @Test public void testIntConstructor() throws Exception {
50          final int INTVALUE = -1;
51  
52          KualiDecimal k = new KualiDecimal(INTVALUE);
53          assertEquals(INTVALUE, k.intValue());
54      }
55  
56      @Test public void testStringConstructor_nullString() throws Exception {
57      	KualiDecimal k = new KualiDecimal((String)null);
58      	assertEquals("When KualiDecimal passed null, it should be constructed as zero", 0, k.intValue());
59      }
60  
61      @Test public void testStringConstructor_nonnumericString() throws Exception {
62          boolean failedAsExpected = false;
63  
64          try {
65              new KualiDecimal("n0nnum3r1c");
66          }
67          catch (IllegalArgumentException e) {
68              failedAsExpected = true;
69          }
70  
71          assertTrue(failedAsExpected);
72      }
73  
74      @Test public void testStringConstructor_integerString() throws Exception {
75          final String INTSTRING = "123";
76  
77          KualiDecimal k = new KualiDecimal(INTSTRING);
78          assertEquals(Integer.valueOf(INTSTRING).intValue(), k.intValue());
79      }
80  
81      @Test public void testStringConstructor_floatingPointString() throws Exception {
82          final String DOUBLESTRING = "0.4567";
83  
84          KualiDecimal k = new KualiDecimal(DOUBLESTRING);
85          assertEquals("0.46", k.toString());
86      }
87  
88  
89      @Test public void testDoubleConstructor_noSig() throws Exception {
90          double value = 21;
91  
92          KualiDecimal k = new KualiDecimal(value);
93          assertEquals(value, k.doubleValue(), 0);
94      }
95  
96      @Test public void testDoubleConstructor_oneSig() throws Exception {
97          double value = 21.1;
98  
99          KualiDecimal k = new KualiDecimal(value);
100         assertEquals(value, k.doubleValue(), 0);
101     }
102 
103     @Test public void testDoubleConstructor_twoSig() throws Exception {
104         double value = 21.12;
105 
106         KualiDecimal k = new KualiDecimal(value);
107         assertEquals(value, k.doubleValue(), 0);
108     }
109 
110     @Test public void testDoubleConstructor_threeSig() throws Exception {
111         double value = 21.123;
112         double roundedValue = 21.12;
113 
114         KualiDecimal k = new KualiDecimal(value);
115         assertEquals(roundedValue, k.doubleValue(), 0);
116     }
117 
118 
119     @Test public void testAdd_nullAddend() throws Exception {
120         boolean failedAsExpected = false;
121 
122         try {
123             this.operand.add(null);
124         }
125         catch (IllegalArgumentException e) {
126             failedAsExpected = true;
127         }
128 
129         assertTrue(failedAsExpected);
130     }
131 
132     @Test public void testAdd_validAddend() throws Exception {
133         KualiDecimal addend = new KualiDecimal(2);
134         KualiDecimal sum = this.operand.add(addend);
135 
136         assertEquals(new KualiDecimal(OPERAND_VALUE + 2), sum);
137     }
138 
139     @Test public void testSubtract_nullSubtrahend() throws Exception {
140         boolean failedAsExpected = false;
141 
142         try {
143             this.operand.subtract(null);
144         }
145         catch (IllegalArgumentException e) {
146             failedAsExpected = true;
147         }
148 
149         assertTrue(failedAsExpected);
150     }
151 
152     @Test public void testSubtract_validSubtrahend() throws Exception {
153         KualiDecimal subtrahend = new KualiDecimal(2);
154         KualiDecimal difference = this.operand.subtract(subtrahend);
155 
156         assertEquals(new KualiDecimal(OPERAND_VALUE - 2), difference);
157     }
158 
159     @Test public void testMultiply_nullMultiplier() throws Exception {
160         boolean failedAsExpected = false;
161 
162         try {
163             this.operand.multiply(null);
164         }
165         catch (IllegalArgumentException e) {
166             failedAsExpected = true;
167         }
168 
169         assertTrue(failedAsExpected);
170     }
171 
172     @Test public void testMultiply_validMultiplier() throws Exception {
173         KualiDecimal multiplier = new KualiDecimal(2);
174         KualiDecimal product = this.operand.multiply(multiplier);
175 
176         assertEquals(new KualiDecimal(OPERAND_VALUE * 2), product);
177     }
178 
179     @Test public void testDivide_nullDivisor() throws Exception {
180         boolean failedAsExpected = false;
181 
182         try {
183             this.operand.divide(null);
184         }
185         catch (IllegalArgumentException e) {
186             failedAsExpected = true;
187         }
188 
189         assertTrue(failedAsExpected);
190     }
191 
192     @Test public void testDivide_validDivisor() throws Exception {
193         KualiDecimal divisor = new KualiDecimal(2).setScale();
194         KualiDecimal quotient = this.operand.divide(divisor).setScale();
195 
196         double expectedQuotient = OPERAND_VALUE / 2.0;
197 
198         assertEquals(expectedQuotient, quotient.doubleValue(), 0);
199     }
200 
201     @Test public void testMod_nullModulus() throws Exception {
202         boolean failedAsExcpected = false;
203 
204         try {
205             this.operand.mod(null);
206         }
207         catch (IllegalArgumentException e) {
208             failedAsExcpected = true;
209         }
210 
211         assertTrue(failedAsExcpected);
212     }
213 
214     @Test public void testMod_validZeroModulus() throws Exception {
215         // divide by some number to make sure that the two aren't the same
216         KualiDecimal zeroModulus = this.operand.divide(new KualiDecimal(5));
217         KualiDecimal expectedZero = this.operand.mod(zeroModulus);
218 
219         assertEquals(KualiDecimal.ZERO, expectedZero);
220     }
221 
222     @Test public void testMod_validNonZeroModulus() throws Exception {
223         KualiDecimal nonZeroModulus = this.operand.divide(new KualiDecimal(5)).add(new KualiDecimal(1));
224         KualiDecimal expectedNonZero = this.operand.mod(nonZeroModulus);
225 
226         assertNotSame(KualiDecimal.ZERO, expectedNonZero);
227     }
228 
229     @Test public void testNegative_zeroValue() {
230         KualiDecimal zeroValue = KualiDecimal.ZERO;
231         KualiDecimal negativeZeroValue = zeroValue.negated();
232 
233         assertEquals(zeroValue, negativeZeroValue);
234     }
235 
236     @Test public void testNegative_negativeValue() {
237         KualiDecimal negativeValue = new KualiDecimal(-4000);
238         KualiDecimal negativeNegativeValue = negativeValue.negated();
239 
240         assertEquals(negativeValue.intValue() * -1, negativeNegativeValue.intValue());
241     }
242 
243     @Test public void testNegative_positiveValue() {
244         KualiDecimal positiveValue = new KualiDecimal(2112);
245         KualiDecimal negativePositiveValue = positiveValue.negated();
246 
247         assertEquals(positiveValue.intValue() * -1, negativePositiveValue.intValue());
248     }
249 
250     @Test public void testNegative_negativeDoubleValue() {
251         KualiDecimal negativeValue = new KualiDecimal("-23.12");
252         KualiDecimal negativeNegativeValue = negativeValue.negated();
253 
254         assertEquals(new Double(negativeValue.doubleValue() * -1.0), new Double(negativeNegativeValue.doubleValue()));
255     }
256 
257     @Test public void testNegative_positiveDoubleValue() {
258         KualiDecimal positiveValue = new KualiDecimal("12.34");
259         KualiDecimal negativePositiveValue = positiveValue.negated();
260 
261         assertEquals(new Double(positiveValue.doubleValue() * -1.0), new Double(negativePositiveValue.doubleValue()));
262     }
263 
264 
265     @Test public void testEquals_inequalIntegerValues() {
266         KualiDecimal v1 = new KualiDecimal(1);
267         KualiDecimal v2 = new KualiDecimal(2);
268 
269         assertFalse(v1.equals(v2));
270         assertFalse(v2.equals(v1));
271     }
272 
273     @Test public void testEquals_equalIntegerValues() {
274         KualiDecimal v1 = new KualiDecimal(3);
275         KualiDecimal v2 = new KualiDecimal(3);
276 
277         assertTrue(v1.equals(v2));
278         assertTrue(v2.equals(v1));
279     }
280 
281     @Test public void testEquals_inequalDoubleValues() {
282         KualiDecimal v1 = new KualiDecimal(1.0d);
283         KualiDecimal v2 = new KualiDecimal(2.0d);
284 
285         assertFalse(v1.equals(v2));
286         assertFalse(v2.equals(v1));
287     }
288 
289     @Test public void testEquals_roughlyEqualDoubleValues() {
290         KualiDecimal v1 = new KualiDecimal(6.03d);
291         KualiDecimal v2 = new KualiDecimal(6.029997d);
292 
293         assertTrue(v1.equals(v2));
294         assertTrue(v2.equals(v1));
295     }
296 
297     @Test public void testEquals_equalDoubleValues() {
298         KualiDecimal v1 = new KualiDecimal(6.03d);
299         KualiDecimal v2 = new KualiDecimal(6.03d);
300 
301         assertTrue(v1.equals(v2));
302         assertTrue(v2.equals(v1));
303     }
304 
305 
306     @Test public void testEquals_inequalStringValue() {
307         KualiDecimal s1 = new KualiDecimal("100.00");
308         KualiDecimal s2 = new KualiDecimal("100.01");
309 
310         assertFalse(s1.equals(s2));
311         assertFalse(s2.equals(s1));
312     }
313 
314     @Test public void testEquals_equalStringValues() {
315         KualiDecimal s1 = new KualiDecimal("100.00");
316         KualiDecimal s2 = new KualiDecimal("100.00");
317 
318         assertTrue(s1.equals(s2));
319         assertTrue(s2.equals(s1));
320     }
321 
322     @Test public void testEquals_equivalentValues() {
323         KualiDecimal d1 = new KualiDecimal(100);
324         KualiDecimal s1 = new KualiDecimal("100");
325 
326         assertTrue(d1.equals(s1));
327         assertTrue(s1.equals(d1));
328     }
329 
330 
331     /**
332      * The specific values used in this test case were copied from the code which was breaking because it was converting the
333      * KualiDecimals into floats, adding the floats, and comparing them. The float addition is here to illustrate one of the
334      * problems that requires us to do KualiDecimal math instead of converting back to a primitive format.
335      */
336     @Test public void testEquals_summedFloatValues() {
337 
338         // sum them as floats
339         float c1 = 1.01f;
340         float c2 = 3.00f;
341         float c3 = 2.02f;
342 
343         float d1 = 4.02f;
344         float d2 = 2.01f;
345 
346         float c = c1 + c2 + c3;
347         float d = d1 + d2;
348 
349         assertFalse(c == d);
350 
351 
352         // sum them as KualiDecimals built from Strings, as the JSP was doing
353         KualiDecimal a1 = new KualiDecimal("1.01");
354         KualiDecimal a2 = new KualiDecimal("3.00");
355         KualiDecimal a3 = new KualiDecimal("2.02");
356 
357         KualiDecimal b1 = new KualiDecimal("4.02");
358         KualiDecimal b2 = new KualiDecimal("2.01");
359 
360         KualiDecimal a = a1.add(a2).add(a3);
361         KualiDecimal b = b1.add(b2);
362 
363         assertTrue(a.equals(b));
364         assertTrue(b.equals(a));
365     }
366 
367 
368     @Test public void testIsNegative_negativeValue() {
369         KualiDecimal v1 = new KualiDecimal(-231);
370 
371         assertTrue(v1.isNegative());
372     }
373 
374     @Test public void testIsNegative_positiveValue() {
375         KualiDecimal v1 = new KualiDecimal(987);
376 
377         assertFalse(v1.isNegative());
378     }
379 
380     @Test public void testIsNegative_zeroValue() {
381         KualiDecimal v1 = KualiDecimal.ZERO;
382 
383         assertFalse(v1.isNegative());
384     }
385 
386 
387     @Test public void testIsPositive_negativeValue() {
388         KualiDecimal v1 = new KualiDecimal(-231);
389 
390         assertFalse(v1.isPositive());
391     }
392 
393     @Test public void testIsPositive_positiveValue() {
394         KualiDecimal v1 = new KualiDecimal(987);
395 
396         assertTrue(v1.isPositive());
397     }
398 
399     @Test public void testIsPositive_zeroValue() {
400         KualiDecimal v1 = KualiDecimal.ZERO;
401 
402         assertFalse(v1.isPositive());
403     }
404 
405 
406     @Test public void testIsZero_negativeValue() {
407         KualiDecimal v1 = new KualiDecimal(-231);
408 
409         assertFalse(v1.isZero());
410     }
411 
412     @Test public void testIsZero_positiveValue() {
413         KualiDecimal v1 = new KualiDecimal(987);
414 
415         assertFalse(v1.isZero());
416     }
417 
418     @Test public void testIsZero_zeroValue() {
419         KualiDecimal v1 = KualiDecimal.ZERO;
420 
421         assertTrue(v1.isZero());
422     }
423 
424 
425     @Test public void testIsNonZero_negativeValue() {
426         KualiDecimal v1 = new KualiDecimal(-231);
427 
428         assertTrue(v1.isNonZero());
429     }
430 
431     @Test public void testIsNonZero_positiveValue() {
432         KualiDecimal v1 = new KualiDecimal(987);
433 
434         assertTrue(v1.isNonZero());
435     }
436 
437     @Test public void testIsNonZero_zeroValue() {
438         KualiDecimal v1 = KualiDecimal.ZERO;
439 
440         assertFalse(v1.isNonZero());
441     }
442 
443 
444     @Test public void testIsLessThan_nullOperand() {
445         boolean failedAsExpected = false;
446 
447         KualiDecimal v1 = new KualiDecimal(123);
448         try {
449             v1.isLessThan(null);
450         }
451         catch (IllegalArgumentException e) {
452             failedAsExpected = true;
453         }
454 
455         assertTrue(failedAsExpected);
456     }
457 
458     @Test public void testIsLessThan_greaterOperand() {
459         KualiDecimal v1 = new KualiDecimal(123);
460         KualiDecimal v2 = new KualiDecimal(456);
461 
462         assertTrue(v1.isLessThan(v2));
463     }
464 
465     @Test public void testIsLessThan_equalOperand() {
466         KualiDecimal v1 = new KualiDecimal(456);
467         KualiDecimal v2 = new KualiDecimal(456);
468 
469         assertFalse(v1.isLessThan(v2));
470     }
471 
472     @Test public void testIsLessThan_lesserOperand() {
473         KualiDecimal v1 = new KualiDecimal(789);
474         KualiDecimal v2 = new KualiDecimal(345);
475 
476         assertFalse(v1.isLessThan(v2));
477     }
478 
479 
480     @Test public void testIsGreaterThan_nullOperand() {
481         boolean failedAsExpected = false;
482 
483         KualiDecimal v1 = new KualiDecimal(123);
484         try {
485             v1.isGreaterThan(null);
486         }
487         catch (IllegalArgumentException e) {
488             failedAsExpected = true;
489         }
490 
491         assertTrue(failedAsExpected);
492     }
493 
494     @Test public void testIsGreaterThan_greaterOperand() {
495         KualiDecimal v1 = new KualiDecimal(123);
496         KualiDecimal v2 = new KualiDecimal(456);
497 
498         assertTrue(v2.isGreaterThan(v1));
499     }
500 
501     @Test public void testIsGreaterThan_equalOperand() {
502         KualiDecimal v1 = new KualiDecimal(456);
503         KualiDecimal v2 = new KualiDecimal(456);
504 
505         assertFalse(v1.isGreaterThan(v2));
506     }
507 
508     @Test public void testIsGreaterThan_lesserOperand() {
509         KualiDecimal v1 = new KualiDecimal(789);
510         KualiDecimal v2 = new KualiDecimal(345);
511 
512         assertFalse(v2.isGreaterThan(v1));
513     }
514 
515 
516     @Test public void testIsLessEqual_nullOperand() {
517         boolean failedAsExpected = false;
518 
519         KualiDecimal v1 = new KualiDecimal(123);
520         try {
521             v1.isLessEqual(null);
522         }
523         catch (IllegalArgumentException e) {
524             failedAsExpected = true;
525         }
526 
527         assertTrue(failedAsExpected);
528     }
529 
530     @Test public void testIsLessEqual_greaterOperand() {
531         KualiDecimal v1 = new KualiDecimal(123);
532         KualiDecimal v2 = new KualiDecimal(456);
533 
534         assertTrue(v1.isLessEqual(v2));
535     }
536 
537     @Test public void testIsLessEqual_equalOperand() {
538         KualiDecimal v1 = new KualiDecimal(456);
539         KualiDecimal v2 = new KualiDecimal(456);
540 
541         assertTrue(v1.isLessEqual(v2));
542     }
543 
544     @Test public void testIsLessEqual_lesserOperand() {
545         KualiDecimal v1 = new KualiDecimal(789);
546         KualiDecimal v2 = new KualiDecimal(345);
547 
548         assertFalse(v1.isLessEqual(v2));
549     }
550 
551 
552     @Test public void testIsGreaterEqual_nullOperand() {
553         boolean failedAsExpected = false;
554 
555         KualiDecimal v1 = new KualiDecimal(123);
556         try {
557             v1.isGreaterEqual(null);
558         }
559         catch (IllegalArgumentException e) {
560             failedAsExpected = true;
561         }
562 
563         assertTrue(failedAsExpected);
564     }
565 
566     @Test public void testIsGreaterEqual_greaterOperand() {
567         KualiDecimal v1 = new KualiDecimal(123);
568         KualiDecimal v2 = new KualiDecimal(456);
569 
570         assertTrue(v2.isGreaterEqual(v1));
571     }
572 
573     @Test public void testIsGreaterEqual_equalOperand() {
574         KualiDecimal v1 = new KualiDecimal(456);
575         KualiDecimal v2 = new KualiDecimal(456);
576 
577         assertTrue(v1.isGreaterEqual(v2));
578     }
579 
580     @Test public void testIsGreaterEqual_lesserOperand() {
581         KualiDecimal v1 = new KualiDecimal(789);
582         KualiDecimal v2 = new KualiDecimal(345);
583 
584         assertFalse(v2.isGreaterEqual(v1));
585     }
586 
587 
588     @Test public void testIsNumeric_null() {
589         assertFalse(KualiDecimal.isNumeric(null));
590     }
591 
592     @Test public void testIsNumeric_blank() {
593         assertFalse(KualiDecimal.isNumeric("   "));
594     }
595 
596     @Test public void testIsNumeric_alphanumeric() {
597         assertFalse(KualiDecimal.isNumeric("12YYZ23"));
598     }
599 
600     @Test public void testIsNumeric_integral() {
601         assertTrue(KualiDecimal.isNumeric("1234"));
602     }
603 
604     @Test public void testIsNumeric_decimal() {
605         assertTrue(KualiDecimal.isNumeric("1234.56"));
606     }
607 
608     @Test public void testIsNumeric_moreSignificantDecimal() {
609         assertTrue(KualiDecimal.isNumeric("1234.56789"));
610     }
611 
612     @Test public void testIsNumeric_negativeIntegral() {
613         assertTrue(KualiDecimal.isNumeric("-1234"));
614     }
615 
616     @Test public void testIsNumeric_negativeDecimal() {
617         assertTrue(KualiDecimal.isNumeric("-1234.56"));
618     }
619 
620     @Test public void testIsNumeric_zero() {
621         assertTrue(KualiDecimal.isNumeric("0"));
622     }
623 
624     @Test public void testIsNumeric_multiZero() {
625         assertTrue(KualiDecimal.isNumeric("0000"));
626     }
627 
628     @Test public void testIsNumeric_negativeZero() {
629         assertTrue(KualiDecimal.isNumeric("-0"));
630     }
631 
632     @Test public void testIsNumeric_decimalZero() {
633         assertTrue(KualiDecimal.isNumeric("0.0"));
634     }
635 
636     @Test public void testIsNumeric_negativeDecimalZero() {
637         assertTrue(KualiDecimal.isNumeric("-0.00"));
638     }
639     
640     @Test 
641     public void testKualiDecimal_Add() throws Exception {
642         result = decimalValue1.add(decimalValue2);
643         assertEquals(new BigDecimal("27.2").setScale(2), result.value);
644         
645         KualiDecimal modifiedResult = new KualiDecimal(result.doubleValue(), 3);
646         assertEquals(new BigDecimal("27.2").setScale(3), modifiedResult.value);
647     }
648 
649     @Test 
650     public void testKualiDecimal_Subtract() throws Exception {
651         result = decimalValue1.subtract(decimalValue2);
652         assertEquals(new BigDecimal("4.74").setScale(2), result.value);
653         
654         KualiDecimal modifiedResult = new KualiDecimal(result.doubleValue(), 3);
655         assertEquals(new BigDecimal("4.74").setScale(3), modifiedResult.value);
656     }
657 
658     @Test 
659     public void testKualiDecimal_Multiply() throws Exception {
660         result = decimalValue1.multiply(decimalValue2);
661         assertEquals(new BigDecimal("179.3431").setScale(2, AbstractKualiDecimal.ROUND_BEHAVIOR), result.value);
662         
663         KualiDecimal modifiedResult = new KualiDecimal(result.doubleValue(), 3);
664         assertEquals(new BigDecimal("179.3431").setScale(2, AbstractKualiDecimal.ROUND_BEHAVIOR).setScale(3), modifiedResult.value);
665     }
666 
667     @Test 
668     public void testKualiDecimal_Divide() throws Exception {
669         result = decimalValue1.divide(decimalValue2);
670         assertEquals(new BigDecimal("1.4220").setScale(2, AbstractKualiDecimal.ROUND_BEHAVIOR), result.value);
671         
672         KualiDecimal modifiedResult = new KualiDecimal(result.doubleValue(), 3);
673         assertEquals(new BigDecimal("1.4220").setScale(2, AbstractKualiDecimal.ROUND_BEHAVIOR).setScale(3), modifiedResult.value);
674     }
675 
676     @Test 
677     public void testKualiDecimal_Divide_Overridden() throws Exception {
678         KualiDecimal operand1 = new KualiDecimal("100", 3);
679         KualiDecimal operand2 = new KualiDecimal("365", 3); 
680         result = operand1.divide(operand2, false).multiply(operand2, false); 
681         assertEquals(new KualiDecimal("100.01"), new KualiDecimal(result.bigDecimalValue().setScale(2, BigDecimal.ROUND_HALF_UP), 2));
682     }
683 
684     @Test 
685     public void testKualiDecimal_Mod() throws Exception {
686         result = decimalValue1.mod(decimalValue2);
687         assertEquals(new BigDecimal("4.74").setScale(2), result.value);
688         
689         KualiDecimal modifiedResult = new KualiDecimal(result.doubleValue(), 3);
690         assertEquals(new BigDecimal("4.74").setScale(3), modifiedResult.value);
691     }
692 
693     @Test 
694     public void testKualiDecimal_Negated() throws Exception {
695         result = decimalValue1.negated();
696         assertEquals(new BigDecimal("-15.97").setScale(2), result.value);
697         
698         KualiDecimal modifiedResult = new KualiDecimal(result.doubleValue(), 3);
699         assertEquals(new BigDecimal("-15.97").setScale(3), modifiedResult.value);
700     }
701 
702     @Test 
703     public void testKualiDecimal_isNegative() throws Exception {
704         result = decimalValue1.negated();
705         assertEquals(new BigDecimal("-15.97").setScale(2), result.value);
706         assertEquals(true, result.isNegative());
707     }
708 
709     @Test 
710     public void testKualiDecimal_isPositive() throws Exception {  
711         assertEquals(true, decimalValue1.isPositive());
712     }
713 
714     @Test 
715     public void testKualiDecimal_isZero() throws Exception {
716         assertEquals(false, decimalValue1.isZero());
717         
718         result = decimalValue1.multiply(KualiDecimal.ZERO);
719         assertEquals(true, result.isZero());
720     }
721 
722     @Test 
723     public void testKualiDecimal_abs() throws Exception {
724         result = decimalValue1.abs();
725         assertEquals(result.value, decimalValue1.value);
726         
727         result = decimalValue1.negated().abs();    
728         assertEquals(decimalValue1.value, result.value);
729     }
730 
731     @Test 
732     public void testKualiDecimal_isNonZero() throws Exception {
733         assertEquals(true, decimalValue1.isNonZero());
734         
735         result = decimalValue1.multiply(KualiDecimal.ZERO);
736         assertEquals(false, result.isNonZero());
737     }
738 
739     @Test 
740     public void testKualiDecimal_isLessThan() throws Exception {
741         assertEquals(false, decimalValue1.isLessThan(decimalValue2));
742         
743         result = decimalValue1.negated();
744         assertEquals(true, result.isLessThan(decimalValue1));
745     }
746 
747     @Test 
748     public void testKualiDecimal_isGreaterThan() throws Exception {
749         assertEquals(true, decimalValue1.isGreaterThan(decimalValue2));
750         assertEquals(false, decimalValue2.isGreaterThan(decimalValue1));
751    }
752     
753     @Test 
754     public void testKualiDecimal_isLessEqual() throws Exception {
755         assertEquals(false, decimalValue1.isLessEqual(decimalValue2));
756         assertEquals(true, decimalValue2.isLessEqual(decimalValue1));
757         assertEquals(true, decimalValue1.isLessEqual(decimalValue1));
758     }    
759 
760     @Test 
761     public void testKualiDecimal_isGreaterEqual() throws Exception {
762         assertEquals(true, decimalValue1.isGreaterEqual(decimalValue2));
763         assertEquals(false, decimalValue2.isGreaterEqual(decimalValue1));
764         assertEquals(true, decimalValue1.isGreaterEqual(decimalValue1));
765     }    
766 
767     @Test 
768     public void testKualiDecimal_isNumeric() throws Exception {
769         assertEquals(true, KualiDecimal.isNumeric("10.234"));
770         assertEquals(false, KualiDecimal.isNumeric("10.df"));
771     }    
772 
773     @Test 
774     public void testKualiDecimal_compareTo() throws Exception {
775         assertEquals(1, decimalValue1.compareTo(decimalValue2));
776         assertEquals(0, decimalValue1.compareTo(decimalValue1));
777         assertEquals(-1, decimalValue2.compareTo(decimalValue1));
778     }    
779 
780     @Test 
781     public void testKualiDecimal_displayFormat() throws Exception {
782         Formatter testFormatter = Formatter.getFormatter(KualiDecimal.class, null);
783         System.out.println(testFormatter); 
784         
785         KualiDecimal operand1;
786         KualiDecimal operand2;
787         
788         operand1 = new KualiDecimal("100");
789         operand2 = new KualiDecimal("365"); 
790         result = operand1.divide(operand2).multiply(operand2);
791         assertEquals(result.toString(), testFormatter.format(result));
792         CurrencyFormatter currencyFormatter = new CurrencyFormatter();
793         assertEquals(currencyFormatter.format(result), testFormatter.format(result));
794         
795         operand1 = new KualiDecimal("100", 3);
796         operand2 = new KualiDecimal("365", 3); 
797         result = operand1.divide(operand2, false).multiply(operand2, false);
798         
799         //CurrencyDecimal cannot be used with KualiDecimal objects of scale > 2.
800         try {
801             currencyFormatter.format(result);
802         } catch (FormatException e) {
803             assertEquals("parsing, error.currency.decimal["+ result.bigDecimalValue() + "]", e.getMessage());
804         }
805     }    
806 
807 }