File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed
androidTest/java/org/wordpress/android/util
main/java/org/wordpress/android/util Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change 1+ package org .wordpress .android .util ;
2+
3+ import android .test .InstrumentationTestCase ;
4+
5+ public class UrlUtilsTest extends InstrumentationTestCase {
6+ public void testGetDomainFromUrlWithEmptyStringDoesNotReturnNull () {
7+ assertNotNull (UrlUtils .getDomainFromUrl ("" ));
8+ }
9+
10+ public void testGetDomainFromUrlWithNoHostDoesNotReturnNull () {
11+ assertNotNull (UrlUtils .getDomainFromUrl ("wordpress" ));
12+ }
13+
14+ public void testGetDomainFromUrlWithHostReturnsHost () {
15+ String url = "http://www.wordpress.com" ;
16+ String host = UrlUtils .getDomainFromUrl (url );
17+
18+ assertTrue (host .equals ("www.wordpress.com" ));
19+ }
20+ }
Original file line number Diff line number Diff line change @@ -32,12 +32,20 @@ public static String urlDecode(final String text) {
3232 }
3333 }
3434
35+ /**
36+ *
37+ * @param urlString url to get domain from
38+ * @return domain of uri if available. Empty string otherwise.
39+ */
3540 public static String getDomainFromUrl (final String urlString ) {
36- if (urlString == null ) {
37- return "" ;
41+ if (urlString != null ) {
42+ Uri uri = Uri .parse (urlString );
43+ if (uri .getHost () != null ) {
44+ return uri .getHost ();
45+ }
3846 }
39- Uri uri = Uri . parse ( urlString );
40- return uri . getHost () ;
47+
48+ return "" ;
4149 }
4250
4351 /**
You can’t perform that action at this time.
0 commit comments