001/** 002 * Copyright 2005-2014 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 */ 016package org.kuali.rice.krad.datadictionary.mask; 017 018import org.junit.Test; 019import org.kuali.rice.krad.test.KRADTestCase; 020 021import static org.junit.Assert.*; 022 023/** 024 * MaskFormatterSubStringTest tests {@link MaskFormatterSubString} methods 025 * 026 * TODO: should be unit test 027 * 028 * @author Kuali Rice Team (rice.collab@kuali.org) 029 */ 030public class MaskFormatterSubStringTest extends KRADTestCase { 031 032 @Test 033 public void testMaskValue() { 034 MaskFormatterSubString formatterSubString = new MaskFormatterSubString(); 035 assertEquals(null, formatterSubString.maskValue(null)); 036 try { 037 formatterSubString.setMaskCharacter(null); 038 formatterSubString.maskValue("someMessage"); 039 fail("Mask Character needs specification"); 040 } 041 catch (RuntimeException e) { 042 assertTrue(e.getMessage().contains("Mask character not specified")); 043 044 } 045 046 formatterSubString = new MaskFormatterSubString(); 047 formatterSubString.setMaskLength(0); 048 assertEquals("FifteenthValues", formatterSubString.maskValue("FifteenthValues")); 049 assertEquals("123456", formatterSubString.maskValue(new Long(123456))); 050 formatterSubString.setMaskLength(6); 051 assertEquals(6, formatterSubString.getMaskLength()); 052 formatterSubString.setMaskCharacter("*"); 053 assertEquals("*", formatterSubString.getMaskCharacter()); 054 assertEquals("******nthValues", formatterSubString.maskValue("FifteenthValues")); 055 assertEquals("******.0", formatterSubString.maskValue(new Float(123456))); 056 formatterSubString.setMaskCharacter("#"); 057 formatterSubString.setMaskLength(3); 058 assertEquals("###", formatterSubString.maskValue("12")); 059 formatterSubString.setMaskLength(-2); 060 assertEquals("FifteenthValues", formatterSubString.maskValue("FifteenthValues")); 061 062 } 063 064 065}