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