1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }