Modified test mocks for compatibility with JDK 10 build environments

This commit is contained in:
Stefan Kalscheuer 2018-03-28 17:39:30 +02:00
parent d2aaea1938
commit 4d46f2c6d1
2 changed files with 14 additions and 10 deletions

View File

@ -149,13 +149,13 @@
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<version>2.15.0</version> <version>2.17.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId> <artifactId>mockito-inline</artifactId>
<version>2.15.0</version> <version>2.17.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -62,7 +62,6 @@ import static org.mockito.Mockito.*;
public class HTTPVaultConnectorOfflineTest { public class HTTPVaultConnectorOfflineTest {
private static final String INVALID_URL = "foo:/\\1nv4l1d_UrL"; private static final String INVALID_URL = "foo:/\\1nv4l1d_UrL";
private static HttpClientBuilder httpMockBuilder = mock(HttpClientBuilder.class);
private static CloseableHttpClient httpMock = mock(CloseableHttpClient.class); private static CloseableHttpClient httpMock = mock(CloseableHttpClient.class);
private CloseableHttpResponse responseMock = mock(CloseableHttpResponse.class); private CloseableHttpResponse responseMock = mock(CloseableHttpResponse.class);
@ -78,7 +77,7 @@ public class HTTPVaultConnectorOfflineTest {
* @return Mocked HTTP client builder. * @return Mocked HTTP client builder.
*/ */
public static HttpClientBuilder create() { public static HttpClientBuilder create() {
return httpMockBuilder; return new MockedHttpClientBuilder();
} }
@BeforeEach @BeforeEach
@ -90,14 +89,8 @@ public class HTTPVaultConnectorOfflineTest {
.make() .make()
.load(HttpClientBuilder.class.getClassLoader(), ClassReloadingStrategy.fromInstalledAgent()); .load(HttpClientBuilder.class.getClassLoader(), ClassReloadingStrategy.fromInstalledAgent());
// Ignore SSL context settings.
when(httpMockBuilder.setSSLSocketFactory(any())).thenReturn(httpMockBuilder);
// Re-initialize HTTP mock to ensure fresh (empty) results. // Re-initialize HTTP mock to ensure fresh (empty) results.
httpMock = mock(CloseableHttpClient.class); httpMock = mock(CloseableHttpClient.class);
// Mock actual client creation.
when(httpMockBuilder.build()).thenReturn(httpMock);
} }
/** /**
@ -486,4 +479,15 @@ public class HTTPVaultConnectorOfflineTest {
when(responseMock.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), status, "")); when(responseMock.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), status, ""));
when(responseMock.getEntity()).thenReturn(new StringEntity(body, type)); when(responseMock.getEntity()).thenReturn(new StringEntity(body, type));
} }
/**
* Mocked {@link HttpClientBuilder} that always returns the mocked client.
*/
private static class MockedHttpClientBuilder extends HttpClientBuilder {
@Override
public CloseableHttpClient build() {
return httpMock;
}
}
} }