Skip to content

Commit f7282b3

Browse files
mstrYodavelo
authored andcommitted
Feature/template unit test (#958)
* add HeaderTemplate create tests for fail * - added expand test * - remove redundant public static identifier from Retryer inner class * - remove redundant public static identifier from Default inner class * add license to test * mvn clean install to format test file
1 parent 284b020 commit f7282b3

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

core/src/main/java/feign/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public interface Client {
4949
*/
5050
Response execute(Request request, Options options) throws IOException;
5151

52-
public static class Default implements Client {
52+
class Default implements Client {
5353

5454
private final SSLSocketFactory sslContextFactory;
5555
private final HostnameVerifier hostnameVerifier;

core/src/main/java/feign/Retryer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface Retryer extends Cloneable {
2828

2929
Retryer clone();
3030

31-
public static class Default implements Retryer {
31+
class Default implements Retryer {
3232

3333
private final int maxAttempts;
3434
private final long period;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)