@@ -84,10 +84,6 @@ void crossHostRedirectStripsAuthHeaders() throws Exception {
8484
8585 // Mock chain to get client without proxy
8686 Interceptor .Chain chain = mock (Interceptor .Chain .class );
87- Call call = mock (Call .class );
88- OkHttpClient client = new OkHttpClient .Builder ().build ();
89- when (chain .call ()).thenReturn (call );
90- when (call .client ()).thenReturn (client );
9187
9288 RedirectHandlerOption option = new RedirectHandlerOption ();
9389 Request result = new RedirectHandler ().getRedirect (original , redirect , option , chain );
@@ -143,17 +139,12 @@ void sameHostRedirectKeepsAllHeaders() throws Exception {
143139
144140 // Mock chain with proxy
145141 Interceptor .Chain chain = mock (Interceptor .Chain .class );
146- Call call = mock (Call .class );
147142 ProxySelector proxySelector = mock (ProxySelector .class );
148143 Proxy proxy = new Proxy (Proxy .Type .HTTP , new InetSocketAddress ("proxy.example.com" , 8080 ));
149144 when (proxySelector .select (any (URI .class ))).thenReturn (Collections .singletonList (proxy ));
150145
151- OkHttpClient client = new OkHttpClient .Builder ().proxySelector (proxySelector ).build ();
152- when (chain .call ()).thenReturn (call );
153- when (call .client ()).thenReturn (client );
154-
155146 RedirectHandlerOption option = new RedirectHandlerOption ();
156- Request result = new RedirectHandler ().getRedirect (original , redirect , option , chain );
147+ Request result = new RedirectHandler (option , proxySelector ).getRedirect (original , redirect , option , chain );
157148
158149 assertNotNull (result );
159150 assertEquals ("trusted.example.com" , result .url ().host ());
@@ -183,17 +174,12 @@ void crossHostRedirectWithProxyKeepsProxyAuth() throws Exception {
183174
184175 // Mock chain with active proxy
185176 Interceptor .Chain chain = mock (Interceptor .Chain .class );
186- Call call = mock (Call .class );
187177 ProxySelector proxySelector = mock (ProxySelector .class );
188178 Proxy proxy = new Proxy (Proxy .Type .HTTP , new InetSocketAddress ("proxy.example.com" , 8080 ));
189179 when (proxySelector .select (any (URI .class ))).thenReturn (Collections .singletonList (proxy ));
190180
191- OkHttpClient client = new OkHttpClient .Builder ().proxySelector (proxySelector ).build ();
192- when (chain .call ()).thenReturn (call );
193- when (call .client ()).thenReturn (client );
194-
195181 RedirectHandlerOption option = new RedirectHandlerOption ();
196- Request result = new RedirectHandler ().getRedirect (original , redirect , option , chain );
182+ Request result = new RedirectHandler (option , proxySelector ).getRedirect (original , redirect , option , chain );
197183
198184 assertNotNull (result );
199185 assertEquals ("other.example.com" , result .url ().host ());
@@ -224,17 +210,12 @@ void crossHostRedirectWithDirectProxyStripsProxyAuth() throws Exception {
224210
225211 // Mock chain with DIRECT proxy (no proxy)
226212 Interceptor .Chain chain = mock (Interceptor .Chain .class );
227- Call call = mock (Call .class );
228213 ProxySelector proxySelector = mock (ProxySelector .class );
229214 when (proxySelector .select (any (URI .class )))
230215 .thenReturn (Collections .singletonList (Proxy .NO_PROXY ));
231216
232- OkHttpClient client = new OkHttpClient .Builder ().proxySelector (proxySelector ).build ();
233- when (chain .call ()).thenReturn (call );
234- when (call .client ()).thenReturn (client );
235-
236217 RedirectHandlerOption option = new RedirectHandlerOption ();
237- Request result = new RedirectHandler ().getRedirect (original , redirect , option , chain );
218+ Request result = new RedirectHandler (option , proxySelector ).getRedirect (original , redirect , option , chain );
238219
239220 assertNotNull (result );
240221 assertEquals ("other.example.com" , result .url ().host ());
@@ -268,10 +249,6 @@ void schemeChangeStripsAuthHeaders() throws Exception {
268249
269250 // Mock chain without proxy
270251 Interceptor .Chain chain = mock (Interceptor .Chain .class );
271- Call call = mock (Call .class );
272- OkHttpClient client = new OkHttpClient .Builder ().build ();
273- when (chain .call ()).thenReturn (call );
274- when (call .client ()).thenReturn (client );
275252
276253 RedirectHandlerOption option = new RedirectHandlerOption ();
277254 Request result = new RedirectHandler ().getRedirect (original , redirect , option , chain );
@@ -310,10 +287,6 @@ void customScrubberIsUsed() throws Exception {
310287
311288 // Mock chain
312289 Interceptor .Chain chain = mock (Interceptor .Chain .class );
313- Call call = mock (Call .class );
314- OkHttpClient client = new OkHttpClient .Builder ().build ();
315- when (chain .call ()).thenReturn (call );
316- when (call .client ()).thenReturn (client );
317290
318291 RedirectHandlerOption option = new RedirectHandlerOption (5 , null , customScrubber );
319292 Request result = new RedirectHandler ().getRedirect (original , redirect , option , chain );
0 commit comments