1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary.mask;
17
18 import org.junit.Test;
19 import org.kuali.rice.krad.test.KRADTestCase;
20
21 import static org.junit.Assert.*;
22
23
24
25
26
27
28
29
30 public class MaskFormatterSubStringTest extends KRADTestCase {
31
32 @Test
33 public void testMaskValue() {
34 MaskFormatterSubString formatterSubString = new MaskFormatterSubString();
35 assertEquals(null, formatterSubString.maskValue(null));
36 try {
37 formatterSubString.setMaskCharacter(null);
38 formatterSubString.maskValue("someMessage");
39 fail("Mask Character needs specification");
40 }
41 catch (RuntimeException e) {
42 assertTrue(e.getMessage().contains("Mask character not specified"));
43
44 }
45
46 formatterSubString = new MaskFormatterSubString();
47 formatterSubString.setMaskLength(0);
48 assertEquals("FifteenthValues", formatterSubString.maskValue("FifteenthValues"));
49 assertEquals("123456", formatterSubString.maskValue(new Long(123456)));
50 formatterSubString.setMaskLength(6);
51 assertEquals(6, formatterSubString.getMaskLength());
52 formatterSubString.setMaskCharacter("*");
53 assertEquals("*", formatterSubString.getMaskCharacter());
54 assertEquals("******nthValues", formatterSubString.maskValue("FifteenthValues"));
55 assertEquals("******.0", formatterSubString.maskValue(new Float(123456)));
56 formatterSubString.setMaskCharacter("#");
57 formatterSubString.setMaskLength(3);
58 assertEquals("###", formatterSubString.maskValue("12"));
59 formatterSubString.setMaskLength(-2);
60 assertEquals("FifteenthValues", formatterSubString.maskValue("FifteenthValues"));
61
62 }
63
64
65 }