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.assertNotSame;
49 import static org.junit.Assert.assertSame;
50 import static org.junit.Assert.assertTrue;
51
52 import org.eclipse.jgit.lib.AnyObjectId;
53 import org.eclipse.jgit.lib.Constants;
54 import org.junit.Test;
55
56 public class RevObjectTest extends RevWalkTestCase {
57 @Test
58 public void testId() throws Exception {
59 final RevCommit a = commit();
60 assertSame(a, a.getId());
61 }
62
63 @Test
64 public void testEquals() throws Exception {
65 final RevCommit a1 = commit();
66 final RevCommit b1 = commit();
67
68 assertTrue(a1.equals(a1));
69 assertTrue(a1.equals((Object) a1));
70 assertFalse(a1.equals(b1));
71
72 assertTrue(a1.equals(a1));
73 assertTrue(a1.equals((Object) a1));
74 assertFalse(a1.equals(""));
75
76 final RevWalk rw2 = new RevWalk(db);
77 final RevCommit a2 = rw2.parseCommit(a1);
78 final RevCommit b2 = rw2.parseCommit(b1);
79 assertNotSame(a1, a2);
80 assertNotSame(b1, b2);
81
82 assertTrue(a1.equals(a2));
83 assertTrue(b1.equals(b2));
84
85 assertEquals(a1.hashCode(), a2.hashCode());
86 assertEquals(b1.hashCode(), b2.hashCode());
87
88 assertTrue(AnyObjectId.equals(a1, a2));
89 assertTrue(AnyObjectId.equals(b1, b2));
90 }
91
92 @Test
93 public void testRevObjectTypes() throws Exception {
94 assertEquals(Constants.OBJ_TREE, tree().getType());
95 assertEquals(Constants.OBJ_COMMIT, commit().getType());
96 assertEquals(Constants.OBJ_BLOB, blob("").getType());
97 assertEquals(Constants.OBJ_TAG, tag("emptyTree", tree()).getType());
98 }
99
100 @Test
101 public void testHasRevFlag() throws Exception {
102 final RevCommit a = commit();
103 assertFalse(a.has(RevFlag.UNINTERESTING));
104 a.flags |= RevWalk.UNINTERESTING;
105 assertTrue(a.has(RevFlag.UNINTERESTING));
106 }
107
108 @Test
109 public void testHasAnyFlag() throws Exception {
110 final RevCommit a = commit();
111 final RevFlag flag1 = rw.newFlag("flag1");
112 final RevFlag flag2 = rw.newFlag("flag2");
113 final RevFlagSet s = new RevFlagSet();
114 s.add(flag1);
115 s.add(flag2);
116
117 assertFalse(a.hasAny(s));
118 a.flags |= flag1.mask;
119 assertTrue(a.hasAny(s));
120 }
121
122 @Test
123 public void testHasAllFlag() throws Exception {
124 final RevCommit a = commit();
125 final RevFlag flag1 = rw.newFlag("flag1");
126 final RevFlag flag2 = rw.newFlag("flag2");
127 final RevFlagSet s = new RevFlagSet();
128 s.add(flag1);
129 s.add(flag2);
130
131 assertFalse(a.hasAll(s));
132 a.flags |= flag1.mask;
133 assertFalse(a.hasAll(s));
134 a.flags |= flag2.mask;
135 assertTrue(a.hasAll(s));
136 }
137
138 @Test
139 public void testAddRevFlag() throws Exception {
140 final RevCommit a = commit();
141 final RevFlag flag1 = rw.newFlag("flag1");
142 final RevFlag flag2 = rw.newFlag("flag2");
143 assertEquals(0, a.flags);
144
145 a.add(flag1);
146 assertEquals(flag1.mask, a.flags);
147
148 a.add(flag2);
149 assertEquals(flag1.mask | flag2.mask, a.flags);
150 }
151
152 @Test
153 public void testAddRevFlagSet() throws Exception {
154 final RevCommit a = commit();
155 final RevFlag flag1 = rw.newFlag("flag1");
156 final RevFlag flag2 = rw.newFlag("flag2");
157 final RevFlagSet s = new RevFlagSet();
158 s.add(flag1);
159 s.add(flag2);
160
161 assertEquals(0, a.flags);
162
163 a.add(s);
164 assertEquals(flag1.mask | flag2.mask, a.flags);
165 }
166
167 @Test
168 public void testRemoveRevFlag() throws Exception {
169 final RevCommit a = commit();
170 final RevFlag flag1 = rw.newFlag("flag1");
171 final RevFlag flag2 = rw.newFlag("flag2");
172 a.add(flag1);
173 a.add(flag2);
174 assertEquals(flag1.mask | flag2.mask, a.flags);
175 a.remove(flag2);
176 assertEquals(flag1.mask, a.flags);
177 }
178
179 @Test
180 public void testRemoveRevFlagSet() throws Exception {
181 final RevCommit a = commit();
182 final RevFlag flag1 = rw.newFlag("flag1");
183 final RevFlag flag2 = rw.newFlag("flag2");
184 final RevFlag flag3 = rw.newFlag("flag3");
185 final RevFlagSet s = new RevFlagSet();
186 s.add(flag1);
187 s.add(flag2);
188 a.add(flag3);
189 a.add(s);
190 assertEquals(flag1.mask | flag2.mask | flag3.mask, a.flags);
191 a.remove(s);
192 assertEquals(flag3.mask, a.flags);
193 }
194 }