3636import java .util .concurrent .atomic .AtomicReference ;
3737
3838import feign .Target .HardCodedTarget ;
39+ import feign .codec .DecodeException ;
3940import feign .codec .Decoder ;
4041import feign .codec .EncodeException ;
4142import feign .codec .Encoder ;
@@ -55,7 +56,7 @@ public class FeignTest {
5556 public final MockWebServerRule server = new MockWebServerRule ();
5657
5758 @ Test
58- public void iterableQueryParams () throws IOException , InterruptedException {
59+ public void iterableQueryParams () throws Exception {
5960 server .enqueue (new MockResponse ().setBody ("foo" ));
6061
6162 TestInterface api = new TestInterfaceBuilder ().target ("http://localhost:" + server .getPort ());
@@ -67,7 +68,7 @@ public void iterableQueryParams() throws IOException, InterruptedException {
6768 }
6869
6970 @ Test
70- public void postTemplateParamsResolve () throws IOException , InterruptedException {
71+ public void postTemplateParamsResolve () throws Exception {
7172 server .enqueue (new MockResponse ().setBody ("foo" ));
7273
7374 TestInterface api = new TestInterfaceBuilder ().target ("http://localhost:" + server .getPort ());
@@ -80,7 +81,7 @@ public void postTemplateParamsResolve() throws IOException, InterruptedException
8081 }
8182
8283 @ Test
83- public void responseCoercesToStringBody () throws IOException , InterruptedException {
84+ public void responseCoercesToStringBody () throws Exception {
8485 server .enqueue (new MockResponse ().setBody ("foo" ));
8586
8687 TestInterface api = new TestInterfaceBuilder ().target ("http://localhost:" + server .getPort ());
@@ -91,7 +92,7 @@ public void responseCoercesToStringBody() throws IOException, InterruptedExcepti
9192 }
9293
9394 @ Test
94- public void postFormParams () throws IOException , InterruptedException {
95+ public void postFormParams () throws Exception {
9596 server .enqueue (new MockResponse ().setBody ("foo" ));
9697
9798 TestInterface api = new TestInterfaceBuilder ().target ("http://localhost:" + server .getPort ());
@@ -104,7 +105,7 @@ public void postFormParams() throws IOException, InterruptedException {
104105 }
105106
106107 @ Test
107- public void postBodyParam () throws IOException , InterruptedException {
108+ public void postBodyParam () throws Exception {
108109 server .enqueue (new MockResponse ().setBody ("foo" ));
109110
110111 TestInterface api = new TestInterfaceBuilder ().target ("http://localhost:" + server .getPort ());
@@ -121,15 +122,14 @@ public void postBodyParam() throws IOException, InterruptedException {
121122 * type.
122123 */
123124 @ Test
124- public void bodyTypeCorrespondsWithParameterType () throws IOException , InterruptedException {
125+ public void bodyTypeCorrespondsWithParameterType () throws Exception {
125126 server .enqueue (new MockResponse ().setBody ("foo" ));
126127
127128 final AtomicReference <Type > encodedType = new AtomicReference <Type >();
128129 TestInterface api = new TestInterfaceBuilder ()
129130 .encoder (new Encoder .Default () {
130131 @ Override
131- public void encode (Object object , Type bodyType , RequestTemplate template )
132- throws EncodeException {
132+ public void encode (Object object , Type bodyType , RequestTemplate template ) {
133133 encodedType .set (bodyType );
134134 }
135135 })
@@ -144,7 +144,7 @@ public void encode(Object object, Type bodyType, RequestTemplate template)
144144 }
145145
146146 @ Test
147- public void postGZIPEncodedBodyParam () throws IOException , InterruptedException {
147+ public void postGZIPEncodedBodyParam () throws Exception {
148148 server .enqueue (new MockResponse ().setBody ("foo" ));
149149
150150 TestInterface api = new TestInterfaceBuilder ().target ("http://localhost:" + server .getPort ());
@@ -157,7 +157,7 @@ public void postGZIPEncodedBodyParam() throws IOException, InterruptedException
157157 }
158158
159159 @ Test
160- public void singleInterceptor () throws IOException , InterruptedException {
160+ public void singleInterceptor () throws Exception {
161161 server .enqueue (new MockResponse ().setBody ("foo" ));
162162
163163 TestInterface api = new TestInterfaceBuilder ()
@@ -171,7 +171,7 @@ public void singleInterceptor() throws IOException, InterruptedException {
171171 }
172172
173173 @ Test
174- public void multipleInterceptor () throws IOException , InterruptedException {
174+ public void multipleInterceptor () throws Exception {
175175 server .enqueue (new MockResponse ().setBody ("foo" ));
176176
177177 TestInterface api = new TestInterfaceBuilder ()
@@ -208,7 +208,7 @@ public void toKeyMethodFormatsAsExpected() throws Exception {
208208 }
209209
210210 @ Test
211- public void canOverrideErrorDecoder () throws IOException , InterruptedException {
211+ public void canOverrideErrorDecoder () throws Exception {
212212 server .enqueue (new MockResponse ().setResponseCode (404 ).setBody ("foo" ));
213213 thrown .expect (IllegalArgumentException .class );
214214 thrown .expectMessage ("zone not found" );
@@ -221,7 +221,7 @@ public void canOverrideErrorDecoder() throws IOException, InterruptedException {
221221 }
222222
223223 @ Test
224- public void retriesLostConnectionBeforeRead () throws IOException , InterruptedException {
224+ public void retriesLostConnectionBeforeRead () throws Exception {
225225 server .enqueue (new MockResponse ().setSocketPolicy (SocketPolicy .DISCONNECT_AT_START ));
226226 server .enqueue (new MockResponse ().setBody ("success!" ));
227227
@@ -233,7 +233,7 @@ public void retriesLostConnectionBeforeRead() throws IOException, InterruptedExc
233233 }
234234
235235 @ Test
236- public void overrideTypeSpecificDecoder () throws IOException , InterruptedException {
236+ public void overrideTypeSpecificDecoder () throws Exception {
237237 server .enqueue (new MockResponse ().setBody ("success!" ));
238238
239239 TestInterface api = new TestInterfaceBuilder ()
@@ -251,7 +251,7 @@ public Object decode(Response response, Type type) {
251251 * when you must parse a 2xx status to determine if the operation succeeded or not.
252252 */
253253 @ Test
254- public void retryableExceptionInDecoder () throws IOException , InterruptedException {
254+ public void retryableExceptionInDecoder () throws Exception {
255255 server .enqueue (new MockResponse ().setBody ("retry!" ));
256256 server .enqueue (new MockResponse ().setBody ("success!" ));
257257
@@ -272,26 +272,54 @@ public Object decode(Response response, Type type) throws IOException {
272272 }
273273
274274 @ Test
275- public void doesntRetryAfterResponseIsSent () throws IOException , InterruptedException {
275+ public void doesntRetryAfterResponseIsSent () throws Exception {
276276 server .enqueue (new MockResponse ().setBody ("success!" ));
277277 thrown .expect (FeignException .class );
278- thrown .expectMessage ("error reading response POST http://" );
278+ thrown .expectMessage ("timeout reading POST http://" );
279279
280280 TestInterface api = new TestInterfaceBuilder ()
281281 .decoder (new Decoder () {
282282 @ Override
283283 public Object decode (Response response , Type type ) throws IOException {
284- throw new IOException ("error reading response " );
284+ throw new IOException ("timeout " );
285285 }
286286 }).target ("http://localhost:" + server .getPort ());
287287
288- try {
289- api .post ();
290- } finally {
291- assertEquals (1 , server .getRequestCount ());
292- }
288+ api .post ();
293289 }
294290
291+ @ Test
292+ public void okIfDecodeRootCauseHasNoMessage () throws Exception {
293+ server .enqueue (new MockResponse ().setBody ("success!" ));
294+ thrown .expect (DecodeException .class );
295+
296+ TestInterface api = new TestInterfaceBuilder ()
297+ .decoder (new Decoder () {
298+ @ Override
299+ public Object decode (Response response , Type type ) throws IOException {
300+ throw new RuntimeException ();
301+ }
302+ }).target ("http://localhost:" + server .getPort ());
303+
304+ api .post ();
305+ }
306+
307+ @ Test
308+ public void okIfEncodeRootCauseHasNoMessage () throws Exception {
309+ server .enqueue (new MockResponse ().setBody ("success!" ));
310+ thrown .expect (EncodeException .class );
311+
312+ TestInterface api = new TestInterfaceBuilder ()
313+ .encoder (new Encoder () {
314+ @ Override
315+ public void encode (Object object , Type bodyType , RequestTemplate template ) {
316+ throw new RuntimeException ();
317+ }
318+ }).target ("http://localhost:" + server .getPort ());
319+
320+ api .body (Arrays .asList ("foo" ));
321+ }
322+
295323 @ Test
296324 public void equalsHashCodeAndToStringWork () {
297325 Target <TestInterface >
0 commit comments