@@ -116,7 +116,7 @@ public void methodTeardown() {
116116 }
117117
118118 @ Test
119- public void canMakeHttpsRequestWhenKeyProviderConfigured () throws IOException {
119+ public void prepareRequest_whenKeyProviderConfigured_successfullyMakesHttpsRequest () throws IOException {
120120 client = Apache5HttpClient .builder ()
121121 .tlsKeyManagersProvider (keyManagersProvider )
122122 .build ();
@@ -125,13 +125,13 @@ public void canMakeHttpsRequestWhenKeyProviderConfigured() throws IOException {
125125 }
126126
127127 @ Test
128- public void requestFailsWhenKeyProviderNotConfigured () throws IOException {
128+ public void prepareRequest_whenKeyProviderNotConfigured_throwsSslException () throws IOException {
129129 client = Apache5HttpClient .builder ().tlsKeyManagersProvider (NoneTlsKeyManagersProvider .getInstance ()).build ();
130130 assertThatThrownBy (() -> makeRequestWithHttpClient (client )).isInstanceOfAny (SSLException .class , SocketException .class );
131131 }
132132
133133 @ Test
134- public void authenticatesWithTlsProxy () throws IOException {
134+ public void prepareRequest_whenTlsProxyConfigured_authenticatesSuccessfully () throws IOException {
135135 ProxyConfiguration proxyConfig = ProxyConfiguration .builder ()
136136 .endpoint (URI .create ("https://localhost:" + wireMockServer .httpsPort ()))
137137 .build ();
@@ -148,7 +148,7 @@ public void authenticatesWithTlsProxy() throws IOException {
148148 }
149149
150150 @ Test
151- public void defaultTlsKeyManagersProviderIsSystemPropertyProvider () throws IOException {
151+ public void build_whenNoTlsKeyManagersProviderSet_usesSystemPropertyProvider () throws IOException {
152152 System .setProperty (SSL_KEY_STORE .property (), clientKeyStore .toAbsolutePath ().toString ());
153153 System .setProperty (SSL_KEY_STORE_TYPE .property (), CLIENT_STORE_TYPE );
154154 System .setProperty (SSL_KEY_STORE_PASSWORD .property (), STORE_PASSWORD );
@@ -164,7 +164,7 @@ public void defaultTlsKeyManagersProviderIsSystemPropertyProvider() throws IOExc
164164 }
165165
166166 @ Test
167- public void defaultTlsKeyManagersProviderIsSystemPropertyProvider_explicitlySetToNull () throws IOException {
167+ public void build_whenTlsKeyManagersProviderExplicitlySetToNull_usesSystemPropertyProvider () throws IOException {
168168 System .setProperty (SSL_KEY_STORE .property (), clientKeyStore .toAbsolutePath ().toString ());
169169 System .setProperty (SSL_KEY_STORE_TYPE .property (), CLIENT_STORE_TYPE );
170170 System .setProperty (SSL_KEY_STORE_PASSWORD .property (), STORE_PASSWORD );
@@ -180,7 +180,7 @@ public void defaultTlsKeyManagersProviderIsSystemPropertyProvider_explicitlySetT
180180 }
181181
182182 @ Test
183- public void build_notSettingSocketFactory_configuresClientWithDefaultSocketFactory () throws Exception {
183+ public void build_whenSocketFactoryNotSet_configuresDefaultSocketFactory () throws Exception {
184184 System .setProperty (SSL_KEY_STORE .property (), clientKeyStore .toAbsolutePath ().toString ());
185185 System .setProperty (SSL_KEY_STORE_TYPE .property (), CLIENT_STORE_TYPE );
186186 System .setProperty (SSL_KEY_STORE_PASSWORD .property (), STORE_PASSWORD );
@@ -212,7 +212,7 @@ public void build_notSettingSocketFactory_configuresClientWithDefaultSocketFacto
212212 }
213213
214214 @ Test
215- public void build_settingCustomSocketFactory_configuresClientWithGivenSocketFactory () throws IOException ,
215+ public void build_whenCustomSocketFactorySet_usesProvidedSocketFactory () throws IOException ,
216216 NoSuchAlgorithmException ,
217217 KeyManagementException {
218218 TlsKeyManagersProvider provider = FileStoreTlsKeyManagersProvider .create (clientKeyStore ,
@@ -259,7 +259,7 @@ private HttpExecuteResponse makeRequestWithHttpClient(SdkHttpClient httpClient)
259259 }
260260
261261 @ Test
262- public void tls_strategy_configuration () throws Exception {
262+ public void build_whenTlsSocketStrategyConfigured_usesProvidedStrategy () throws Exception {
263263 // Setup TLS context
264264 KeyManager [] keyManagers = keyManagersProvider .keyManagers ();
265265 SSLContext sslContext = SSLContext .getInstance ("TLS" );
@@ -289,45 +289,32 @@ public void tls_strategy_configuration() throws Exception {
289289 }
290290
291291 @ Test
292- public void tls_strategy_overrides_legacy_factory () throws Exception {
292+ public void build_whenBothTlsStrategyAndLegacyFactorySet_throwsIllegalArgumentException () throws Exception {
293293 // Setup TLS context
294294 KeyManager [] keyManagers = keyManagersProvider .keyManagers ();
295295 SSLContext sslContext = SSLContext .getInstance ("TLS" );
296296 sslContext .init (keyManagers , null , null );
297297
298- // Create spies for both approaches
298+ // Create both socket factory and TLS strategy
299299 SSLConnectionSocketFactory legacyFactory = new SSLConnectionSocketFactory (
300300 sslContext ,
301301 NoopHostnameVerifier .INSTANCE
302302 );
303- SSLConnectionSocketFactory legacyFactorySpy = Mockito .spy (legacyFactory );
304303
305304 TlsSocketStrategy tlsStrategy = new SdkTlsSocketFactory (
306305 sslContext ,
307306 NoopHostnameVerifier .INSTANCE
308307 );
309- TlsSocketStrategy tlsStrategySpy = Mockito .spy (tlsStrategy );
310-
311- // Build client with both - TLS strategy should take precedence
312- client = Apache5HttpClient .builder ()
313- .socketFactory (legacyFactorySpy )
314- .tlsSocketStrategy (tlsStrategySpy ) // This should override
315- .build ();
316-
317- // Make request
318- HttpExecuteResponse response = makeRequestWithHttpClient (client );
319- assertThat (response .httpResponse ().isSuccessful ()).isTrue ();
320-
321- // Verify only TLS strategy was used, not legacy
322- Mockito .verify (tlsStrategySpy ).upgrade (
323- Mockito .any (Socket .class ),
324- Mockito .anyString (),
325- Mockito .anyInt (),
326- Mockito .any (),
327- Mockito .any (HttpContext .class )
328- );
329308
330- Mockito .verifyNoInteractions (legacyFactorySpy );
309+ // Attempt to build client with both - should throw exception
310+ assertThatThrownBy (() -> Apache5HttpClient .builder ()
311+ .socketFactory (legacyFactory )
312+ .tlsSocketStrategy (tlsStrategy )
313+ .build ())
314+ .isInstanceOf (IllegalArgumentException .class )
315+ .hasMessageContaining ("Cannot configure both tlsSocketStrategy and socketFactory" )
316+ .hasMessageContaining ("deprecated" )
317+ .hasMessageContaining ("use tlsSocketStrategy" );
331318 }
332319
333320}
0 commit comments