Skip to content

Commit

Permalink
[JAVA-11283] Fix and cleanup live test for HttpClient URL expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
hkhan committed Apr 9, 2022
1 parent 87cce8d commit 60fd316
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion httpclient-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,35 +22,29 @@
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);
Expand Down

0 comments on commit 60fd316

Please sign in to comment.