Upgrade to Mockito 3.4.6

Closes gh-22838
This commit is contained in:
Andy Wilkinson
2020-08-08 15:53:42 +01:00
parent f2a52a87ec
commit 969dd35e45
79 changed files with 444 additions and 443 deletions

View File

@@ -24,11 +24,12 @@ import java.net.URI;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.buildpack.platform.docker.DockerApi.ContainerApi;
import org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi;
@@ -64,6 +65,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Scott Frederick
*/
@ExtendWith(MockitoExtension.class)
class DockerApiTests {
private static final String API_URL = "/" + DockerApi.API_VERSION;
@@ -81,7 +83,6 @@ class DockerApiTests {
@BeforeEach
void setup() {
MockitoAnnotations.initMocks(this);
this.dockerApi = new DockerApi(this.http);
}
@@ -127,7 +128,6 @@ class DockerApiTests {
@BeforeEach
void setup() {
MockitoAnnotations.initMocks(this);
this.api = DockerApiTests.this.dockerApi.image();
}
@@ -232,7 +232,6 @@ class DockerApiTests {
@BeforeEach
void setup() {
MockitoAnnotations.initMocks(this);
this.api = DockerApiTests.this.dockerApi.container();
}
@@ -370,7 +369,6 @@ class DockerApiTests {
@BeforeEach
void setup() {
MockitoAnnotations.initMocks(this);
this.api = DockerApiTests.this.dockerApi.volume();
}

View File

@@ -37,10 +37,11 @@ import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.buildpack.platform.docker.transport.HttpTransport.Response;
import org.springframework.util.StreamUtils;
@@ -58,6 +59,7 @@ import static org.mockito.Mockito.verify;
* @author Mike Smithson
* @author Scott Frederick
*/
@ExtendWith(MockitoExtension.class)
class HttpClientTransportTests {
private static final String APPLICATION_JSON = "application/json";
@@ -89,16 +91,13 @@ class HttpClientTransportTests {
@BeforeEach
void setup() throws Exception {
MockitoAnnotations.initMocks(this);
given(this.client.execute(any(HttpHost.class), any(HttpRequest.class))).willReturn(this.response);
given(this.response.getEntity()).willReturn(this.entity);
given(this.response.getStatusLine()).willReturn(this.statusLine);
this.http = new TestHttpClientTransport(this.client);
this.uri = new URI("example");
}
@Test
void getShouldExecuteHttpGet() throws Exception {
givenClientWillReturnResponse();
given(this.entity.getContent()).willReturn(this.content);
given(this.statusLine.getStatusCode()).willReturn(200);
Response response = this.http.get(this.uri);
@@ -112,6 +111,7 @@ class HttpClientTransportTests {
@Test
void postShouldExecuteHttpPost() throws Exception {
givenClientWillReturnResponse();
given(this.entity.getContent()).willReturn(this.content);
given(this.statusLine.getStatusCode()).willReturn(200);
Response response = this.http.post(this.uri);
@@ -125,6 +125,7 @@ class HttpClientTransportTests {
@Test
void postWithContentShouldExecuteHttpPost() throws Exception {
givenClientWillReturnResponse();
given(this.entity.getContent()).willReturn(this.content);
given(this.statusLine.getStatusCode()).willReturn(200);
Response response = this.http.post(this.uri, APPLICATION_JSON,
@@ -145,6 +146,7 @@ class HttpClientTransportTests {
@Test
void putWithContentShouldExecuteHttpPut() throws Exception {
givenClientWillReturnResponse();
given(this.entity.getContent()).willReturn(this.content);
given(this.statusLine.getStatusCode()).willReturn(200);
Response response = this.http.put(this.uri, APPLICATION_JSON,
@@ -165,6 +167,7 @@ class HttpClientTransportTests {
@Test
void deleteShouldExecuteHttpDelete() throws IOException {
givenClientWillReturnResponse();
given(this.entity.getContent()).willReturn(this.content);
given(this.statusLine.getStatusCode()).willReturn(200);
Response response = this.http.delete(this.uri);
@@ -178,6 +181,7 @@ class HttpClientTransportTests {
@Test
void executeWhenResponseIsIn400RangeShouldThrowDockerException() throws IOException {
givenClientWillReturnResponse();
given(this.entity.getContent()).willReturn(getClass().getResourceAsStream("errors.json"));
given(this.statusLine.getStatusCode()).willReturn(404);
assertThatExceptionOfType(DockerEngineException.class).isThrownBy(() -> this.http.get(this.uri))
@@ -188,7 +192,8 @@ class HttpClientTransportTests {
}
@Test
void executeWhenResponseIsIn500RangeWithNoContentShouldThrowDockerException() {
void executeWhenResponseIsIn500RangeWithNoContentShouldThrowDockerException() throws IOException {
givenClientWillReturnResponse();
given(this.statusLine.getStatusCode()).willReturn(500);
assertThatExceptionOfType(DockerEngineException.class).isThrownBy(() -> this.http.get(this.uri))
.satisfies((ex) -> {
@@ -199,6 +204,7 @@ class HttpClientTransportTests {
@Test
void executeWhenResponseIsIn500RangeWithMessageShouldThrowDockerException() throws IOException {
givenClientWillReturnResponse();
given(this.entity.getContent()).willReturn(getClass().getResourceAsStream("message.json"));
given(this.statusLine.getStatusCode()).willReturn(500);
assertThatExceptionOfType(DockerEngineException.class).isThrownBy(() -> this.http.get(this.uri))
@@ -210,6 +216,7 @@ class HttpClientTransportTests {
@Test
void executeWhenResponseIsIn500RangeWithOtherContentShouldThrowDockerException() throws IOException {
givenClientWillReturnResponse();
given(this.entity.getContent()).willReturn(this.content);
given(this.statusLine.getStatusCode()).willReturn(500);
assertThatExceptionOfType(DockerEngineException.class).isThrownBy(() -> this.http.get(this.uri))
@@ -233,6 +240,12 @@ class HttpClientTransportTests {
return new String(out.toByteArray(), StandardCharsets.UTF_8);
}
private void givenClientWillReturnResponse() throws IOException {
given(this.client.execute(any(HttpHost.class), any(HttpRequest.class))).willReturn(this.response);
given(this.response.getEntity()).willReturn(this.entity);
given(this.response.getStatusLine()).willReturn(this.statusLine);
}
/**
* Test {@link HttpClientTransport} implementation.
*/