Skip to content

Commit

Permalink
Feature/template unit test (#958)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mstrYoda authored and velo committed May 8, 2019
1 parent c59ce54 commit 92d0f64
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/feign/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface Client {
*/
Response execute(Request request, Options options) throws IOException;

public static class Default implements Client {
class Default implements Client {

private final SSLSocketFactory sslContextFactory;
private final HostnameVerifier hostnameVerifier;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/feign/Retryer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface Retryer extends Cloneable {

Retryer clone();

public static class Default implements Retryer {
class Default implements Retryer {

private final int maxAttempts;
private final long period;
Expand Down
60 changes: 60 additions & 0 deletions core/src/test/java/feign/template/HeaderTemplateTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright 2012-2019 The Feign Authors
*
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package feign.template;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collections;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class HeaderTemplateTest {

@Rule public ExpectedException exception = ExpectedException.none();

@Test(expected = IllegalArgumentException.class)
public void it_should_throw_exception_when_name_is_null() {
HeaderTemplate.create(null, Arrays.asList("test"));
exception.expectMessage("name is required.");
}

@Test(expected = IllegalArgumentException.class)
public void it_should_throw_exception_when_name_is_empty() {
HeaderTemplate.create("", Arrays.asList("test"));
exception.expectMessage("name is required.");
}

@Test(expected = IllegalArgumentException.class)
public void it_should_throw_exception_when_value_is_null() {
HeaderTemplate.create("test", null);
exception.expectMessage("values are required");
}

@Test
public void it_should_return_name() {
HeaderTemplate headerTemplate =
HeaderTemplate.create("test", Arrays.asList("test 1", "test 2"));
assertEquals("test", headerTemplate.getName());
}

@Test
public void it_should_return_expanded() {
HeaderTemplate headerTemplate = HeaderTemplate.create("hello", Arrays.asList("emre", "savci"));
assertEquals("hello emre, savci", headerTemplate.expand(Collections.emptyMap()));
assertEquals(
"hello emre, savci", headerTemplate.expand(Collections.singletonMap("name", "firsts")));
}
}

0 comments on commit 92d0f64

Please sign in to comment.