|
| 1 | +/** |
| 2 | + * Copyright 2012-2019 The Feign Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | + * in compliance with the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | + * or implied. See the License for the specific language governing permissions and limitations under |
| 12 | + * the License. |
| 13 | + */ |
| 14 | +package feign.template; |
| 15 | + |
| 16 | +import org.junit.Rule; |
| 17 | +import org.junit.Test; |
| 18 | +import org.junit.rules.ExpectedException; |
| 19 | +import java.util.Arrays; |
| 20 | +import java.util.Collections; |
| 21 | +import static org.junit.Assert.assertEquals; |
| 22 | + |
| 23 | +public class HeaderTemplateTest { |
| 24 | + |
| 25 | + @Rule |
| 26 | + public ExpectedException exception = ExpectedException.none(); |
| 27 | + |
| 28 | + @Test(expected = IllegalArgumentException.class) |
| 29 | + public void it_should_throw_exception_when_name_is_null() { |
| 30 | + HeaderTemplate.create(null, Arrays.asList("test")); |
| 31 | + exception.expectMessage("name is required."); |
| 32 | + } |
| 33 | + |
| 34 | + @Test(expected = IllegalArgumentException.class) |
| 35 | + public void it_should_throw_exception_when_name_is_empty() { |
| 36 | + HeaderTemplate.create("", Arrays.asList("test")); |
| 37 | + exception.expectMessage("name is required."); |
| 38 | + } |
| 39 | + |
| 40 | + @Test(expected = IllegalArgumentException.class) |
| 41 | + public void it_should_throw_exception_when_value_is_null() { |
| 42 | + HeaderTemplate.create("test", null); |
| 43 | + exception.expectMessage("values are required"); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void it_should_return_name() { |
| 48 | + HeaderTemplate headerTemplate = |
| 49 | + HeaderTemplate.create("test", Arrays.asList("test 1", "test 2")); |
| 50 | + assertEquals("test", headerTemplate.getName()); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void it_should_return_expanded() { |
| 55 | + HeaderTemplate headerTemplate = HeaderTemplate.create("hello", Arrays.asList("emre", "savci")); |
| 56 | + assertEquals("hello emre, savci", headerTemplate.expand(Collections.emptyMap())); |
| 57 | + assertEquals("hello emre, savci", |
| 58 | + headerTemplate.expand(Collections.singletonMap("name", "firsts"))); |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments