test: close static mocks
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
76a5ea4fe9
commit
c04d940a80
@ -27,9 +27,7 @@ import org.apache.http.entity.StringEntity;
|
|||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.http.message.BasicStatusLine;
|
import org.apache.http.message.BasicStatusLine;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.*;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.function.Executable;
|
import org.junit.jupiter.api.function.Executable;
|
||||||
import org.mockito.MockedStatic;
|
import org.mockito.MockedStatic;
|
||||||
|
|
||||||
@ -60,16 +58,22 @@ import static org.mockito.Mockito.*;
|
|||||||
class HTTPVaultConnectorOfflineTest {
|
class HTTPVaultConnectorOfflineTest {
|
||||||
private static final String INVALID_URL = "foo:/\\1nv4l1d_UrL";
|
private static final String INVALID_URL = "foo:/\\1nv4l1d_UrL";
|
||||||
|
|
||||||
|
private static MockedStatic<HttpClientBuilder> hcbMock;
|
||||||
private static CloseableHttpClient httpMock;
|
private static CloseableHttpClient httpMock;
|
||||||
private final CloseableHttpResponse responseMock = mock(CloseableHttpResponse.class);
|
private final CloseableHttpResponse responseMock = mock(CloseableHttpResponse.class);
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void prepare() {
|
static void prepare() {
|
||||||
// Mock the static HTTPClient creation.
|
// Mock the static HTTPClient creation.
|
||||||
MockedStatic<HttpClientBuilder> hcbMock = mockStatic(HttpClientBuilder.class);
|
hcbMock = mockStatic(HttpClientBuilder.class);
|
||||||
hcbMock.when(HttpClientBuilder::create).thenReturn(new MockedHttpClientBuilder());
|
hcbMock.when(HttpClientBuilder::create).thenReturn(new MockedHttpClientBuilder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
static void tearDown() {
|
||||||
|
hcbMock.close();
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void init() {
|
void init() {
|
||||||
// Re-initialize HTTP mock to ensure fresh (empty) results.
|
// Re-initialize HTTP mock to ensure fresh (empty) results.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user