blob: 9758511f4d3cc991f03b15b17ae88053ced9851b [file] [log] [blame]
Yuta HIGUCHIc8ad76d2015-01-12 22:31:25 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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
17package org.onlab.util;
18
19import static org.junit.Assert.*;
20import static org.onlab.util.PositionalParameterStringFormatter.format;
21
22import org.junit.Test;
23
24public class PositionalParameterStringFormatterTest {
25
26 @Test
27 public void testFormat0() {
28 String fmt = "Some string 1 2 3";
29 assertEquals("Some string 1 2 3", format(fmt));
30 }
31
32 @Test
33 public void testFormat1() {
34 String fmt = "Some string {} 2 3";
35 assertEquals("Some string 1 2 3", format(fmt, 1));
36 }
37
38 @Test
39 public void testFormat2() {
40 String fmt = "Some string {} 2 {}";
41 assertEquals("Some string 1 2 3", format(fmt, 1, "3"));
42 }
43
44 @Test
45 public void testFormatNull() {
46 String fmt = "Some string {} 2 {}";
47 assertEquals("Some string 1 2 null", format(fmt, 1, null));
48 }
49
50 @Test
51 public void testFormatExtraBracket() {
52 String fmt = "Some string {} 2 {}";
53 assertEquals("Some string 1 2 {}", format(fmt, 1));
54 }
55
56 @Test
57 public void testFormatMissingBracket() {
58 String fmt = "Some string 1 2 3";
59 assertEquals("Some string 1 2 3", format(fmt, 7));
60 }
61}