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