|
9 | 9 | import java.util.List; |
10 | 10 | import java.util.logging.Level; |
11 | 11 | import java.util.stream.Collectors; |
| 12 | +import org.apache.http.impl.client.CloseableHttpClient; |
| 13 | +import org.apache.http.impl.client.HttpClientBuilder; |
12 | 14 | import org.junit.Assert; |
13 | 15 | import org.junit.Rule; |
14 | 16 | import org.junit.Test; |
15 | 17 | import org.jvnet.hudson.test.JenkinsRule; |
16 | 18 | import org.jvnet.hudson.test.LoggerRule; |
17 | 19 | import org.jvnet.hudson.test.WithoutJenkins; |
| 20 | +import org.mockito.MockedStatic; |
18 | 21 |
|
19 | 22 | import static com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.API_BROWSE_PATH; |
20 | 23 | import static org.hamcrest.MatcherAssert.assertThat; |
|
23 | 26 | import static org.hamcrest.Matchers.hasItem; |
24 | 27 | import static org.hamcrest.Matchers.is; |
25 | 28 | import static org.hamcrest.Matchers.not; |
| 29 | +import static org.mockito.Mockito.mock; |
| 30 | +import static org.mockito.Mockito.mockStatic; |
| 31 | +import static org.mockito.Mockito.verify; |
| 32 | +import static org.mockito.Mockito.when; |
26 | 33 |
|
27 | 34 | public class BitbucketServerAPIClientTest { |
28 | 35 |
|
@@ -82,4 +89,16 @@ public void sortRepositoriesByName() throws Exception { |
82 | 89 | assertThat(names, is(List.of("another-repo", "dogs-repo", "test-repos"))); |
83 | 90 | } |
84 | 91 |
|
| 92 | + @Test |
| 93 | + public void disableCookieManager() throws Exception { |
| 94 | + try(MockedStatic<HttpClientBuilder> staticHttpClientBuilder = mockStatic(HttpClientBuilder.class)) { |
| 95 | + HttpClientBuilder httpClientBuilder = mock(HttpClientBuilder.class); |
| 96 | + CloseableHttpClient httpClient = mock(CloseableHttpClient.class); |
| 97 | + staticHttpClientBuilder.when(HttpClientBuilder::create).thenReturn(httpClientBuilder); |
| 98 | + when(httpClientBuilder.build()).thenReturn(httpClient); |
| 99 | + BitbucketApi client = BitbucketIntegrationClientFactory.getClient("localhost", "amuniz", "test-repos"); |
| 100 | + client.getRepositories(); |
| 101 | + verify(httpClientBuilder).disableCookieManagement(); |
| 102 | + } |
| 103 | + } |
85 | 104 | } |
0 commit comments