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