1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package cgeo.geocaching;
import cgeo.geocaching.network.Parameters;
import android.test.AndroidTestCase;
import java.security.InvalidParameterException;
import junit.framework.Assert;
public class ParametersTest extends AndroidTestCase {
public static void testException() {
try {
final Parameters params = new Parameters("aaa", "AAA", "bbb");
params.clear(); // this will never be invoked, but suppresses warnings about unused objects
Assert.fail("Exception not raised");
} catch (InvalidParameterException e) {
// Ok
}
try {
final Parameters params = new Parameters("aaa", "AAA");
params.put("bbb", "BBB", "ccc");
Assert.fail("Exception not raised");
} catch (InvalidParameterException e) {
// Ok
}
}
public static void testMultipleValues() {
final Parameters params = new Parameters("aaa", "AAA", "bbb", "BBB");
params.put("ccc", "CCC", "ddd", "DDD");
Assert.assertEquals("aaa=AAA&bbb=BBB&ccc=CCC&ddd=DDD", params.toString());
}
public static void testSort() {
final Parameters params = new Parameters();
params.put("aaa", "AAA");
params.put("ccc", "CCC");
params.put("bbb", "BBB");
Assert.assertEquals("aaa=AAA&ccc=CCC&bbb=BBB", params.toString());
params.sort();
Assert.assertEquals("aaa=AAA&bbb=BBB&ccc=CCC", params.toString());
}
public static void testToString() {
final Parameters params = new Parameters();
params.put("name", "foo&bar");
params.put("type", "moving");
Assert.assertEquals("name=foo%26bar&type=moving", params.toString());
}
}
|