View Javadoc

1   /**
2    * Copyright 2005-2011 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.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   * Unit Tests for MaskFormatterSubString.java
25   *
26   * @author Kuali Rice Team (rice.collab@kuali.org)
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  }