| 1 | |
package org.webslinger.collections.tests; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.HashMap; |
| 5 | |
import java.util.Map; |
| 6 | |
|
| 7 | |
import org.webslinger.collections.CollectionUtil; |
| 8 | |
import org.webslinger.containers.TestContainer; |
| 9 | |
|
| 10 | |
public class TestCollectionUtil extends TestContainer.TestContainerTestCase { |
| 11 | |
public TestCollectionUtil(String name) { |
| 12 | 3 | super(name); |
| 13 | 3 | } |
| 14 | |
|
| 15 | |
public void testPush() { |
| 16 | 1 | Map wanted = map(new Object[] { |
| 17 | |
"a", map(new Object[] { |
| 18 | |
"A", list(new Object[] {"foo", "bar"}) |
| 19 | |
}), |
| 20 | |
"b", map(new Object[] { |
| 21 | |
"B", list(new Object[] {"one", "random"}), |
| 22 | |
"C", list(new Object[] {"two"}) |
| 23 | |
}) |
| 24 | |
}); |
| 25 | 1 | HashMap container = new HashMap(); |
| 26 | 1 | CollectionUtil.push(container, "a.A", "foo"); |
| 27 | 1 | CollectionUtil.push(container, "b.B", "one"); |
| 28 | 1 | CollectionUtil.push(container, "a.A", "bar"); |
| 29 | 1 | CollectionUtil.push(container, "b.C", "two"); |
| 30 | 1 | CollectionUtil.push(container, "b.B", "random"); |
| 31 | 1 | System.err.println("wanted=" + wanted); |
| 32 | 1 | System.err.println("container=" + container); |
| 33 | 1 | assertEquals(wanted, container); |
| 34 | 1 | } |
| 35 | |
|
| 36 | |
public void testExpandMap() { |
| 37 | 1 | Map input = map(new Object[] { |
| 38 | |
"a.b.c", "one", |
| 39 | |
"1.2.3", "two", |
| 40 | |
"a.b.C", "ONE", |
| 41 | |
"1.2.foo", "bar", |
| 42 | |
"a.c.3", new String[] {"first", "second", "third"}, |
| 43 | |
}); |
| 44 | 1 | Map result = CollectionUtil.expandMap(input); |
| 45 | 1 | System.err.println("input=" + input); |
| 46 | 1 | System.err.println("result=" + result); |
| 47 | 1 | } |
| 48 | |
|
| 49 | |
public void testFlattenMap() { |
| 50 | 1 | Map input = map(new Object[] { |
| 51 | |
"a", map(new Object[] { |
| 52 | |
"b", map(new Object[] { |
| 53 | |
"c", "one", |
| 54 | |
"C", "ONE", |
| 55 | |
}), |
| 56 | |
}), |
| 57 | |
"1", map(new Object[] { |
| 58 | |
"2", map(new Object[] { |
| 59 | |
"3", "two", |
| 60 | |
"foo", "bar", |
| 61 | |
}), |
| 62 | |
}), |
| 63 | |
}); |
| 64 | 1 | Map result = CollectionUtil.flattenMap(input); |
| 65 | 1 | System.err.println("input=" + input); |
| 66 | 1 | System.err.println("result=" + result); |
| 67 | 1 | } |
| 68 | |
} |