Modified test mocks for compatibility with JDK 10 build environments
This commit is contained in:
parent
ee9a6530d3
commit
6b1211d90f
29
pom.xml
29
pom.xml
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<groupId>de.stklcode.jvault</groupId>
|
<groupId>de.stklcode.jvault</groupId>
|
||||||
<artifactId>connector</artifactId>
|
<artifactId>connector</artifactId>
|
||||||
<version>0.7.1</version>
|
<version>0.7.2-SNAPSHOT</version>
|
||||||
|
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
@ -29,7 +29,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.7.0</version>
|
<version>3.8.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<source>1.8</source>
|
||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
@ -41,17 +41,17 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-clean-plugin</artifactId>
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
<version>3.0.0</version>
|
<version>3.1.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
<version>3.0.2</version>
|
<version>3.1.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.0.2</version>
|
<version>3.1.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifestEntries>
|
<manifestEntries>
|
||||||
@ -68,14 +68,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.19.1</version>
|
<version>2.22.0</version>
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.platform</groupId>
|
|
||||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
|
||||||
<version>1.1.0</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
@ -106,13 +99,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<version>5.1.0</version>
|
<version>5.3.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-migrationsupport</artifactId>
|
<artifactId>junit-jupiter-migrationsupport</artifactId>
|
||||||
<version>5.1.0</version>
|
<version>5.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
@ -123,19 +116,19 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.stefanbirkner</groupId>
|
<groupId>com.github.stefanbirkner</groupId>
|
||||||
<artifactId>system-rules</artifactId>
|
<artifactId>system-rules</artifactId>
|
||||||
<version>1.17.1</version>
|
<version>1.17.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<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.21.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.21.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -60,7 +60,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);
|
||||||
|
|
||||||
@ -76,7 +75,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
|
||||||
@ -88,14 +87,8 @@ public class HTTPVaultConnectorOfflineTest {
|
|||||||
.make()
|
.make()
|
||||||
.load(HttpClientBuilder.class.getClassLoader(), ClassReloadingStrategy.fromInstalledAgent());
|
.load(HttpClientBuilder.class.getClassLoader(), ClassReloadingStrategy.fromInstalledAgent());
|
||||||
|
|
||||||
// Ignore SSL context settings.
|
|
||||||
when(httpMockBuilder.setSSLContext(null)).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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -466,7 +459,7 @@ public class HTTPVaultConnectorOfflineTest {
|
|||||||
private void setPrivate(Object target, String fieldName, Object value) {
|
private void setPrivate(Object target, String fieldName, Object value) {
|
||||||
try {
|
try {
|
||||||
Field field = target.getClass().getDeclaredField(fieldName);
|
Field field = target.getClass().getDeclaredField(fieldName);
|
||||||
boolean accessible =field.isAccessible();
|
boolean accessible = field.isAccessible();
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
field.set(target, value);
|
field.set(target, value);
|
||||||
field.setAccessible(accessible);
|
field.setAccessible(accessible);
|
||||||
@ -480,4 +473,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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user