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.util;
20  
21  import junit.framework.Test;
22  import junit.framework.TestCase;
23  import junit.framework.TestSuite;
24  
25  import java.util.TreeSet;
26  import java.util.List;
27  
28  import org.apache.myfaces.trinidad.util.ListFromCollection;
29  
30  public class ListFromCollectionTest extends TestCase
31  {
32    public static final Test suite()
33    {
34      return new TestSuite(ListFromCollectionTest.class);
35    }
36    
37    public static void main(String[] args) throws Throwable
38    {
39      junit.textui.TestRunner.run(suite());
40    }
41  
42    public ListFromCollectionTest(
43      String testName)
44    {
45      super(testName);
46    }
47  
48    public void testGet()
49    {
50      TreeSet<Integer> tree = new TreeSet<Integer>();
51      for (int i = 0; i < 250; i++)
52        tree.add(new Integer(i));
53  
54      ListFromCollection lfc = new ListFromCollection();
55      lfc.setSize(100);
56  
57      List<?> list = lfc.getList().get(tree);
58      assertEquals(tree.size(), list.size());
59      assertEquals(new Integer(5), list.get(5));
60      assertEquals(new Integer(155), list.get(155));
61      assertEquals(new Integer(0), list.get(0));
62      assertEquals(new Integer(99), list.get(99));
63      assertEquals(new Integer(100), list.get(100));
64      
65      try
66      {
67        list.get(-1);
68        fail();
69      }          
70      catch (IndexOutOfBoundsException ioobe)
71      {
72      }
73  
74      try
75      {
76        list.get(250);
77        fail();
78      }          
79      catch (IndexOutOfBoundsException ioobe)
80      {
81      }
82    }
83  }