22
33import android .test .InstrumentationTestCase ;
44
5+ import java .util .HashMap ;
6+ import java .util .Map ;
7+
58public class UrlUtilsTest extends InstrumentationTestCase {
69 public void testGetDomainFromUrlWithEmptyStringDoesNotReturnNull () {
710 assertNotNull (UrlUtils .getDomainFromUrl ("" ));
@@ -17,4 +20,55 @@ public void testGetDomainFromUrlWithHostReturnsHost() {
1720
1821 assertTrue (host .equals ("www.wordpress.com" ));
1922 }
23+
24+ public void testAppendUrlParameter1 () {
25+ String url = UrlUtils .appendUrlParameter ("http://wp.com/test" , "preview" , "true" );
26+ assertEquals ("http://wp.com/test?preview=true" , url );
27+ }
28+
29+ public void testAppendUrlParameter2 () {
30+ String url = UrlUtils .appendUrlParameter ("http://wp.com/test?q=pony" , "preview" , "true" );
31+ assertEquals ("http://wp.com/test?q=pony&preview=true" , url );
32+ }
33+
34+ public void testAppendUrlParameter3 () {
35+ String url = UrlUtils .appendUrlParameter ("http://wp.com/test?q=pony#unicorn" , "preview" , "true" );
36+ assertEquals ("http://wp.com/test?q=pony&preview=true#unicorn" , url );
37+ }
38+
39+ public void testAppendUrlParameter4 () {
40+ String url = UrlUtils .appendUrlParameter ("/relative/test" , "preview" , "true" );
41+ assertEquals ("/relative/test?preview=true" , url );
42+ }
43+
44+ public void testAppendUrlParameter5 () {
45+ String url = UrlUtils .appendUrlParameter ("/relative/" , "preview" , "true" );
46+ assertEquals ("/relative/?preview=true" , url );
47+ }
48+
49+ public void testAppendUrlParameter6 () {
50+ String url = UrlUtils .appendUrlParameter ("http://wp.com/test/" , "preview" , "true" );
51+ assertEquals ("http://wp.com/test/?preview=true" , url );
52+ }
53+
54+ public void testAppendUrlParameter7 () {
55+ String url = UrlUtils .appendUrlParameter ("http://wp.com/test/?q=pony" , "preview" , "true" );
56+ assertEquals ("http://wp.com/test/?q=pony&preview=true" , url );
57+ }
58+
59+ public void testAppendUrlParameters1 () {
60+ Map <String , String > params = new HashMap <>();
61+ params .put ("w" , "200" );
62+ params .put ("h" , "300" );
63+ String url = UrlUtils .appendUrlParameters ("http://wp.com/test" , params );
64+ assertEquals ("http://wp.com/test?h=300&w=200" , url );
65+ }
66+
67+ public void testAppendUrlParameters2 () {
68+ Map <String , String > params = new HashMap <>();
69+ params .put ("h" , "300" );
70+ params .put ("w" , "200" );
71+ String url = UrlUtils .appendUrlParameters ("/relative/test" , params );
72+ assertEquals ("/relative/test?h=300&w=200" , url );
73+ }
2074}
0 commit comments