45
45
import org .springframework .util .StreamUtils ;
46
46
import org .springframework .web .util .DefaultUriBuilderFactory ;
47
47
48
- import static org .junit .Assert .*;
49
- import static org .mockito .BDDMockito .*;
48
+ import static org .junit .Assert .assertEquals ;
49
+ import static org .junit .Assert .assertFalse ;
50
+ import static org .junit .Assert .assertNull ;
51
+ import static org .junit .Assert .assertSame ;
52
+ import static org .junit .Assert .fail ;
53
+ import static org .mockito .BDDMockito .any ;
54
+ import static org .mockito .BDDMockito .eq ;
55
+ import static org .mockito .BDDMockito .given ;
56
+ import static org .mockito .BDDMockito .mock ;
57
+ import static org .mockito .BDDMockito .verify ;
58
+ import static org .mockito .BDDMockito .willThrow ;
59
+ import static org .springframework .http .MediaType .parseMediaType ;
50
60
51
61
/**
52
62
* @author Arjen Poutsma
@@ -706,9 +716,7 @@ public void optionsForAllow() throws Exception {
706
716
verify (response ).close ();
707
717
}
708
718
709
- // Issue: SPR-9325, SPR-13860
710
-
711
- @ Test
719
+ @ Test // Issue: SPR-9325, SPR-13860
712
720
public void ioException () throws Exception {
713
721
String url = "http://example.com/resource?access_token=123" ;
714
722
@@ -730,6 +738,29 @@ public void ioException() throws Exception {
730
738
}
731
739
}
732
740
741
+ @ Test // SPR-15900
742
+ public void ioExceptionWithEmptyQueryString () throws Exception {
743
+
744
+ // http://example.com/resource?
745
+ URI uri = new URI ("http" , "example.com" , "/resource" , "" , null );
746
+
747
+ given (converter .canRead (String .class , null )).willReturn (true );
748
+ given (converter .getSupportedMediaTypes ()).willReturn (Collections .singletonList (parseMediaType ("foo/bar" )));
749
+ given (requestFactory .createRequest (uri , HttpMethod .GET )).willReturn (request );
750
+ given (request .getHeaders ()).willReturn (new HttpHeaders ());
751
+ given (request .execute ()).willThrow (new IOException ("Socket failure" ));
752
+
753
+ try {
754
+ template .getForObject (uri , String .class );
755
+ fail ("RestClientException expected" );
756
+ }
757
+ catch (ResourceAccessException ex ) {
758
+ assertEquals ("I/O error on GET request for \" http://example.com/resource\" : " +
759
+ "Socket failure; nested exception is java.io.IOException: Socket failure" ,
760
+ ex .getMessage ());
761
+ }
762
+ }
763
+
733
764
@ Test
734
765
public void exchange () throws Exception {
735
766
given (converter .canRead (Integer .class , null )).willReturn (true );
0 commit comments