Skip to content

Commit 192ef11

Browse files
authored
Create unit test for JAXRS2Contract (OpenFeign#695)
1 parent ecd928a commit 192ef11

7 files changed

Lines changed: 83 additions & 12 deletions

File tree

httpclient/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@
5555
<scope>test</scope>
5656
</dependency>
5757

58-
<dependency>
59-
<artifactId>jsr311-api</artifactId>
60-
<version>1.1.1</version>
61-
<groupId>javax.ws.rs</groupId>
62-
<scope>test</scope>
63-
</dependency>
64-
6558
<dependency>
6659
<groupId>com.squareup.okhttp3</groupId>
6760
<artifactId>mockwebserver</artifactId>

jaxrs/pom.xml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@
3737
</dependency>
3838

3939
<dependency>
40+
<groupId>javax.ws.rs</groupId>
4041
<artifactId>jsr311-api</artifactId>
4142
<version>1.1.1</version>
42-
<groupId>javax.ws.rs</groupId>
43-
<scope>provided</scope>
4443
</dependency>
4544

4645
<!-- for example -->
@@ -57,4 +56,20 @@
5756
<scope>test</scope>
5857
</dependency>
5958
</dependencies>
59+
60+
<build>
61+
<plugins>
62+
<plugin>
63+
<artifactId>maven-jar-plugin</artifactId>
64+
<executions>
65+
<execution>
66+
<goals>
67+
<goal>test-jar</goal>
68+
</goals>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
</plugins>
73+
</build>
6074
</project>
75+

jaxrs/src/test/java/feign/jaxrs/JAXRSContractTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ public class JAXRSContractTest {
5454
private static final List<String> STRING_LIST = null;
5555
@Rule
5656
public final ExpectedException thrown = ExpectedException.none();
57-
JAXRSContract contract = new JAXRSContract();
57+
JAXRSContract contract = createContract();
58+
59+
protected JAXRSContract createContract() {
60+
return new JAXRSContract();
61+
}
5862

5963
@Test
6064
public void httpMethods() throws Exception {
@@ -179,7 +183,7 @@ public void bodyParamIsGeneric() throws Exception {
179183
assertThat(md.bodyIndex())
180184
.isEqualTo(0);
181185
assertThat(md.bodyType())
182-
.isEqualTo(getClass().getDeclaredField("STRING_LIST").getGenericType());
186+
.isEqualTo(JAXRSContractTest.class.getDeclaredField("STRING_LIST").getGenericType());
183187
}
184188

185189
@Test

jaxrs2/pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
<description>Feign JAX-RS 2</description>
2828

2929
<properties>
30+
<!-- override default bytecode version for src/main from parent pom -->
31+
<main.java.version>1.8</main.java.version>
32+
<main.signature.artifact>java18</main.signature.artifact>
3033
<main.basedir>${project.basedir}/..</main.basedir>
34+
<maven.compiler.source>1.8</maven.compiler.source>
35+
<maven.compiler.target>1.8</maven.compiler.target>
3136
</properties>
3237

3338
<dependencies>
@@ -39,6 +44,12 @@
3944
<dependency>
4045
<groupId>${project.groupId}</groupId>
4146
<artifactId>feign-jaxrs</artifactId>
47+
<exclusions>
48+
<exclusion>
49+
<groupId>javax.ws.rs</groupId>
50+
<artifactId>jsr311-api</artifactId>
51+
</exclusion>
52+
</exclusions>
4253
</dependency>
4354

4455
<dependency>
@@ -61,5 +72,11 @@
6172
<type>test-jar</type>
6273
<scope>test</scope>
6374
</dependency>
75+
<dependency>
76+
<groupId>${project.groupId}</groupId>
77+
<artifactId>feign-jaxrs</artifactId>
78+
<type>test-jar</type>
79+
<scope>test</scope>
80+
</dependency>
6481
</dependencies>
6582
</project>

jaxrs2/src/main/java/feign/jaxrs/JAXRS2Contract.java renamed to jaxrs2/src/main/java/feign/jaxrs2/JAXRS2Contract.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
* or implied. See the License for the specific language governing permissions and limitations under
1212
* the License.
1313
*/
14-
package feign.jaxrs;
14+
package feign.jaxrs2;
1515

1616
import javax.ws.rs.container.Suspended;
1717
import javax.ws.rs.core.Context;
18+
19+
import feign.jaxrs.JAXRSContract;
20+
1821
import java.lang.annotation.Annotation;
1922

2023
/**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright 2012-2018 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.jaxrs2;
15+
16+
import feign.jaxrs.JAXRSContract;
17+
import feign.jaxrs.JAXRSContractTest;
18+
19+
/**
20+
* Tests interfaces defined per {@link JAXRS2Contract} are interpreted into expected {@link feign
21+
* .RequestTemplate template} instances.
22+
*/
23+
public class JAXRS2ContractTest extends JAXRSContractTest
24+
{
25+
26+
@Override
27+
protected JAXRSContract createContract()
28+
{
29+
return new JAXRS2Contract();
30+
}
31+
32+
}

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@
192192
<version>${project.version}</version>
193193
</dependency>
194194

195+
<dependency>
196+
<groupId>${project.groupId}</groupId>
197+
<artifactId>feign-jaxrs</artifactId>
198+
<version>${project.version}</version>
199+
<type>test-jar</type>
200+
</dependency>
201+
195202
<dependency>
196203
<groupId>${project.groupId}</groupId>
197204
<artifactId>feign-jaxrs2</artifactId>

0 commit comments

Comments
 (0)