View Javadoc
1   /**
2    * Copyright 2005-2013 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.rice.krad.test.KRADTestCase;
20  
21  import static org.junit.Assert.*;
22  
23  /**
24   * MaskFormatterSubStringTest tests {@link MaskFormatterSubString} methods
25   *
26   * TODO: should be unit test
27   *
28   * @author Kuali Rice Team (rice.collab@kuali.org)
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  }