Replace Mockito argument captors with assertArg

See gh-35015
This commit is contained in:
Marc Leroux
2023-04-16 20:49:34 -04:00
committed by Moritz Halbritter
parent 4d14d0e437
commit b61834c92d
27 changed files with 186 additions and 250 deletions

View File

@@ -25,14 +25,10 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import joptsimple.OptionSet;
import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpHost;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.cli.command.status.ExitStatus;
@@ -40,6 +36,7 @@ import org.springframework.boot.cli.command.status.ExitStatus;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.assertArg;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.then;
@@ -57,9 +54,6 @@ class InitCommandTests extends AbstractHttpClientMockTests {
private final InitCommand command;
@Captor
private ArgumentCaptor<HttpUriRequest> requestCaptor;
InitCommandTests() {
InitializrService initializrService = new InitializrService(this.http);
this.handler = new TestableInitCommandOptionHandler(initializrService);
@@ -400,9 +394,9 @@ class InitCommandTests extends AbstractHttpClientMockTests {
@Test
void userAgent() throws Exception {
this.command.run("--list", "--target=https://fake-service");
then(this.http).should().executeOpen(any(HttpHost.class), this.requestCaptor.capture(), isNull());
Header agent = this.requestCaptor.getValue().getHeaders("User-Agent")[0];
assertThat(agent.getValue()).startsWith("SpringBootCli/");
then(this.http).should()
.executeOpen(any(HttpHost.class), assertArg((request) -> assertThat(
request.getHeaders("User-Agent")[0].getValue().startsWith("SpringBootCli/"))), isNull());
}
private byte[] createFakeZipArchive(String fileName, String content) throws IOException {