Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ss-Android into feature/viewpager-main-activity
  • Loading branch information
nbradbury committed Apr 2, 2015
2 parents 17cda45 + 04a450e commit a8081b7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.wordpress.android.util;

import android.test.InstrumentationTestCase;

public class UrlUtilsTest extends InstrumentationTestCase {
public void testGetDomainFromUrlWithEmptyStringDoesNotReturnNull() {
assertNotNull(UrlUtils.getDomainFromUrl(""));
}

public void testGetDomainFromUrlWithNoHostDoesNotReturnNull() {
assertNotNull(UrlUtils.getDomainFromUrl("wordpress"));
}

public void testGetDomainFromUrlWithHostReturnsHost() {
String url = "http://www.wordpress.com";
String host = UrlUtils.getDomainFromUrl(url);

assertTrue(host.equals("www.wordpress.com"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@ public static String urlDecode(final String text) {
}
}

/**
*
* @param urlString url to get domain from
* @return domain of uri if available. Empty string otherwise.
*/
public static String getDomainFromUrl(final String urlString) {
if (urlString == null) {
return "";
if (urlString != null) {
Uri uri = Uri.parse(urlString);
if (uri.getHost() != null) {
return uri.getHost();
}
}
Uri uri = Uri.parse(urlString);
return uri.getHost();

return "";
}

/**
Expand Down

0 comments on commit a8081b7

Please sign in to comment.