| OLD | NEW |
| (Empty) |
| 1 package org.adblockplus.libadblockplus.tests; | |
| 2 | |
| 3 import android.test.InstrumentationTestCase; | |
| 4 | |
| 5 import org.adblockplus.libadblockplus.android.Utils; | |
| 6 import org.junit.Test; | |
| 7 | |
| 8 import java.util.Arrays; | |
| 9 import java.util.LinkedList; | |
| 10 import java.util.List; | |
| 11 | |
| 12 /** | |
| 13 * Test for Utils | |
| 14 */ | |
| 15 public class UtilsTest extends InstrumentationTestCase | |
| 16 { | |
| 17 @Test | |
| 18 public void testJson_null() | |
| 19 { | |
| 20 final List<String> list = null; | |
| 21 String json = Utils.stringListToJsonArray(list); | |
| 22 assertEquals("[]", json); | |
| 23 } | |
| 24 | |
| 25 @Test | |
| 26 public void testJson_single() | |
| 27 { | |
| 28 final List<String> list = Arrays.asList("string1"); | |
| 29 String json = Utils.stringListToJsonArray(list); | |
| 30 assertEquals("[\"string1\"]", json); | |
| 31 } | |
| 32 | |
| 33 @Test | |
| 34 public void testJson_multiple() | |
| 35 { | |
| 36 final List<String> list = Arrays.asList("string1", "string2"); | |
| 37 String json = Utils.stringListToJsonArray(list); | |
| 38 assertEquals("[\"string1\",\"string2\"]", json); | |
| 39 } | |
| 40 | |
| 41 @Test | |
| 42 public void testJson_multipleWithNull() | |
| 43 { | |
| 44 final List<String> list = Arrays.asList("string1", null, "string2"); | |
| 45 String json = Utils.stringListToJsonArray(list); | |
| 46 assertEquals("[\"string1\",\"string2\"]", json); | |
| 47 } | |
| 48 | |
| 49 @Test | |
| 50 public void testJson_singleWithNull() | |
| 51 { | |
| 52 final List<String> list = new LinkedList<String>(); | |
| 53 list.add(null); | |
| 54 String json = Utils.stringListToJsonArray(list); | |
| 55 assertEquals("[]", json); | |
| 56 } | |
| 57 | |
| 58 @Test | |
| 59 public void testUrlWithoutParams_null() | |
| 60 { | |
| 61 try | |
| 62 { | |
| 63 Utils.getUrlWithoutParams(null); | |
| 64 fail(); | |
| 65 } | |
| 66 catch (IllegalArgumentException ignored) | |
| 67 { | |
| 68 // ignored | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 @Test | |
| 73 public void testUrlWithoutParams_empty() | |
| 74 { | |
| 75 String url = Utils.getUrlWithoutParams("https://www.google.com?"); | |
| 76 assertNotNull(url); | |
| 77 assertEquals("https://www.google.com", url); | |
| 78 } | |
| 79 | |
| 80 @Test | |
| 81 public void testUrlWithoutParams_withoutParams() | |
| 82 { | |
| 83 final String originalUrl = "http://www.google.com"; | |
| 84 String url = Utils.getUrlWithoutParams(originalUrl); | |
| 85 assertNotNull(url); | |
| 86 assertEquals(originalUrl, url); | |
| 87 } | |
| 88 | |
| 89 @Test | |
| 90 public void testUrlWithoutParams_ok() | |
| 91 { | |
| 92 String url = Utils.getUrlWithoutParams("https://www.google.com?q=adblockplus
"); | |
| 93 assertNotNull(url); | |
| 94 assertEquals("https://www.google.com", url); | |
| 95 } | |
| 96 | |
| 97 @Test | |
| 98 public void testUrlWithoutParams_multipleParams() | |
| 99 { | |
| 100 String url = Utils.getUrlWithoutParams("https://www.google.com?q=adblockplus
&gws_rd=cr"); | |
| 101 assertNotNull(url); | |
| 102 assertEquals("https://www.google.com", url); | |
| 103 } | |
| 104 | |
| 105 @Test | |
| 106 public void testUrlWithoutParams_language() | |
| 107 { | |
| 108 String url = Utils.getUrlWithoutParams("http://почта.рф?q=myemail"); // non-
English characters in URL | |
| 109 assertNotNull(url); | |
| 110 assertEquals("http://почта.рф", url); | |
| 111 } | |
| 112 | |
| 113 @Test | |
| 114 public void testUrlWithoutParams_digits() | |
| 115 { | |
| 116 String url = Utils.getUrlWithoutParams("https://www.google.com?q=123"); | |
| 117 assertNotNull(url); | |
| 118 assertEquals("https://www.google.com", url); | |
| 119 } | |
| 120 | |
| 121 @Test | |
| 122 public void testUrlWithoutParams_multipleQuestionMarks() | |
| 123 { | |
| 124 String url = Utils.getUrlWithoutParams("https://www.google.com?q=123?t=123")
; // invalid URL | |
| 125 assertNotNull(url); | |
| 126 assertEquals("https://www.google.com", url); | |
| 127 } | |
| 128 } | |
| OLD | NEW |