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