View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  
25  /**
26   * Unit tests for UIXSelectOrder.
27   *
28   */
29  public class UIXSelectOrderTest extends UIXSelectManyTest
30  {
31    /**
32     * Creates a new UIXSelectOrderTest.
33     *
34     * @param testName  the unit test name
35     */
36    public UIXSelectOrderTest(
37      String testName)
38    {
39      super(testName);
40    }
41  
42    @Override
43    public void testCompareValues()
44    {
45      UIXSelectOrder component = createSelectOrder();
46  
47      assertFalse(component.compareValues(null, null));
48      assertFalse(component.compareValues(null, new Object[0]));
49      assertFalse(component.compareValues(null, new ArrayList<String>()));
50      assertTrue(component.compareValues(null, new Object[1]));
51      assertTrue(component.compareValues(new int[]{1, 2}, new int[]{2, 1}));
52      assertTrue(component.compareValues(new int[]{1, 2, 3}, new int[]{2, 1}));
53  
54      ArrayList<String> one;
55      ArrayList<String> two;
56  
57      one = new ArrayList<String>();
58      one.add("foo");
59      one.add("bar");
60  
61      two = new ArrayList<String>();
62      two.add("bar");
63      two.add("foo");
64  
65      assertTrue(component.compareValues(one, two));
66      // Make sure compareValues didn't destroy either list
67  
68      assertEquals(2, one.size());
69      assertEquals(2, two.size());
70  
71      one.add("baz");
72      assertTrue(component.compareValues(one, two));
73    }
74  
75    @Override
76    public void testProcessValidations()
77    {
78      String[] submittedValue = new String[] {"foo", "bar"};
79      List<String> convertedValue = Arrays.asList(submittedValue);
80  
81      doTestProcessValidations(createEditableValue(), submittedValue, convertedValue);
82    }
83  
84    @Override
85    protected UIXEditableValue createEditableValue()
86    {
87      return createSelectOrder();
88    }
89  
90    @Override
91    protected UIXSelectMany createSelectMany()
92    {
93      return createSelectOrder();
94    }
95  
96    protected UIXSelectOrder createSelectOrder()
97    {
98      return new UIXSelectOrder();
99    }
100 
101 }