001/**
002 * Copyright 2005-2015 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.util;
017
018import org.junit.Test;
019import static org.junit.Assert.*;
020
021/**
022 * @author Kuali Rice Team (rice.collab@kuali.org)
023 */
024public class PatternedStringBuilderTest {
025
026    @Test
027    public void testSprintf() {
028        double pi = Math.PI;
029        PatternedStringBuilder patterenedStringBuilder = new PatternedStringBuilder("pi = %5.3f");
030        String expectedVal = patterenedStringBuilder.sprintf(pi);
031        assertEquals("pi = 3.142", expectedVal);
032        patterenedStringBuilder.setPattern("%4$2s %3$2s %2$2s %1$2s");
033        assertEquals(" z  y  x  w", patterenedStringBuilder.sprintf("w", "x", "y", "z"));
034        patterenedStringBuilder.setPattern("");
035        assertEquals("", patterenedStringBuilder.sprintf("somethingElse"));
036        // This basically replicates tests done via jdk to test java.util.Formatter.java
037    }
038}