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

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