Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2010 Google Inc. | 2 * Copyright (c) 2010 Google Inc. |
3 * | 3 * |
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not u se this file except | 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not u se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.apache.org/licenses/LICENSE-2.0 | 7 * http://www.apache.org/licenses/LICENSE-2.0 |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 private static String NO_PATH = "foo://bar?a=b"; | 60 private static String NO_PATH = "foo://bar?a=b"; |
61 | 61 |
62 public void testBuild_noPath() { | 62 public void testBuild_noPath() { |
63 GenericUrl url = new GenericUrl(); | 63 GenericUrl url = new GenericUrl(); |
64 url.setScheme("foo"); | 64 url.setScheme("foo"); |
65 url.setHost("bar"); | 65 url.setHost("bar"); |
66 url.set("a", "b"); | 66 url.set("a", "b"); |
67 assertEquals(NO_PATH, url.build()); | 67 assertEquals(NO_PATH, url.build()); |
68 } | 68 } |
69 | 69 |
70 public void testBuild_noUserInfo() { | |
71 GenericUrl url = new GenericUrl(NO_PATH); | |
72 assertNull(url.getUserInfo()); | |
73 } | |
74 | |
70 public void testBuild_noScheme() { | 75 public void testBuild_noScheme() { |
71 GenericUrl url = new GenericUrl(); | 76 GenericUrl url = new GenericUrl(); |
72 try { | 77 try { |
73 url.build(); | 78 url.build(); |
74 fail("expected " + NullPointerException.class); | 79 fail("expected " + NullPointerException.class); |
75 } catch (NullPointerException e) { | 80 } catch (NullPointerException e) { |
76 // expected | 81 // expected |
77 } | 82 } |
78 } | 83 } |
79 | 84 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 | 151 |
147 public TestUrl() { | 152 public TestUrl() { |
148 } | 153 } |
149 | 154 |
150 public TestUrl(String encodedUrl) { | 155 public TestUrl(String encodedUrl) { |
151 super(encodedUrl); | 156 super(encodedUrl); |
152 } | 157 } |
153 } | 158 } |
154 | 159 |
155 private static String FULL = | 160 private static String FULL = |
156 "https://user:password2@www.google.com:223/m8/feeds/contacts/someone=%23%2 5&%20%3F%3Co%3E%7B%7D@gmail.com/" | 161 "https://user:%3Cpa&$w%40rd%3E@www.google.com:223/m8/feeds/contacts/" |
162 + "someone=%23%25&%20%3F%3Co%3E%7B%7D@gmail.com/" | |
157 + "full?" + "foo=bar&" + "alt=json&" + "max-results=3&" + "prettyprint=tru e&" | 163 + "full?" + "foo=bar&" + "alt=json&" + "max-results=3&" + "prettyprint=tru e&" |
158 + "q=Go%3D%23/%25%26%20?%3Co%3Egle#DOWNLOADING"; | 164 + "q=Go%3D%23/%25%26%20?%3Co%3Egle#%3CD@WNL:ADING%3E"; |
159 | 165 |
160 private static List<String> FULL_PARTS = | 166 private static List<String> FULL_PARTS = |
161 Arrays.asList("", "m8", "feeds", "contacts", "someone=#%& ?<o>{}@gmail.com ", "full"); | 167 Arrays.asList("", "m8", "feeds", "contacts", "someone=#%& ?<o>{}@gmail.com ", "full"); |
168 | |
169 private static String USER_INFO = "user:<pa&$w@rd>"; | |
170 private static String FRAGMENT = "<D@WNL:ADING>"; | |
162 | 171 |
163 public void testBuild_full() { | 172 public void testBuild_full() { |
164 TestUrl url = new TestUrl(); | 173 TestUrl url = new TestUrl(); |
165 url.setScheme("https"); | 174 url.setScheme("https"); |
166 url.setHost("www.google.com"); | 175 url.setHost("www.google.com"); |
167 url.setPort(223); | 176 url.setPort(223); |
168 url.setPathParts(FULL_PARTS); | 177 url.setPathParts(FULL_PARTS); |
169 url.set("alt", "json") | 178 url.set("alt", "json") |
170 .set("max-results", 3).set("prettyprint", true).set("q", "Go=#/%& ?<o>gl e"); | 179 .set("max-results", 3).set("prettyprint", true).set("q", "Go=#/%& ?<o>gl e"); |
171 url.foo = "bar"; | 180 url.foo = "bar"; |
172 url.hidden = "invisible"; | 181 url.hidden = "invisible"; |
173 url.setFragment("DOWNLOADING"); | 182 url.setFragment(FRAGMENT); |
174 url.setUserInfo("user:password2"); | 183 url.setUserInfo(USER_INFO); |
175 assertEquals(FULL, url.build()); | 184 assertEquals(FULL, url.build()); |
176 } | 185 } |
177 | 186 |
178 public void testParse_full() { | 187 public void testParse_full() { |
179 TestUrl url = new TestUrl(FULL); | 188 TestUrl url = new TestUrl(FULL); |
180 subtestFull(url); | 189 subtestFull(url); |
181 assertNull(url.hidden); | 190 assertNull(url.hidden); |
182 assertEquals("bar", url.get("foo")); | 191 assertEquals("bar", url.get("foo")); |
183 assertEquals("bar", url.foo); | 192 assertEquals("bar", url.foo); |
184 } | 193 } |
(...skipping 25 matching lines...) Expand all Loading... | |
210 private void subtestFull(GenericUrl url) { | 219 private void subtestFull(GenericUrl url) { |
211 assertEquals("https", url.getScheme()); | 220 assertEquals("https", url.getScheme()); |
212 assertEquals("www.google.com", url.getHost()); | 221 assertEquals("www.google.com", url.getHost()); |
213 assertEquals(223, url.getPort()); | 222 assertEquals(223, url.getPort()); |
214 assertEquals(FULL_PARTS, url.getPathParts()); | 223 assertEquals(FULL_PARTS, url.getPathParts()); |
215 assertEquals("json", url.getFirst("alt")); | 224 assertEquals("json", url.getFirst("alt")); |
216 assertEquals("3", url.getFirst("max-results")); | 225 assertEquals("3", url.getFirst("max-results")); |
217 assertEquals("true", url.getFirst("prettyprint")); | 226 assertEquals("true", url.getFirst("prettyprint")); |
218 assertEquals("Go=#/%& ?<o>gle", url.getFirst("q")); | 227 assertEquals("Go=#/%& ?<o>gle", url.getFirst("q")); |
219 assertEquals("bar", url.getFirst("foo")); | 228 assertEquals("bar", url.getFirst("foo")); |
220 assertEquals("DOWNLOADING", url.getFragment()); | 229 assertEquals(FRAGMENT, url.getFragment()); |
221 assertEquals("user:password2", url.getUserInfo()); | 230 assertEquals(USER_INFO, url.getUserInfo()); |
yanivi
2013/04/11 03:30:55
add a case where getUserInfo() is null
peleyal
2013/04/11 18:08:14
Done.
| |
222 } | 231 } |
223 | 232 |
224 public static class FieldTypesUrl extends GenericUrl { | 233 public static class FieldTypesUrl extends GenericUrl { |
225 | 234 |
226 @Key | 235 @Key |
227 Boolean B; | 236 Boolean B; |
228 | 237 |
229 @Key | 238 @Key |
230 Double D; | 239 Double D; |
231 | 240 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 url.setScheme("http"); | 375 url.setScheme("http"); |
367 url.setHost("example.com"); | 376 url.setHost("example.com"); |
368 url.setPort(1234); | 377 url.setPort(1234); |
369 assertEquals("http://example.com:1234", url.buildAuthority()); | 378 assertEquals("http://example.com:1234", url.buildAuthority()); |
370 } | 379 } |
371 | 380 |
372 public void testBuildAuthority_withUserInfo() { | 381 public void testBuildAuthority_withUserInfo() { |
373 GenericUrl url = new GenericUrl(); | 382 GenericUrl url = new GenericUrl(); |
374 url.setScheme("http"); | 383 url.setScheme("http"); |
375 url.setHost("www.example.com"); | 384 url.setHost("www.example.com"); |
376 url.setUserInfo("user:pass"); | 385 url.setUserInfo("first.last:pa@@"); |
377 assertEquals("http://user:pass@www.example.com", url.buildAuthority()); | 386 assertEquals("http://first.last:pa%40%40@www.example.com", url.buildAuthorit y()); |
378 } | 387 } |
379 | 388 |
380 public void testBuildRelativeUrl_empty() { | 389 public void testBuildRelativeUrl_empty() { |
381 GenericUrl url = new GenericUrl(); | 390 GenericUrl url = new GenericUrl(); |
382 url.setScheme("foo"); | 391 url.setScheme("foo"); |
383 url.setHost("bar"); | 392 url.setHost("bar"); |
384 url.setRawPath(""); | 393 url.setRawPath(""); |
385 assertEquals("", url.buildRelativeUrl()); | 394 assertEquals("", url.buildRelativeUrl()); |
386 } | 395 } |
387 | 396 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 testRedirectUtility( | 577 testRedirectUtility( |
569 "https://example.com/test", "http://www.google.com/", "https://example.c om/test"); | 578 "https://example.com/test", "http://www.google.com/", "https://example.c om/test"); |
570 } | 579 } |
571 | 580 |
572 private void testRedirectUtility(String expectedResult, String url, String rel ative) { | 581 private void testRedirectUtility(String expectedResult, String url, String rel ative) { |
573 GenericUrl gu = new GenericUrl(url); | 582 GenericUrl gu = new GenericUrl(url); |
574 GenericUrl redirectedUrl = new GenericUrl(gu.toURL(relative)); | 583 GenericUrl redirectedUrl = new GenericUrl(gu.toURL(relative)); |
575 assertEquals(expectedResult, redirectedUrl.toString()); | 584 assertEquals(expectedResult, redirectedUrl.toString()); |
576 } | 585 } |
577 } | 586 } |
LEFT | RIGHT |