001    /**
002     * Copyright 2005-2011 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.krad.datadictionary.mask;
017    
018    import org.junit.Test;
019    import org.kuali.test.KRADTestCase;
020    
021    import static org.junit.Assert.*;
022    
023    /**
024     * Unit Tests for MaskFormatterSubString.java
025     *
026     * @author Kuali Rice Team (rice.collab@kuali.org)
027     */
028    
029    public class MaskFormatterSubStringTest extends KRADTestCase {
030    
031        @Test
032        public void testMaskValue() {
033            MaskFormatterSubString formatterSubString = new MaskFormatterSubString();
034            assertEquals(null, formatterSubString.maskValue(null));
035            try {
036                formatterSubString.setMaskCharacter(null);
037                formatterSubString.maskValue("someMessage");
038                fail("Mask Character needs specification");
039            }
040            catch (RuntimeException e) {
041                assertTrue(e.getMessage().contains("Mask character not specified"));
042    
043            }
044    
045            formatterSubString = new MaskFormatterSubString();
046            formatterSubString.setMaskLength(0);
047            assertEquals("FifteenthValues", formatterSubString.maskValue("FifteenthValues"));
048            assertEquals("123456", formatterSubString.maskValue(new Long(123456)));
049            formatterSubString.setMaskLength(6);
050            assertEquals(6, formatterSubString.getMaskLength());
051            formatterSubString.setMaskCharacter("*");
052            assertEquals("*", formatterSubString.getMaskCharacter());
053            assertEquals("******nthValues", formatterSubString.maskValue("FifteenthValues"));
054            assertEquals("******.0", formatterSubString.maskValue(new Float(123456)));
055            formatterSubString.setMaskCharacter("#");
056            formatterSubString.setMaskLength(3);
057            assertEquals("###", formatterSubString.maskValue("12"));
058            formatterSubString.setMaskLength(-2);
059            assertEquals("FifteenthValues", formatterSubString.maskValue("FifteenthValues"));
060    
061        }
062    
063    
064    }