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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 org.eclipse.jgit.lib.AnyObjectId;
  45. import org.eclipse.jgit.lib.Constants;
  46. public class RevObjectTest extends RevWalkTestCase {
  47. public void testId() throws Exception {
  48. final RevCommit a = commit();
  49. assertSame(a, a.getId());
  50. }
  51. public void testEqualsIsIdentity() throws Exception {
  52. final RevCommit a1 = commit();
  53. final RevCommit b1 = commit();
  54. assertTrue(a1.equals(a1));
  55. assertTrue(a1.equals((Object) a1));
  56. assertFalse(a1.equals(b1));
  57. assertFalse(a1.equals(a1.copy()));
  58. assertFalse(a1.equals((Object) a1.copy()));
  59. assertFalse(a1.equals(""));
  60. final RevWalk rw2 = new RevWalk(db);
  61. final RevCommit a2 = rw2.parseCommit(a1);
  62. final RevCommit b2 = rw2.parseCommit(b1);
  63. assertNotSame(a1, a2);
  64. assertNotSame(b1, b2);
  65. assertFalse(a1.equals(a2));
  66. assertFalse(b1.equals(b2));
  67. assertEquals(a1.hashCode(), a2.hashCode());
  68. assertEquals(b1.hashCode(), b2.hashCode());
  69. assertTrue(AnyObjectId.equals(a1, a2));
  70. assertTrue(AnyObjectId.equals(b1, b2));
  71. }
  72. public void testRevObjectTypes() throws Exception {
  73. assertEquals(Constants.OBJ_TREE, tree().getType());
  74. assertEquals(Constants.OBJ_COMMIT, commit().getType());
  75. assertEquals(Constants.OBJ_BLOB, blob("").getType());
  76. assertEquals(Constants.OBJ_TAG, tag("emptyTree", tree()).getType());
  77. }
  78. public void testHasRevFlag() throws Exception {
  79. final RevCommit a = commit();
  80. assertFalse(a.has(RevFlag.UNINTERESTING));
  81. a.flags |= RevWalk.UNINTERESTING;
  82. assertTrue(a.has(RevFlag.UNINTERESTING));
  83. }
  84. public void testHasAnyFlag() throws Exception {
  85. final RevCommit a = commit();
  86. final RevFlag flag1 = rw.newFlag("flag1");
  87. final RevFlag flag2 = rw.newFlag("flag2");
  88. final RevFlagSet s = new RevFlagSet();
  89. s.add(flag1);
  90. s.add(flag2);
  91. assertFalse(a.hasAny(s));
  92. a.flags |= flag1.mask;
  93. assertTrue(a.hasAny(s));
  94. }
  95. public void testHasAllFlag() 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.hasAll(s));
  103. a.flags |= flag1.mask;
  104. assertFalse(a.hasAll(s));
  105. a.flags |= flag2.mask;
  106. assertTrue(a.hasAll(s));
  107. }
  108. public void testAddRevFlag() throws Exception {
  109. final RevCommit a = commit();
  110. final RevFlag flag1 = rw.newFlag("flag1");
  111. final RevFlag flag2 = rw.newFlag("flag2");
  112. assertEquals(0, a.flags);
  113. a.add(flag1);
  114. assertEquals(flag1.mask, a.flags);
  115. a.add(flag2);
  116. assertEquals(flag1.mask | flag2.mask, a.flags);
  117. }
  118. public void testAddRevFlagSet() throws Exception {
  119. final RevCommit a = commit();
  120. final RevFlag flag1 = rw.newFlag("flag1");
  121. final RevFlag flag2 = rw.newFlag("flag2");
  122. final RevFlagSet s = new RevFlagSet();
  123. s.add(flag1);
  124. s.add(flag2);
  125. assertEquals(0, a.flags);
  126. a.add(s);
  127. assertEquals(flag1.mask | flag2.mask, a.flags);
  128. }
  129. public void testRemoveRevFlag() throws Exception {
  130. final RevCommit a = commit();
  131. final RevFlag flag1 = rw.newFlag("flag1");
  132. final RevFlag flag2 = rw.newFlag("flag2");
  133. a.add(flag1);
  134. a.add(flag2);
  135. assertEquals(flag1.mask | flag2.mask, a.flags);
  136. a.remove(flag2);
  137. assertEquals(flag1.mask, a.flags);
  138. }
  139. public void testRemoveRevFlagSet() throws Exception {
  140. final RevCommit a = commit();
  141. final RevFlag flag1 = rw.newFlag("flag1");
  142. final RevFlag flag2 = rw.newFlag("flag2");
  143. final RevFlag flag3 = rw.newFlag("flag3");
  144. final RevFlagSet s = new RevFlagSet();
  145. s.add(flag1);
  146. s.add(flag2);
  147. a.add(flag3);
  148. a.add(s);
  149. assertEquals(flag1.mask | flag2.mask | flag3.mask, a.flags);
  150. a.remove(s);
  151. assertEquals(flag3.mask, a.flags);
  152. }
  153. }