1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.KualiDecimal;
22 import org.kuali.rice.kns.util.KualiPercent;
23 import org.kuali.rice.kns.web.format.Formatter;
24 import org.kuali.rice.test.BaseRiceTestCase;
25
26
27
28
29 public class KualiPercentTest extends BaseRiceTestCase {
30 private static final int OPERAND_VALUE = 25;
31
32 @Test public void testToKualiDecimal() throws Exception {
33 KualiPercent percent1 = new KualiPercent(50);
34 KualiDecimal percentAsDecimal1 = percent1.toKualiDecimal();
35 assertEquals(0.50, percentAsDecimal1.doubleValue(), 0);
36
37 KualiPercent percent2 = new KualiPercent(new BigDecimal(25.2));
38 KualiDecimal percentAsDecimal2 = percent2.toKualiDecimal();
39
40 assertEquals(0.25, percentAsDecimal2.doubleValue(), 0);
41
42 KualiPercent percent3 = new KualiPercent(new BigDecimal(25.7));
43 KualiDecimal percentAsDecimal3 = percent3.toKualiDecimal();
44
45 assertEquals(0.26, percentAsDecimal3.doubleValue(), 0);
46 }
47
48 @Test
49 public void testFormat() throws Exception {
50 Formatter testFormatter = Formatter.getFormatter(KualiPercent.class, null);
51
52 KualiDecimal decimal1 = new KualiDecimal(52);
53 KualiDecimal decimal2 = new KualiDecimal(32.3);
54
55 String percent1 = (String)testFormatter.format(decimal1);
56 String percent2 = (String)testFormatter.format(decimal2);
57
58 assertEquals("52 percent", percent1);
59 assertEquals("32.3 percent", percent2);
60
61 }
62
63 }