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

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