Skip to content

Commit 057caad

Browse files
myifengliqf7velo
authored
Remove deprecated method. (OpenFeign#1545)
* Remove deprecated method. Replace JUnit ExpectedException with assertThrows. Replace JUnit Assert.assertThat with TestCase.assertEquals. Fix assertEquals parameter position. * Fix license * format code * Replace JUnit assertThat with Hamcrest. * Replace TestCase.assertEquals with Assert.assertEquals Co-authored-by: liqf7 <liqf7@lenovo.com> Co-authored-by: Marvin Froeder <velo@users.noreply.github.com>
1 parent f71849d commit 057caad

8 files changed

Lines changed: 33 additions & 39 deletions

File tree

core/src/test/java/feign/CapabilityTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
package feign;
1515

1616
import static org.hamcrest.CoreMatchers.nullValue;
17-
import static org.junit.Assert.assertThat;
17+
import static org.hamcrest.MatcherAssert.assertThat;
1818
import org.hamcrest.CoreMatchers;
1919
import org.junit.Test;
2020
import java.io.IOException;

core/src/test/java/feign/EmptyTargetTest.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,15 @@
1414
package feign;
1515

1616
import feign.Request.HttpMethod;
17-
import org.junit.Rule;
17+
import feign.Target.EmptyTarget;
1818
import org.junit.Test;
19-
import org.junit.rules.ExpectedException;
2019
import java.net.URI;
21-
import feign.Target.EmptyTarget;
2220
import static feign.assertj.FeignAssertions.assertThat;
21+
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertThrows;
2323

2424
public class EmptyTargetTest {
2525

26-
@Rule
27-
public final ExpectedException thrown = ExpectedException.none();
28-
2926
@Test
3027
public void whenNameNotSupplied() {
3128
assertThat(EmptyTarget.create(UriInterface.class))
@@ -46,11 +43,11 @@ public void toString_withName() {
4643

4744
@Test
4845
public void mustApplyToAbsoluteUrl() {
49-
thrown.expect(UnsupportedOperationException.class);
50-
thrown.expectMessage("Request with non-absolute URL not supported with empty target");
51-
52-
EmptyTarget.create(UriInterface.class)
53-
.apply(new RequestTemplate().method(HttpMethod.GET).uri("/relative"));
46+
UnsupportedOperationException exception = assertThrows(UnsupportedOperationException.class,
47+
() -> EmptyTarget.create(UriInterface.class)
48+
.apply(new RequestTemplate().method(HttpMethod.GET).uri("/relative")));
49+
assertEquals("Request with non-absolute URL not supported with empty target",
50+
exception.getMessage());
5451
}
5552

5653
interface UriInterface {

core/src/test/java/feign/template/HeaderTemplateTest.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,36 @@
1313
*/
1414
package feign.template;
1515

16-
import static org.hamcrest.CoreMatchers.equalTo;
17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertThat;
16+
import org.junit.Test;
1917
import java.util.ArrayList;
2018
import java.util.Arrays;
2119
import java.util.Collections;
22-
import java.util.Map;
23-
import org.junit.Rule;
24-
import org.junit.Test;
25-
import org.junit.rules.ExpectedException;
20+
import static org.hamcrest.MatcherAssert.assertThat;
21+
import static org.hamcrest.Matchers.equalTo;
22+
import static org.junit.Assert.assertEquals;
23+
import static org.junit.Assert.assertThrows;
2624

2725
public class HeaderTemplateTest {
2826

29-
@Rule
30-
public ExpectedException exception = ExpectedException.none();
31-
32-
@Test(expected = IllegalArgumentException.class)
27+
@Test
3328
public void it_should_throw_exception_when_name_is_null() {
34-
HeaderTemplate.create(null, Collections.singletonList("test"));
35-
exception.expectMessage("name is required.");
29+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
30+
() -> HeaderTemplate.create(null, Collections.singletonList("test")));
31+
assertEquals("name is required.", exception.getMessage());
3632
}
3733

38-
@Test(expected = IllegalArgumentException.class)
34+
@Test
3935
public void it_should_throw_exception_when_name_is_empty() {
40-
HeaderTemplate.create("", Collections.singletonList("test"));
41-
exception.expectMessage("name is required.");
36+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
37+
() -> HeaderTemplate.create("", Collections.singletonList("test")));
38+
assertEquals("name is required.", exception.getMessage());
4239
}
4340

44-
@Test(expected = IllegalArgumentException.class)
41+
@Test
4542
public void it_should_throw_exception_when_value_is_null() {
46-
HeaderTemplate.create("test", null);
47-
exception.expectMessage("values are required");
43+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
44+
() -> HeaderTemplate.create("test", null));
45+
assertEquals("values are required", exception.getMessage());
4846
}
4947

5048
@Test
@@ -111,9 +109,8 @@ public void append_should_preserve_order() {
111109
public void it_should_support_http_date() {
112110
HeaderTemplate headerTemplate =
113111
HeaderTemplate.create("Expires", Collections.singletonList("{expires}"));
114-
assertEquals(
112+
assertEquals("Wed, 4 Jul 2001 12:08:56 -0700",
115113
headerTemplate.expand(
116-
Collections.singletonMap("expires", "Wed, 4 Jul 2001 12:08:56 -0700")),
117-
"Wed, 4 Jul 2001 12:08:56 -0700");
114+
Collections.singletonMap("expires", "Wed, 4 Jul 2001 12:08:56 -0700")));
118115
}
119116
}

example-github/src/test/java/feign/example/github/GitHubExampleIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
package feign.example.github;
1515

16-
import static org.junit.Assert.assertThat;
16+
import static org.hamcrest.MatcherAssert.assertThat;
1717
import org.apache.commons.exec.CommandLine;
1818
import org.apache.commons.exec.DefaultExecutor;
1919
import org.hamcrest.CoreMatchers;

example-wikipedia/src/test/java/feign/example/wikipedia/WikipediaExampleIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
package feign.example.wikipedia;
1515

16-
import static org.junit.Assert.assertThat;
16+
import static org.hamcrest.MatcherAssert.assertThat;
1717
import org.apache.commons.exec.CommandLine;
1818
import org.apache.commons.exec.DefaultExecutor;
1919
import org.hamcrest.CoreMatchers;

mock/src/test/java/feign/mock/MockTargetTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
package feign.mock;
1515

1616
import static org.hamcrest.Matchers.equalTo;
17-
import static org.junit.Assert.assertThat;
17+
import static org.hamcrest.MatcherAssert.assertThat;
1818
import org.junit.Before;
1919
import org.junit.Test;
2020

mock/src/test/java/feign/mock/RequestKeyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static org.hamcrest.Matchers.is;
2020
import static org.hamcrest.Matchers.not;
2121
import static org.hamcrest.Matchers.startsWith;
22-
import static org.junit.Assert.assertThat;
22+
import static org.hamcrest.MatcherAssert.assertThat;
2323
import java.nio.charset.StandardCharsets;
2424
import java.util.Arrays;
2525
import java.util.Collection;

ribbon/src/test/java/feign/ribbon/RibbonClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertNotNull;
2121
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertThat;
22+
import static org.hamcrest.MatcherAssert.assertThat;
2323
import static org.junit.Assert.assertTrue;
2424
import static org.junit.Assert.fail;
2525
import java.io.IOException;

0 commit comments

Comments
 (0)