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