1 /**
2 * Copyright 2005-2012 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.util;
17
18 import org.junit.Test;
19 import static org.junit.Assert.*;
20
21 /**
22 * @author Kuali Rice Team (rice.collab@kuali.org)
23 */
24 public class PatternedStringBuilderTest {
25
26 @Test
27 public void testSprintf() {
28 double pi = Math.PI;
29 PatternedStringBuilder patterenedStringBuilder = new PatternedStringBuilder("pi = %5.3f");
30 String expectedVal = patterenedStringBuilder.sprintf(pi);
31 assertEquals("pi = 3.142", expectedVal);
32 patterenedStringBuilder.setPattern("%4$2s %3$2s %2$2s %1$2s");
33 assertEquals(" z y x w", patterenedStringBuilder.sprintf("w", "x", "y", "z"));
34 patterenedStringBuilder.setPattern("");
35 assertEquals("", patterenedStringBuilder.sprintf("somethingElse"));
36 // This basically replicates tests done via jdk to test java.util.Formatter.java
37 }
38 }