01: package org.drools.decisiontable.parser;
02:
03: import java.util.HashMap;
04: import java.util.Map;
05:
06: import junit.framework.TestCase;
07:
08: public class ArrayColumnTest extends TestCase {
09:
10: public void testGetValueSingle() {
11: ArrayColumn ac = new ArrayColumn("array column");
12: String[] value = (String[]) ac.getValue("value1");
13: assertEquals(1, value.length);
14: assertEquals("value1", value[0]);
15: }
16:
17: public void testGetValueTrailingComma() {
18: ArrayColumn ac = new ArrayColumn("array column");
19: String[] value = (String[]) ac.getValue("value1,");
20: assertEquals(2, value.length);
21: assertEquals("value1", value[0]);
22: assertEquals("", value[1]);
23: }
24:
25: public void testGetValueLeadingComma() {
26: ArrayColumn ac = new ArrayColumn("array column");
27: String[] value = (String[]) ac.getValue(",value2");
28: assertEquals(2, value.length);
29: assertEquals("value2", value[1]);
30: }
31:
32: public void testGetValueMultiple() {
33: ArrayColumn ac = new ArrayColumn("array column");
34: String[] value = (String[]) ac.getValue("value1,value2,value3");
35: assertEquals(3, value.length);
36: assertEquals("value1", value[0]);
37: assertEquals("value2", value[1]);
38: assertEquals("value3", value[2]);
39: }
40:
41: public void testAddValueSingle() {
42: ArrayColumn ac = new ArrayColumn("array");
43: String[] value = new String[] { "value" };
44: Map vars = new HashMap();
45: ac.addValue(vars, value);
46: assertEquals("value", vars.get("array0"));
47: }
48:
49: public void testAddValueMultiple() {
50: ArrayColumn ac = new ArrayColumn("array");
51: String[] value = new String[] { "value1", "value2" };
52: Map vars = new HashMap();
53: ac.addValue(vars, value);
54: assertEquals("value1", vars.get("array0"));
55: assertEquals("value2", vars.get("array1"));
56: }
57:
58: }
|