Merge pull request #12036 from hkhan/JAVA-11283-fix-url-live-test

[JAVA-11283] Fix and cleanup live test for HttpClient URL expansion
This commit is contained in:
kwoyke 2022-04-11 09:10:48 +02:00 committed by GitHub
commit 05cc448212
2 changed files with 6 additions and 12 deletions

View File

@ -12,5 +12,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Reading an HTTP Response Body as a String in Java](https://www.baeldung.com/java-http-response-body-as-string)
- [How To Get Cookies From the Apache HttpClient Response](https://www.baeldung.com/java-apache-httpclient-cookies)
- [Enabling Logging for Apache HttpClient](https://www.baeldung.com/apache-httpclient-enable-logging)
- [Unshorten URLs with HttpClient](https://www.baeldung.com/unshorten-url-httpclient)
- [Expand Shortened URLs with Apache HttpClient](https://www.baeldung.com/unshorten-url-httpclient)
- More articles: [[<-- prev]](../httpclient)

View File

@ -1,4 +1,4 @@
package com.baeldung.httpclient.rare;
package com.baeldung.httpclient.expandurl;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
@ -22,35 +22,29 @@ import java.util.List;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
public class HttpClientUnshortenLiveTest {
public class HttpClientExpandUrlLiveTest {
private CloseableHttpClient client;
// fixtures
@Before
public final void before() {
client = HttpClientBuilder.create().disableRedirectHandling().build();
}
// tests
@Test
public final void givenShortenedOnce_whenUrlIsUnshortened_thenCorrectResult() throws IOException {
public final void givenShortenedOnce_whenUrlIsExpanded_thenCorrectResult() throws IOException {
final String expectedResult = "http://www.baeldung.com/rest-versioning";
final String actualResult = expandSingleLevel("http://bit.ly/13jEoS1");
assertThat(actualResult, equalTo(expectedResult));
}
@Test
public final void givenShortenedMultiple_whenUrlIsUnshortened_thenCorrectResult() throws IOException {
final String expectedResult = "http://www.baeldung.com/rest-versioning";
public final void givenShortenedMultiple_whenUrlIsExpanded_thenCorrectResult() throws IOException {
final String expectedResult = "https://www.baeldung.com/rest-versioning";
final String actualResult = expand("http://t.co/e4rDDbnzmk");
assertThat(actualResult, equalTo(expectedResult));
}
// API
private String expand(final String urlArg) throws IOException {
String originalUrl = urlArg;
String newUrl = expandSingleLevel(originalUrl);