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 org.junit.Test;
19  import org.kuali.rice.kns.util.KualiDecimal;
20  import org.kuali.rice.kns.util.NumberUtils;
21  import org.kuali.test.KNSTestCase;
22  
23  /**
24   * This class tests the NumberUtils methods.
25   */
26  public class NumberUtilsTest extends KNSTestCase {
27  
28      @Test public void testIntValue_nullInteger() {
29          Integer testInteger = null;
30          int testInt = 123;
31  
32          int intValue = NumberUtils.intValue(testInteger, testInt);
33          assertEquals(intValue, testInt);
34      }
35  
36      @Test public void testIntValue_nonNullInteger() {
37          Integer testInteger = new Integer(456);
38          int testInt = 123;
39  
40          int intValue = NumberUtils.intValue(testInteger, testInt);
41          assertEquals(intValue, 456);
42      }
43  
44  
45      @Test public void testIntegerEquals_bothNull() {
46          assertTrue(NumberUtils.equals((Integer) null, (Integer) null));
47      }
48  
49      @Test public void testIntegerEquals_bothNonNull_inequal() {
50          Integer i = new Integer(0);
51          Integer j = new Integer(1);
52  
53          assertFalse(NumberUtils.equals(i, j));
54      }
55  
56      @Test public void testIntegerEquals_bothNonNull_equal() {
57          Integer i = new Integer(2);
58          Integer j = new Integer(2);
59  
60          assertTrue(NumberUtils.equals(i, j));
61      }
62  
63      @Test public void testIntegerEquals_firstNotNull() {
64          Integer i = new Integer(3);
65          Integer j = null;
66  
67          assertFalse(NumberUtils.equals(i, j));
68      }
69  
70      @Test public void testIntegerEquals_secondNotNull() {
71          Integer i = null;
72          Integer j = new Integer(4);
73  
74          assertFalse(NumberUtils.equals(i, j));
75      }
76  
77      @Test public void testKualiDecimalEquals_bothNull() {
78          assertTrue(NumberUtils.equals((KualiDecimal) null, (KualiDecimal) null));
79      }
80  
81      @Test public void testKualiDecimalEquals_bothNonNull_inequal() {
82          KualiDecimal i = KualiDecimal.ZERO;
83          KualiDecimal j = new KualiDecimal(1);
84  
85          assertFalse(NumberUtils.equals(i, j));
86      }
87  
88      @Test public void testKualiDecimalEquals_bothNonNull_equal() {
89          KualiDecimal i = new KualiDecimal(2);
90          KualiDecimal j = new KualiDecimal(2);
91  
92          assertTrue(NumberUtils.equals(i, j));
93      }
94  
95      @Test public void testKualiDecimalEquals_firstNotNull() {
96          KualiDecimal i = new KualiDecimal(3);
97          KualiDecimal j = null;
98  
99          assertFalse(NumberUtils.equals(i, j));
100     }
101 
102     @Test public void testKualiDecimalEquals_secondNotNull() {
103         KualiDecimal i = null;
104         KualiDecimal j = new KualiDecimal(4);
105 
106         assertFalse(NumberUtils.equals(i, j));
107     }
108 }