3030import org .apache .hc .client5 .http .impl .classic .RedirectExec ;
3131import org .apache .hc .client5 .http .protocol .RedirectStrategy ;
3232import org .assertj .core .extractor .Extractors ;
33+ import org .jspecify .annotations .Nullable ;
3334import org .junit .jupiter .api .Test ;
3435
3536import org .springframework .boot .http .client .ClientHttpRequestFactoryBuilder ;
@@ -203,13 +204,14 @@ private RequestConfig getRequestConfig(TestRestTemplate template) {
203204 return (RequestConfig ) Extractors .byName ("httpClient.defaultConfig" ).apply (requestFactory );
204205 }
205206
206- private RedirectStrategy getRedirectStrategy (RestTemplateBuilder builder , HttpClientOption ... httpClientOptions ) {
207+ private @ Nullable RedirectStrategy getRedirectStrategy (@ Nullable RestTemplateBuilder builder ,
208+ HttpClientOption ... httpClientOptions ) {
207209 builder = (builder != null ) ? builder : new RestTemplateBuilder ();
208210 TestRestTemplate template = new TestRestTemplate (builder , null , null , httpClientOptions );
209211 return getRedirectStrategy (template );
210212 }
211213
212- private RedirectStrategy getRedirectStrategy (TestRestTemplate template ) {
214+ private @ Nullable RedirectStrategy getRedirectStrategy (TestRestTemplate template ) {
213215 ClientHttpRequestFactory requestFactory = template .getRestTemplate ().getRequestFactory ();
214216 Object chain = Extractors .byName ("httpClient.execChain" ).apply (requestFactory );
215217 while (chain != null ) {
@@ -233,7 +235,9 @@ private boolean isDontFollowStrategy(RedirectStrategy redirectStrategy) {
233235 private HttpClient getJdkHttpClient (TestRestTemplate template ) {
234236 JdkClientHttpRequestFactory requestFactory = (JdkClientHttpRequestFactory ) template .getRestTemplate ()
235237 .getRequestFactory ();
236- return (HttpClient ) ReflectionTestUtils .getField (requestFactory , "httpClient" );
238+ HttpClient httpClient = (HttpClient ) ReflectionTestUtils .getField (requestFactory , "httpClient" );
239+ assertThat (httpClient ).isNotNull ();
240+ return httpClient ;
237241 }
238242
239243 @ Test
@@ -459,10 +463,11 @@ private void verifyRelativeUriHandling(TestRestTemplateCallback callback) throws
459463 then (requestFactory ).should ().createRequest (eq (absoluteUri ), any (HttpMethod .class ));
460464 }
461465
462- private void assertBasicAuthorizationCredentials (TestRestTemplate testRestTemplate , String username ,
463- String password ) {
466+ private void assertBasicAuthorizationCredentials (TestRestTemplate testRestTemplate , @ Nullable String username ,
467+ @ Nullable String password ) {
464468 ClientHttpRequest request = ReflectionTestUtils .invokeMethod (testRestTemplate .getRestTemplate (),
465469 "createRequest" , URI .create ("http://localhost" ), HttpMethod .POST );
470+ assertThat (request ).isNotNull ();
466471 if (username == null ) {
467472 assertThat (request .getHeaders ().headerNames ()).doesNotContain (HttpHeaders .AUTHORIZATION );
468473 }
0 commit comments