Enforce use of BDDMockito
1. Replace Mockito.verify*() with BDDMockito.then() 2. Replace Mockito.doReturn() with BDDMockito.willReturn() 3. Adjust checkstyle rule See gh-29178
This commit is contained in:
committed by
Stephane Nicoll
parent
f60af4dbbd
commit
b49418aaaf
@@ -47,17 +47,17 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Tests for {@link Builder}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Scott Frederick
|
||||
* @author Rafael Ceccone
|
||||
*/
|
||||
class BuilderTests {
|
||||
|
||||
@@ -96,11 +96,13 @@ class BuilderTests {
|
||||
assertThat(out.toString()).contains("Running creator");
|
||||
assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
|
||||
ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
|
||||
verify(docker.image()).pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull());
|
||||
verify(docker.image()).pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), isNull());
|
||||
verify(docker.image()).load(archive.capture(), any());
|
||||
verify(docker.image()).remove(archive.getValue().getTag(), true);
|
||||
verifyNoMoreInteractions(docker.image());
|
||||
then(docker.image()).should().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
|
||||
isNull());
|
||||
then(docker.image()).should().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(),
|
||||
isNull());
|
||||
then(docker.image()).should().load(archive.capture(), any());
|
||||
then(docker.image()).should().remove(archive.getValue().getTag(), true);
|
||||
then(docker.image()).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -124,15 +126,15 @@ class BuilderTests {
|
||||
assertThat(out.toString()).contains("Running creator");
|
||||
assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
|
||||
ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
|
||||
verify(docker.image()).pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
|
||||
then(docker.image()).should().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(),
|
||||
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
|
||||
verify(docker.image()).pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(),
|
||||
then(docker.image()).should().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(),
|
||||
eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
|
||||
verify(docker.image()).push(eq(request.getName()), any(),
|
||||
then(docker.image()).should().push(eq(request.getName()), any(),
|
||||
eq(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()));
|
||||
verify(docker.image()).load(archive.capture(), any());
|
||||
verify(docker.image()).remove(archive.getValue().getTag(), true);
|
||||
verifyNoMoreInteractions(docker.image());
|
||||
then(docker.image()).should().load(archive.capture(), any());
|
||||
then(docker.image()).should().remove(archive.getValue().getTag(), true);
|
||||
then(docker.image()).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,8 +153,8 @@ class BuilderTests {
|
||||
assertThat(out.toString()).contains("Running creator");
|
||||
assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
|
||||
ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
|
||||
verify(docker.image()).load(archive.capture(), any());
|
||||
verify(docker.image()).remove(archive.getValue().getTag(), true);
|
||||
then(docker.image()).should().load(archive.capture(), any());
|
||||
then(docker.image()).should().remove(archive.getValue().getTag(), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -172,8 +174,8 @@ class BuilderTests {
|
||||
assertThat(out.toString()).contains("Running creator");
|
||||
assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
|
||||
ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
|
||||
verify(docker.image()).load(archive.capture(), any());
|
||||
verify(docker.image()).remove(archive.getValue().getTag(), true);
|
||||
then(docker.image()).should().load(archive.capture(), any());
|
||||
then(docker.image()).should().remove(archive.getValue().getTag(), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -192,8 +194,8 @@ class BuilderTests {
|
||||
assertThat(out.toString()).contains("Running creator");
|
||||
assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
|
||||
ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
|
||||
verify(docker.image()).load(archive.capture(), any());
|
||||
verify(docker.image()).remove(archive.getValue().getTag(), true);
|
||||
then(docker.image()).should().load(archive.capture(), any());
|
||||
then(docker.image()).should().remove(archive.getValue().getTag(), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -216,10 +218,10 @@ class BuilderTests {
|
||||
assertThat(out.toString()).contains("Running creator");
|
||||
assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
|
||||
ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
|
||||
verify(docker.image()).load(archive.capture(), any());
|
||||
verify(docker.image()).remove(archive.getValue().getTag(), true);
|
||||
verify(docker.image(), never()).pull(any(), any());
|
||||
verify(docker.image(), times(2)).inspect(any());
|
||||
then(docker.image()).should().load(archive.capture(), any());
|
||||
then(docker.image()).should().remove(archive.getValue().getTag(), true);
|
||||
then(docker.image()).should(never()).pull(any(), any());
|
||||
then(docker.image()).should(times(2)).inspect(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -242,10 +244,10 @@ class BuilderTests {
|
||||
assertThat(out.toString()).contains("Running creator");
|
||||
assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
|
||||
ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
|
||||
verify(docker.image()).load(archive.capture(), any());
|
||||
verify(docker.image()).remove(archive.getValue().getTag(), true);
|
||||
verify(docker.image(), times(2)).pull(any(), any(), isNull());
|
||||
verify(docker.image(), never()).inspect(any());
|
||||
then(docker.image()).should().load(archive.capture(), any());
|
||||
then(docker.image()).should().remove(archive.getValue().getTag(), true);
|
||||
then(docker.image()).should(times(2)).pull(any(), any(), isNull());
|
||||
then(docker.image()).should(never()).inspect(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -270,10 +272,10 @@ class BuilderTests {
|
||||
assertThat(out.toString()).contains("Running creator");
|
||||
assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
|
||||
ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
|
||||
verify(docker.image()).load(archive.capture(), any());
|
||||
verify(docker.image()).remove(archive.getValue().getTag(), true);
|
||||
verify(docker.image(), times(2)).inspect(any());
|
||||
verify(docker.image(), times(2)).pull(any(), any(), isNull());
|
||||
then(docker.image()).should().load(archive.capture(), any());
|
||||
then(docker.image()).should().remove(archive.getValue().getTag(), true);
|
||||
then(docker.image()).should(times(2)).inspect(any());
|
||||
then(docker.image()).should(times(2)).pull(any(), any(), isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -54,8 +54,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Tests for {@link Lifecycle}.
|
||||
@@ -149,7 +149,7 @@ class LifecycleTests {
|
||||
createLifecycle(request).execute();
|
||||
assertPhaseWasRun("creator", withExpectedConfig("lifecycle-creator-clean-cache.json"));
|
||||
VolumeName name = VolumeName.of("pack-cache-b35197ac41ea.build");
|
||||
verify(this.docker.volume()).delete(name, true);
|
||||
then(this.docker.volume()).should().delete(name, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -184,8 +184,8 @@ class LifecycleTests {
|
||||
@Test
|
||||
void closeClearsVolumes() throws Exception {
|
||||
createLifecycle().close();
|
||||
verify(this.docker.volume()).delete(VolumeName.of("pack-layers-aaaaaaaaaa"), true);
|
||||
verify(this.docker.volume()).delete(VolumeName.of("pack-app-aaaaaaaaaa"), true);
|
||||
then(this.docker.volume()).should().delete(VolumeName.of("pack-layers-aaaaaaaaaa"), true);
|
||||
then(this.docker.volume()).should().delete(VolumeName.of("pack-app-aaaaaaaaaa"), true);
|
||||
}
|
||||
|
||||
private DockerApi mockDockerApi() {
|
||||
@@ -256,9 +256,9 @@ class LifecycleTests {
|
||||
|
||||
private void assertPhaseWasRun(String name, IOConsumer<ContainerConfig> configConsumer) throws IOException {
|
||||
ContainerReference containerReference = ContainerReference.of("cnb-lifecycle-" + name);
|
||||
verify(this.docker.container()).start(containerReference);
|
||||
verify(this.docker.container()).logs(eq(containerReference), any());
|
||||
verify(this.docker.container()).remove(containerReference, true);
|
||||
then(this.docker.container()).should().start(containerReference);
|
||||
then(this.docker.container()).should().logs(eq(containerReference), any());
|
||||
then(this.docker.container()).should().remove(containerReference, true);
|
||||
configConsumer.accept(this.configs.get(containerReference.toString()));
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,8 @@ import org.springframework.boot.buildpack.platform.docker.type.ContainerConfig.U
|
||||
import org.springframework.boot.buildpack.platform.docker.type.VolumeName;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Tests for {@link Phase}.
|
||||
@@ -54,9 +53,9 @@ class PhaseTests {
|
||||
Phase phase = new Phase("test", false);
|
||||
Update update = mock(Update.class);
|
||||
phase.apply(update);
|
||||
verify(update).withCommand("/cnb/lifecycle/test", NO_ARGS);
|
||||
verify(update).withLabel("author", "spring-boot");
|
||||
verifyNoMoreInteractions(update);
|
||||
then(update).should().withCommand("/cnb/lifecycle/test", NO_ARGS);
|
||||
then(update).should().withLabel("author", "spring-boot");
|
||||
then(update).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,11 +64,11 @@ class PhaseTests {
|
||||
phase.withDaemonAccess();
|
||||
Update update = mock(Update.class);
|
||||
phase.apply(update);
|
||||
verify(update).withUser("root");
|
||||
verify(update).withBinding(Binding.from("/var/run/docker.sock", "/var/run/docker.sock"));
|
||||
verify(update).withCommand("/cnb/lifecycle/test", NO_ARGS);
|
||||
verify(update).withLabel("author", "spring-boot");
|
||||
verifyNoMoreInteractions(update);
|
||||
then(update).should().withUser("root");
|
||||
then(update).should().withBinding(Binding.from("/var/run/docker.sock", "/var/run/docker.sock"));
|
||||
then(update).should().withCommand("/cnb/lifecycle/test", NO_ARGS);
|
||||
then(update).should().withLabel("author", "spring-boot");
|
||||
then(update).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,9 +77,9 @@ class PhaseTests {
|
||||
phase.withLogLevelArg();
|
||||
Update update = mock(Update.class);
|
||||
phase.apply(update);
|
||||
verify(update).withCommand("/cnb/lifecycle/test", "-log-level", "debug");
|
||||
verify(update).withLabel("author", "spring-boot");
|
||||
verifyNoMoreInteractions(update);
|
||||
then(update).should().withCommand("/cnb/lifecycle/test", "-log-level", "debug");
|
||||
then(update).should().withLabel("author", "spring-boot");
|
||||
then(update).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,9 +88,9 @@ class PhaseTests {
|
||||
phase.withLogLevelArg();
|
||||
Update update = mock(Update.class);
|
||||
phase.apply(update);
|
||||
verify(update).withCommand("/cnb/lifecycle/test");
|
||||
verify(update).withLabel("author", "spring-boot");
|
||||
verifyNoMoreInteractions(update);
|
||||
then(update).should().withCommand("/cnb/lifecycle/test");
|
||||
then(update).should().withLabel("author", "spring-boot");
|
||||
then(update).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,9 +99,9 @@ class PhaseTests {
|
||||
phase.withArgs("a", "b", "c");
|
||||
Update update = mock(Update.class);
|
||||
phase.apply(update);
|
||||
verify(update).withCommand("/cnb/lifecycle/test", "a", "b", "c");
|
||||
verify(update).withLabel("author", "spring-boot");
|
||||
verifyNoMoreInteractions(update);
|
||||
then(update).should().withCommand("/cnb/lifecycle/test", "a", "b", "c");
|
||||
then(update).should().withLabel("author", "spring-boot");
|
||||
then(update).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,10 +111,10 @@ class PhaseTests {
|
||||
phase.withBinding(Binding.from(volumeName, "/test"));
|
||||
Update update = mock(Update.class);
|
||||
phase.apply(update);
|
||||
verify(update).withCommand("/cnb/lifecycle/test");
|
||||
verify(update).withLabel("author", "spring-boot");
|
||||
verify(update).withBinding(Binding.from(volumeName, "/test"));
|
||||
verifyNoMoreInteractions(update);
|
||||
then(update).should().withCommand("/cnb/lifecycle/test");
|
||||
then(update).should().withLabel("author", "spring-boot");
|
||||
then(update).should().withBinding(Binding.from(volumeName, "/test"));
|
||||
then(update).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,11 +124,11 @@ class PhaseTests {
|
||||
phase.withEnv("name2", "value2");
|
||||
Update update = mock(Update.class);
|
||||
phase.apply(update);
|
||||
verify(update).withCommand("/cnb/lifecycle/test");
|
||||
verify(update).withLabel("author", "spring-boot");
|
||||
verify(update).withEnv("name1", "value1");
|
||||
verify(update).withEnv("name2", "value2");
|
||||
verifyNoMoreInteractions(update);
|
||||
then(update).should().withCommand("/cnb/lifecycle/test");
|
||||
then(update).should().withLabel("author", "spring-boot");
|
||||
then(update).should().withEnv("name1", "value1");
|
||||
then(update).should().withEnv("name2", "value2");
|
||||
then(update).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,10 +61,10 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Tests for {@link DockerApi}.
|
||||
@@ -260,7 +260,7 @@ class DockerApiTests {
|
||||
ordered.verify(this.loadListener).onStart();
|
||||
ordered.verify(this.loadListener).onUpdate(any());
|
||||
ordered.verify(this.loadListener).onFinish();
|
||||
verify(http()).post(any(), any(), this.writer.capture());
|
||||
then(http()).should().post(any(), any(), this.writer.capture());
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
this.writer.getValue().accept(out);
|
||||
assertThat(out.toByteArray()).hasSizeGreaterThan(21000);
|
||||
@@ -280,7 +280,7 @@ class DockerApiTests {
|
||||
+ "/docker.io/library/ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
|
||||
given(http().delete(removeUri)).willReturn(emptyResponse());
|
||||
this.api.remove(reference, false);
|
||||
verify(http()).delete(removeUri);
|
||||
then(http()).should().delete(removeUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -291,7 +291,7 @@ class DockerApiTests {
|
||||
+ "/docker.io/library/ubuntu@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d?force=1");
|
||||
given(http().delete(removeUri)).willReturn(emptyResponse());
|
||||
this.api.remove(reference, true);
|
||||
verify(http()).delete(removeUri);
|
||||
then(http()).should().delete(removeUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -381,7 +381,7 @@ class DockerApiTests {
|
||||
.willReturn(responseOf("create-container-response.json"));
|
||||
ContainerReference containerReference = this.api.create(config);
|
||||
assertThat(containerReference.toString()).isEqualTo("e90e34656806");
|
||||
verify(http()).post(any(), any(), this.writer.capture());
|
||||
then(http()).should().post(any(), any(), this.writer.capture());
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
this.writer.getValue().accept(out);
|
||||
assertThat(out.toByteArray().length).isEqualTo(config.toString().length());
|
||||
@@ -403,11 +403,11 @@ class DockerApiTests {
|
||||
given(http().put(eq(uploadUri), eq("application/x-tar"), any())).willReturn(emptyResponse());
|
||||
ContainerReference containerReference = this.api.create(config, content);
|
||||
assertThat(containerReference.toString()).isEqualTo("e90e34656806");
|
||||
verify(http()).post(any(), any(), this.writer.capture());
|
||||
then(http()).should().post(any(), any(), this.writer.capture());
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
this.writer.getValue().accept(out);
|
||||
assertThat(out.toByteArray().length).isEqualTo(config.toString().length());
|
||||
verify(http()).put(any(), any(), this.writer.capture());
|
||||
then(http()).should().put(any(), any(), this.writer.capture());
|
||||
this.writer.getValue().accept(out);
|
||||
assertThat(out.toByteArray()).hasSizeGreaterThan(2000);
|
||||
}
|
||||
@@ -424,7 +424,7 @@ class DockerApiTests {
|
||||
URI startContainerUri = new URI(CONTAINERS_URL + "/e90e34656806/start");
|
||||
given(http().post(startContainerUri)).willReturn(emptyResponse());
|
||||
this.api.start(reference);
|
||||
verify(http()).post(startContainerUri);
|
||||
then(http()).should().post(startContainerUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -479,7 +479,7 @@ class DockerApiTests {
|
||||
URI removeUri = new URI(CONTAINERS_URL + "/e90e34656806");
|
||||
given(http().delete(removeUri)).willReturn(emptyResponse());
|
||||
this.api.remove(reference, false);
|
||||
verify(http()).delete(removeUri);
|
||||
then(http()).should().delete(removeUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -488,7 +488,7 @@ class DockerApiTests {
|
||||
URI removeUri = new URI(CONTAINERS_URL + "/e90e34656806?force=1");
|
||||
given(http().delete(removeUri)).willReturn(emptyResponse());
|
||||
this.api.remove(reference, true);
|
||||
verify(http()).delete(removeUri);
|
||||
then(http()).should().delete(removeUri);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -515,7 +515,7 @@ class DockerApiTests {
|
||||
URI removeUri = new URI(VOLUMES_URL + "/test");
|
||||
given(http().delete(removeUri)).willReturn(emptyResponse());
|
||||
this.api.delete(name, false);
|
||||
verify(http()).delete(removeUri);
|
||||
then(http()).should().delete(removeUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -524,7 +524,7 @@ class DockerApiTests {
|
||||
URI removeUri = new URI(VOLUMES_URL + "/test?force=1");
|
||||
given(http().delete(removeUri)).willReturn(emptyResponse());
|
||||
this.api.delete(name, true);
|
||||
verify(http()).delete(removeUri);
|
||||
then(http()).should().delete(removeUri);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,7 +50,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
|
||||
/**
|
||||
* Tests for {@link HttpClientTransport}.
|
||||
@@ -58,6 +58,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Phillip Webb
|
||||
* @author Mike Smithson
|
||||
* @author Scott Frederick
|
||||
* @author Yanming Zhou
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class HttpClientTransportTests {
|
||||
@@ -103,7 +104,7 @@ class HttpClientTransportTests {
|
||||
given(this.entity.getContent()).willReturn(this.content);
|
||||
given(this.statusLine.getStatusCode()).willReturn(200);
|
||||
Response response = this.http.get(this.uri);
|
||||
verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
HttpUriRequest request = this.requestCaptor.getValue();
|
||||
assertThat(request).isInstanceOf(HttpGet.class);
|
||||
assertThat(request.getURI()).isEqualTo(this.uri);
|
||||
@@ -117,7 +118,7 @@ class HttpClientTransportTests {
|
||||
given(this.entity.getContent()).willReturn(this.content);
|
||||
given(this.statusLine.getStatusCode()).willReturn(200);
|
||||
Response response = this.http.post(this.uri);
|
||||
verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
HttpUriRequest request = this.requestCaptor.getValue();
|
||||
assertThat(request).isInstanceOf(HttpPost.class);
|
||||
assertThat(request.getURI()).isEqualTo(this.uri);
|
||||
@@ -132,7 +133,7 @@ class HttpClientTransportTests {
|
||||
given(this.entity.getContent()).willReturn(this.content);
|
||||
given(this.statusLine.getStatusCode()).willReturn(200);
|
||||
Response response = this.http.post(this.uri, "auth token");
|
||||
verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
HttpUriRequest request = this.requestCaptor.getValue();
|
||||
assertThat(request).isInstanceOf(HttpPost.class);
|
||||
assertThat(request.getURI()).isEqualTo(this.uri);
|
||||
@@ -147,7 +148,7 @@ class HttpClientTransportTests {
|
||||
given(this.entity.getContent()).willReturn(this.content);
|
||||
given(this.statusLine.getStatusCode()).willReturn(200);
|
||||
Response response = this.http.post(this.uri, "");
|
||||
verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
HttpUriRequest request = this.requestCaptor.getValue();
|
||||
assertThat(request).isInstanceOf(HttpPost.class);
|
||||
assertThat(request.getURI()).isEqualTo(this.uri);
|
||||
@@ -164,7 +165,7 @@ class HttpClientTransportTests {
|
||||
given(this.statusLine.getStatusCode()).willReturn(200);
|
||||
Response response = this.http.post(this.uri, APPLICATION_JSON,
|
||||
(out) -> StreamUtils.copy(content, StandardCharsets.UTF_8, out));
|
||||
verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
HttpUriRequest request = this.requestCaptor.getValue();
|
||||
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
|
||||
assertThat(request).isInstanceOf(HttpPost.class);
|
||||
@@ -186,7 +187,7 @@ class HttpClientTransportTests {
|
||||
given(this.statusLine.getStatusCode()).willReturn(200);
|
||||
Response response = this.http.post(this.uri, APPLICATION_X_TAR,
|
||||
(out) -> StreamUtils.copy(content, StandardCharsets.UTF_8, out));
|
||||
verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
HttpUriRequest request = this.requestCaptor.getValue();
|
||||
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
|
||||
assertThat(request).isInstanceOf(HttpPost.class);
|
||||
@@ -208,7 +209,7 @@ class HttpClientTransportTests {
|
||||
given(this.statusLine.getStatusCode()).willReturn(200);
|
||||
Response response = this.http.put(this.uri, APPLICATION_JSON,
|
||||
(out) -> StreamUtils.copy(content, StandardCharsets.UTF_8, out));
|
||||
verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
HttpUriRequest request = this.requestCaptor.getValue();
|
||||
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
|
||||
assertThat(request).isInstanceOf(HttpPut.class);
|
||||
@@ -230,7 +231,7 @@ class HttpClientTransportTests {
|
||||
given(this.statusLine.getStatusCode()).willReturn(200);
|
||||
Response response = this.http.put(this.uri, APPLICATION_X_TAR,
|
||||
(out) -> StreamUtils.copy(content, StandardCharsets.UTF_8, out));
|
||||
verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
HttpUriRequest request = this.requestCaptor.getValue();
|
||||
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
|
||||
assertThat(request).isInstanceOf(HttpPut.class);
|
||||
@@ -250,7 +251,7 @@ class HttpClientTransportTests {
|
||||
given(this.entity.getContent()).willReturn(this.content);
|
||||
given(this.statusLine.getStatusCode()).willReturn(200);
|
||||
Response response = this.http.delete(this.uri);
|
||||
verify(this.client).execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
then(this.client).should().execute(this.hostCaptor.capture(), this.requestCaptor.capture());
|
||||
HttpUriRequest request = this.requestCaptor.getValue();
|
||||
assertThat(request).isInstanceOf(HttpDelete.class);
|
||||
assertThat(request.getURI()).isEqualTo(this.uri);
|
||||
|
||||
Reference in New Issue
Block a user