1 package org.apache.maven.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.util.Arrays;
22 import java.util.HashSet;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Set;
26
27 import junit.framework.TestCase;
28
29 /**
30 * Test InsertionOrderedSet.
31 *
32 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
33 * @version $Id: InsertionOrderedSetTest.java 517014 2007-03-11 21:15:50Z ltheussl $
34 */
35 public class InsertionOrderedSetTest
36 extends TestCase
37 {
38 private Set set = new InsertionOrderedSet();
39
40 private static final String STRING_1 = "zzz";
41
42 private static final String STRING_2 = "qqq";
43
44 private static final String STRING_3 = "www";
45
46 private static final HashSet REMOVED_ELEMENT_SET = new HashSet( Arrays.asList( new String[] { STRING_1, STRING_3 } ) );
47
48 private static final HashSet OUTPUT_SET = new HashSet( Arrays
49 .asList( new String[] { STRING_1, STRING_2, STRING_3 } ) );
50
51 private static final List INPUT_SET = Arrays.asList( new String[] { STRING_1, STRING_2, STRING_1, STRING_3 } );
52
53 public void setUp()
54 throws Exception
55 {
56 }
57
58 public void testAdd()
59 {
60 set.add( STRING_1 );
61 set.add( STRING_2 );
62 set.add( STRING_1 );
63 set.add( STRING_3 );
64
65 assertEquals( OUTPUT_SET, set );
66 }
67
68 public void testAddAll()
69 {
70 set.addAll( INPUT_SET );
71 assertEquals( OUTPUT_SET, set );
72 }
73
74 public void testConstructor()
75 {
76 Set set = new InsertionOrderedSet( INPUT_SET );
77 assertEquals( OUTPUT_SET, set );
78 }
79
80 public void testRemove()
81 {
82 set.addAll( INPUT_SET );
83 set.remove( STRING_2 );
84 assertEquals( REMOVED_ELEMENT_SET, set );
85 }
86
87 public void testIterator()
88 {
89 set.addAll( INPUT_SET );
90
91 Iterator i = set.iterator();
92 assertEquals( STRING_1, i.next() );
93 assertEquals( STRING_2, i.next() );
94 assertEquals( STRING_3, i.next() );
95 }
96
97 public void testIteratorRemove()
98 {
99 set.addAll( INPUT_SET );
100
101 Iterator i = set.iterator();
102 assertEquals( STRING_1, i.next() );
103 assertEquals( STRING_2, i.next() );
104 i.remove();
105 assertEquals( STRING_3, i.next() );
106
107 assertEquals( REMOVED_ELEMENT_SET, set );
108 }
109
110 }