Merge branch 'eugenp:master' into JAVA-23970

This commit is contained in:
Bipin kumar
2023-09-14 08:31:19 +05:30
committed by GitHub
79 changed files with 776 additions and 423 deletions
@@ -16,7 +16,7 @@ public class ApacheHttpClient5UnitTest {
public static final String DUMMY_URL = "https://postman-echo.com/get";
@Test
public void whenUseApacheHttpClient_thenCorrect() throws IOException {
void whenUseApacheHttpClient_thenCorrect() throws IOException {
HttpGet request = new HttpGet(DUMMY_URL);
try (CloseableHttpClient client = HttpClients.createDefault()) {
@@ -1,6 +1,5 @@
package com.baeldung.httpclient.readresponsebodystring;
import org.junit.Test;
import java.io.IOException;
import java.net.URI;
@@ -8,11 +7,13 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class HttpClientUnitTest {
import org.junit.jupiter.api.Test;
class HttpClientUnitTest {
public static final String DUMMY_URL = "https://postman-echo.com/get";
@Test
public void whenUseHttpClient_thenCorrect() throws IOException, InterruptedException {
void whenUseHttpClient_thenCorrect() throws IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(DUMMY_URL)).build();
@@ -1,7 +1,7 @@
package com.baeldung.httpclient.readresponsebodystring;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.BufferedReader;
import java.io.IOException;
@@ -10,12 +10,14 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.junit.jupiter.api.Test;
public class HttpUrlConnectionUnitTest {
public static final String DUMMY_URL = "https://postman-echo.com/get";
@Test
public void whenUseHttpUrlConnection_thenCorrect() throws IOException {
void whenUseHttpUrlConnection_thenCorrect() throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(DUMMY_URL).openConnection();
InputStream inputStream = connection.getInputStream();
@@ -28,7 +30,7 @@ public class HttpUrlConnectionUnitTest {
response.append(currentLine);
in.close();
Assert.assertNotNull(response.toString());
assertNotNull(response.toString());
System.out.println("Response -> " + response.toString());
}
}
@@ -1,6 +1,6 @@
package com.baeldung.httpclient.readresponsebodystring;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.web.client.RestTemplate;
public class SpringRestTemplateUnitTest {
@@ -1,6 +1,6 @@
package com.baeldung.httpclient.readresponsebodystring;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
@@ -8,7 +8,7 @@ public class SpringWebClientUnitTest {
public static final String DUMMY_URL = "https://postman-echo.com/get";
@Test
public void whenUseWebClientRetrieve_thenCorrect() {
void whenUseWebClientRetrieve_thenCorrect() {
WebClient webClient = WebClient.create(DUMMY_URL);
Mono<String> body = webClient.get().retrieve().bodyToMono(String.class);
String s = body.block();