1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.trinidad.component;
20
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24 import java.util.Map;
25
26 import javax.faces.validator.Validator;
27
28 import junit.framework.Test;
29 import junit.framework.TestSuite;
30
31
32
33
34 public class UIXSelectManyTest extends UIXEditableValueTestCase
35 {
36
37
38
39
40
41 public UIXSelectManyTest(
42 String testName)
43 {
44 super(testName);
45 }
46
47 @Override
48 protected void setUp() throws Exception
49 {
50 super.setUp();
51 }
52
53 @Override
54 protected void tearDown() throws Exception
55 {
56 super.tearDown();
57 }
58
59 public static Test suite()
60 {
61 return new TestSuite(UIXSelectManyTest.class);
62 }
63
64
65
66
67
68 @SuppressWarnings("unchecked")
69 public void testAttributeMap()
70 {
71 UIXSelectMany component = createSelectMany();
72 assertEquals(null, component.getValueBinding("validators"));
73 Map<String, Object> attributes = component.getAttributes();
74 Validator[] validators = (Validator[]) attributes.get("validators");
75 assertEquals(0, validators.length);
76
77 component.addValidator(new javax.faces.validator.LengthValidator());
78 validators = (Validator[]) attributes.get("validators");
79 assertEquals(1, validators.length);
80 assertTrue(validators[0] instanceof javax.faces.validator.LengthValidator);
81 }
82
83 public void testCompareValues()
84 {
85 UIXSelectMany component = createSelectMany();
86
87 assertFalse(component.compareValues(null, null));
88 assertFalse(component.compareValues(null, new Object[0]));
89 assertFalse(component.compareValues(null, new ArrayList<String>()));
90 assertTrue(component.compareValues(null, new Object[1]));
91 assertFalse(component.compareValues(new int[]{1, 2}, new int[]{2, 1}));
92 assertTrue(component.compareValues(new int[]{1, 2, 3}, new int[]{2, 1}));
93
94 ArrayList<String> one;
95 ArrayList<String> two;
96
97 one = new ArrayList<String>();
98 one.add("foo");
99 one.add("bar");
100
101 two = new ArrayList<String>();
102 two.add("bar");
103 two.add("foo");
104
105 assertFalse(component.compareValues(one, two));
106
107 assertEquals(2, one.size());
108 assertEquals(2, two.size());
109
110 one.add("baz");
111 assertTrue(component.compareValues(one, two));
112 }
113
114 @Override
115 public void testProcessValidations()
116 {
117 String[] submittedValue = new String[] {"foo", "bar"};
118 List<String> convertedValue = Arrays.asList(submittedValue);
119
120 doTestProcessValidations(createEditableValue(), submittedValue, convertedValue);
121 }
122
123 @Override
124 protected UIXEditableValue createEditableValue()
125 {
126 return createSelectMany();
127 }
128
129 protected UIXSelectMany createSelectMany()
130 {
131 return new UIXSelectMany();
132 }
133
134 }