Source:
<code>public void test_build_http_client_with_proxy() throws Exception { <START> String address = "109.196.210.110"; <END> int port = 8080; String login = "admin"; String password = "123"; Secret secret = mock(Secret.class); when(Secret.fromString(password)).thenReturn(secret); when(Secret.toString(secret)).thenReturn(password); when(secret.getPlainText()).thenReturn(password); when(httpClientBuilder.setProxy(any(HttpHost.class))).thenReturn(httpClientBuilder); when(httpClientBuilder.setDefaultCredentialsProvider(any(CredentialsProvider.class))).thenReturn(httpClientBuilder); when(httpClientBuilder.setProxyAuthenticationStrategy(any(AuthenticationStrategy.class))).thenReturn(httpClientBuilder); jenkins.proxy = new ProxyConfiguration(address, port, login, password); PrintStream logger = mock(PrintStream.class); sn.getHttpClient(logger, build); ArgumentCaptor<HttpHost> proxyCaptor = ArgumentCaptor.forClass(HttpHost.class); verify(httpClientBuilder).setProxy(proxyCaptor.capture()); HttpHost proxy = proxyCaptor.getValue(); assertThat(proxy.getHostName(), is(address)); assertThat(proxy.getPort(), is(port)); assertThat(proxy.getSchemeName(), is("http")); ArgumentCaptor<CredentialsProvider> credentialsProviderCaptor = ArgumentCaptor.forClass(CredentialsProvider.class); verify(httpClientBuilder).setDefaultCredentialsProvider(credentialsProviderCaptor.capture()); CredentialsProvider credentialsProvider = credentialsProviderCaptor.getValue(); org.apache.http.auth.UsernamePasswordCredentials credentials = (UsernamePasswordCredentials) credentialsProvider.getCredentials(new AuthScope(proxy)); assertThat(credentials.getUserName(), is(login)); assertThat(credentials.getPassword(), is(password)); }</code><technical_language>public IP for mock data. Replace private network IP please</technical_language>

Target:
public void test_build_http_client_with_proxy() throws Exception { StashNotifier sn = spy(this.sn); doReturn(new ArrayList<Credentials>()).when(sn).lookupCredentials( Mockito.<Class>anyObject(), Mockito.<Item>anyObject(), Mockito.<Authentication>anyObject(), Mockito.<ArrayList<DomainRequirement>>anyObject()); String address = "192.168.1.1"; int port = 8080; String login = "admin"; String password = "123"; Secret secret = mock(Secret.class); when(Secret.fromString(password)).thenReturn(secret); when(Secret.toString(secret)).thenReturn(password); when(secret.getPlainText()).thenReturn(password); when(httpClientBuilder.setProxy(any(HttpHost.class))).thenReturn(httpClientBuilder); when(httpClientBuilder.setDefaultCredentialsProvider(any(CredentialsProvider.class))).thenReturn(httpClientBuilder); when(httpClientBuilder.setProxyAuthenticationStrategy(any(AuthenticationStrategy.class))).thenReturn(httpClientBuilder); jenkins.proxy = new ProxyConfiguration(address, port, login, password); PrintStream logger = mock(PrintStream.class); sn.getHttpClient(logger, build); ArgumentCaptor<HttpHost> proxyCaptor = ArgumentCaptor.forClass(HttpHost.class); verify(httpClientBuilder).setProxy(proxyCaptor.capture()); HttpHost proxy = proxyCaptor.getValue(); assertThat(proxy.getHostName(), is(address)); assertThat(proxy.getPort(), is(port)); assertThat(proxy.getSchemeName(), is("http")); ArgumentCaptor<CredentialsProvider> credentialsProviderCaptor = ArgumentCaptor.forClass(CredentialsProvider.class); verify(httpClientBuilder).setDefaultCredentialsProvider(credentialsProviderCaptor.capture()); CredentialsProvider credentialsProvider = credentialsProviderCaptor.getValue(); org.apache.http.auth.UsernamePasswordCredentials credentials = (UsernamePasswordCredentials) credentialsProvider.getCredentials(new AuthScope(proxy)); assertThat(credentials.getUserName(), is(login)); assertThat(credentials.getPassword(), is(password)); }