1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.revwalk;
45
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertFalse;
48 import static org.junit.Assert.assertNotNull;
49 import static org.junit.Assert.assertSame;
50 import static org.junit.Assert.assertTrue;
51
52 import java.util.Arrays;
53 import java.util.Iterator;
54
55 import org.junit.Test;
56
57 public class RevFlagSetTest extends RevWalkTestCase {
58 @Test
59 public void testEmpty() {
60 final RevFlagSet set = new RevFlagSet();
61 assertEquals(0, set.mask);
62 assertEquals(0, set.size());
63 assertNotNull(set.iterator());
64 assertFalse(set.iterator().hasNext());
65 }
66
67 @Test
68 public void testAddOne() {
69 final String flagName = "flag";
70 final RevFlag flag = rw.newFlag(flagName);
71 assertTrue(0 != flag.mask);
72 assertSame(flagName, flag.name);
73
74 final RevFlagSet set = new RevFlagSet();
75 assertTrue(set.add(flag));
76 assertFalse(set.add(flag));
77 assertEquals(flag.mask, set.mask);
78 assertEquals(1, set.size());
79 final Iterator<RevFlag> i = set.iterator();
80 assertTrue(i.hasNext());
81 assertSame(flag, i.next());
82 assertFalse(i.hasNext());
83 }
84
85 @Test
86 public void testAddTwo() {
87 final RevFlag flag1 = rw.newFlag("flag_1");
88 final RevFlag flag2 = rw.newFlag("flag_2");
89 assertEquals(0, (flag1.mask & flag2.mask));
90
91 final RevFlagSet set = new RevFlagSet();
92 assertTrue(set.add(flag1));
93 assertTrue(set.add(flag2));
94 assertEquals(flag1.mask | flag2.mask, set.mask);
95 assertEquals(2, set.size());
96 }
97
98 @Test
99 public void testContainsAll() {
100 final RevFlag flag1 = rw.newFlag("flag_1");
101 final RevFlag flag2 = rw.newFlag("flag_2");
102 final RevFlagSet set1 = new RevFlagSet();
103 assertTrue(set1.add(flag1));
104 assertTrue(set1.add(flag2));
105
106 assertTrue(set1.containsAll(Arrays
107 .asList(new RevFlag[] { flag1, flag2 })));
108
109 final RevFlagSet set2 = new RevFlagSet();
110 set2.add(rw.newFlag("flag_3"));
111 assertFalse(set1.containsAll(set2));
112 }
113
114 @Test
115 public void testEquals() {
116 final RevFlag flag1 = rw.newFlag("flag_1");
117 final RevFlag flag2 = rw.newFlag("flag_2");
118 final RevFlagSet set = new RevFlagSet();
119 assertTrue(set.add(flag1));
120 assertTrue(set.add(flag2));
121
122 assertEquals(set, new RevFlagSet(set));
123 assertTrue(new RevFlagSet(Arrays.asList(new RevFlag[] { flag1, flag2 }))
124 .equals(set));
125 }
126
127 @Test
128 public void testRemove() {
129 final RevFlag flag1 = rw.newFlag("flag_1");
130 final RevFlag flag2 = rw.newFlag("flag_2");
131 final RevFlagSet set = new RevFlagSet();
132 assertTrue(set.add(flag1));
133 assertTrue(set.add(flag2));
134
135 assertTrue(set.remove(flag1));
136 assertFalse(set.remove(flag1));
137 assertEquals(flag2.mask, set.mask);
138 assertFalse(set.contains(flag1));
139 }
140
141 @Test
142 public void testContains() {
143 final RevFlag flag1 = rw.newFlag("flag_1");
144 final RevFlag flag2 = rw.newFlag("flag_2");
145 final RevFlagSet set = new RevFlagSet();
146 set.add(flag1);
147 assertTrue(set.contains(flag1));
148 assertFalse(set.contains(flag2));
149 assertFalse(set.contains("bob"));
150 }
151 }