4040import okhttp3 .mockwebserver .MockResponse ;
4141import okhttp3 .mockwebserver .MockWebServer ;
4242import okhttp3 .mockwebserver .RecordedRequest ;
43+
44+ import org .junit .After ;
4345import org .junit .Rule ;
4446import org .junit .Test ;
4547import org .junit .experimental .theories .DataPoint ;
5153
5254import static java .lang .String .format ;
5355import static org .assertj .core .api .Assertions .assertThat ;
56+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
5457import static org .assertj .core .api .Assertions .fail ;
5558import static org .mockito .Mockito .mock ;
5659
@@ -65,10 +68,16 @@ public class OkHttpClientFactoryTest {
6568 private static final String KEYSTORE_PASSWORD = "abcdef" ;
6669 private static final String KEYSTORE_FILE = "/server.jks" ;
6770 private static final Logger logger = mock (Logger .class );
71+ private static final String SONAR_WS_TIMEOUT = "sonar.ws.timeout" ;
6872
6973 @ Rule
7074 public ExpectedException expectedException = ExpectedException .none ();
7175
76+ @ After
77+ public void cleanSystemProperty () {
78+ System .clearProperty (SONAR_WS_TIMEOUT );
79+ }
80+
7281 @ Test
7382 public void support_tls_versions_of_java8 () {
7483 OkHttpClient underTest = OkHttpClientFactory .create (logger );
@@ -77,6 +86,25 @@ public void support_tls_versions_of_java8() {
7786 assertThat (underTest .sslSocketFactory ()).isInstanceOf (SSLSocketFactory .getDefault ().getClass ());
7887 }
7988
89+ @ Test
90+ public void support_custom_timeouts () {
91+ int readTimeout = 2000 ;
92+ System .setProperty (SONAR_WS_TIMEOUT , String .valueOf (readTimeout ));
93+
94+ Logger logger = mock (Logger .class );
95+ OkHttpClient underTest = OkHttpClientFactory .create (logger );
96+
97+ assertThat (underTest .readTimeoutMillis ()).isEqualTo (readTimeout );
98+ }
99+
100+ @ Test
101+ public void support_custom_timeouts_throws_exception_on_non_number () {
102+ System .setProperty (SONAR_WS_TIMEOUT , "fail" );
103+
104+ Logger logger = mock (Logger .class );
105+ assertThatThrownBy (() -> OkHttpClientFactory .create (logger )).isInstanceOf (NumberFormatException .class );
106+ }
107+
80108 private void assertTlsAndClearTextSpecifications (OkHttpClient client ) {
81109 List <ConnectionSpec > connectionSpecs = client .connectionSpecs ();
82110 assertThat (connectionSpecs ).hasSize (2 );
0 commit comments