You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RevObjectTest.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (C) 2009-2010, Google Inc.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.revwalk;
  44. import static org.junit.Assert.assertEquals;
  45. import static org.junit.Assert.assertFalse;
  46. import static org.junit.Assert.assertNotSame;
  47. import static org.junit.Assert.assertSame;
  48. import static org.junit.Assert.assertTrue;
  49. import org.eclipse.jgit.lib.AnyObjectId;
  50. import org.eclipse.jgit.lib.Constants;
  51. import org.junit.Test;
  52. public class RevObjectTest extends RevWalkTestCase {
  53. @Test
  54. public void testId() throws Exception {
  55. final RevCommit a = commit();
  56. assertSame(a, a.getId());
  57. }
  58. @SuppressWarnings("unlikely-arg-type")
  59. @Test
  60. public void testEquals() throws Exception {
  61. final RevCommit a1 = commit();
  62. final RevCommit b1 = commit();
  63. assertTrue(a1.equals(a1));
  64. assertTrue(a1.equals((Object) a1));
  65. assertFalse(a1.equals(b1));
  66. assertTrue(a1.equals(a1));
  67. assertTrue(a1.equals((Object) a1));
  68. assertFalse(a1.equals(""));
  69. final RevCommit a2;
  70. final RevCommit b2;
  71. try (RevWalk rw2 = new RevWalk(db)) {
  72. a2 = rw2.parseCommit(a1);
  73. b2 = rw2.parseCommit(b1);
  74. }
  75. assertNotSame(a1, a2);
  76. assertNotSame(b1, b2);
  77. assertTrue(a1.equals(a2));
  78. assertTrue(b1.equals(b2));
  79. assertEquals(a1.hashCode(), a2.hashCode());
  80. assertEquals(b1.hashCode(), b2.hashCode());
  81. assertTrue(AnyObjectId.equals(a1, a2));
  82. assertTrue(AnyObjectId.equals(b1, b2));
  83. }
  84. @Test
  85. public void testRevObjectTypes() throws Exception {
  86. assertEquals(Constants.OBJ_TREE, tree().getType());
  87. assertEquals(Constants.OBJ_COMMIT, commit().getType());
  88. assertEquals(Constants.OBJ_BLOB, blob("").getType());
  89. assertEquals(Constants.OBJ_TAG, tag("emptyTree", tree()).getType());
  90. }
  91. @Test
  92. public void testHasRevFlag() throws Exception {
  93. final RevCommit a = commit();
  94. assertFalse(a.has(RevFlag.UNINTERESTING));
  95. a.flags |= RevWalk.UNINTERESTING;
  96. assertTrue(a.has(RevFlag.UNINTERESTING));
  97. }
  98. @Test
  99. public void testHasAnyFlag() throws Exception {
  100. final RevCommit a = commit();
  101. final RevFlag flag1 = rw.newFlag("flag1");
  102. final RevFlag flag2 = rw.newFlag("flag2");
  103. final RevFlagSet s = new RevFlagSet();
  104. s.add(flag1);
  105. s.add(flag2);
  106. assertFalse(a.hasAny(s));
  107. a.flags |= flag1.mask;
  108. assertTrue(a.hasAny(s));
  109. }
  110. @Test
  111. public void testHasAllFlag() throws Exception {
  112. final RevCommit a = commit();
  113. final RevFlag flag1 = rw.newFlag("flag1");
  114. final RevFlag flag2 = rw.newFlag("flag2");
  115. final RevFlagSet s = new RevFlagSet();
  116. s.add(flag1);
  117. s.add(flag2);
  118. assertFalse(a.hasAll(s));
  119. a.flags |= flag1.mask;
  120. assertFalse(a.hasAll(s));
  121. a.flags |= flag2.mask;
  122. assertTrue(a.hasAll(s));
  123. }
  124. @Test
  125. public void testAddRevFlag() throws Exception {
  126. final RevCommit a = commit();
  127. final RevFlag flag1 = rw.newFlag("flag1");
  128. final RevFlag flag2 = rw.newFlag("flag2");
  129. assertEquals(0, a.flags);
  130. a.add(flag1);
  131. assertEquals(flag1.mask, a.flags);
  132. a.add(flag2);
  133. assertEquals(flag1.mask | flag2.mask, a.flags);
  134. }
  135. @Test
  136. public void testAddRevFlagSet() throws Exception {
  137. final RevCommit a = commit();
  138. final RevFlag flag1 = rw.newFlag("flag1");
  139. final RevFlag flag2 = rw.newFlag("flag2");
  140. final RevFlagSet s = new RevFlagSet();
  141. s.add(flag1);
  142. s.add(flag2);
  143. assertEquals(0, a.flags);
  144. a.add(s);
  145. assertEquals(flag1.mask | flag2.mask, a.flags);
  146. }
  147. @Test
  148. public void testRemoveRevFlag() throws Exception {
  149. final RevCommit a = commit();
  150. final RevFlag flag1 = rw.newFlag("flag1");
  151. final RevFlag flag2 = rw.newFlag("flag2");
  152. a.add(flag1);
  153. a.add(flag2);
  154. assertEquals(flag1.mask | flag2.mask, a.flags);
  155. a.remove(flag2);
  156. assertEquals(flag1.mask, a.flags);
  157. }
  158. @Test
  159. public void testRemoveRevFlagSet() throws Exception {
  160. final RevCommit a = commit();
  161. final RevFlag flag1 = rw.newFlag("flag1");
  162. final RevFlag flag2 = rw.newFlag("flag2");
  163. final RevFlag flag3 = rw.newFlag("flag3");
  164. final RevFlagSet s = new RevFlagSet();
  165. s.add(flag1);
  166. s.add(flag2);
  167. a.add(flag3);
  168. a.add(s);
  169. assertEquals(flag1.mask | flag2.mask | flag3.mask, a.flags);
  170. a.remove(s);
  171. assertEquals(flag3.mask, a.flags);
  172. }
  173. }