Yuta HIGUCHI | c8ad76d | 2015-01-12 22:31:25 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Yuta HIGUCHI | c8ad76d | 2015-01-12 22:31:25 -0800 | [diff] [blame] | 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 | |
| 17 | package org.onlab.util; |
| 18 | |
| 19 | import static org.junit.Assert.*; |
| 20 | import static org.onlab.util.PositionalParameterStringFormatter.format; |
| 21 | |
| 22 | import org.junit.Test; |
| 23 | |
| 24 | public 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 | } |