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.

RevFlagSetTest.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (C) 2009, 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.assertNotNull;
  47. import static org.junit.Assert.assertSame;
  48. import static org.junit.Assert.assertTrue;
  49. import java.util.Arrays;
  50. import java.util.Iterator;
  51. import org.junit.Test;
  52. public class RevFlagSetTest extends RevWalkTestCase {
  53. @Test
  54. public void testEmpty() {
  55. final RevFlagSet set = new RevFlagSet();
  56. assertEquals(0, set.mask);
  57. assertEquals(0, set.size());
  58. assertNotNull(set.iterator());
  59. assertFalse(set.iterator().hasNext());
  60. }
  61. @Test
  62. public void testAddOne() {
  63. final String flagName = "flag";
  64. final RevFlag flag = rw.newFlag(flagName);
  65. assertTrue(0 != flag.mask);
  66. assertSame(flagName, flag.name);
  67. final RevFlagSet set = new RevFlagSet();
  68. assertTrue(set.add(flag));
  69. assertFalse(set.add(flag));
  70. assertEquals(flag.mask, set.mask);
  71. assertEquals(1, set.size());
  72. final Iterator<RevFlag> i = set.iterator();
  73. assertTrue(i.hasNext());
  74. assertSame(flag, i.next());
  75. assertFalse(i.hasNext());
  76. }
  77. @Test
  78. public void testAddTwo() {
  79. final RevFlag flag1 = rw.newFlag("flag_1");
  80. final RevFlag flag2 = rw.newFlag("flag_2");
  81. assertEquals(0, (flag1.mask & flag2.mask));
  82. final RevFlagSet set = new RevFlagSet();
  83. assertTrue(set.add(flag1));
  84. assertTrue(set.add(flag2));
  85. assertEquals(flag1.mask | flag2.mask, set.mask);
  86. assertEquals(2, set.size());
  87. }
  88. @Test
  89. public void testContainsAll() {
  90. final RevFlag flag1 = rw.newFlag("flag_1");
  91. final RevFlag flag2 = rw.newFlag("flag_2");
  92. final RevFlagSet set1 = new RevFlagSet();
  93. assertTrue(set1.add(flag1));
  94. assertTrue(set1.add(flag2));
  95. assertTrue(set1.containsAll(Arrays
  96. .asList(new RevFlag[] { flag1, flag2 })));
  97. final RevFlagSet set2 = new RevFlagSet();
  98. set2.add(rw.newFlag("flag_3"));
  99. assertFalse(set1.containsAll(set2));
  100. }
  101. @Test
  102. public void testEquals() {
  103. final RevFlag flag1 = rw.newFlag("flag_1");
  104. final RevFlag flag2 = rw.newFlag("flag_2");
  105. final RevFlagSet set = new RevFlagSet();
  106. assertTrue(set.add(flag1));
  107. assertTrue(set.add(flag2));
  108. assertEquals(set, new RevFlagSet(set));
  109. assertTrue(new RevFlagSet(Arrays.asList(new RevFlag[] { flag1, flag2 }))
  110. .equals(set));
  111. }
  112. @Test
  113. public void testRemove() {
  114. final RevFlag flag1 = rw.newFlag("flag_1");
  115. final RevFlag flag2 = rw.newFlag("flag_2");
  116. final RevFlagSet set = new RevFlagSet();
  117. assertTrue(set.add(flag1));
  118. assertTrue(set.add(flag2));
  119. assertTrue(set.remove(flag1));
  120. assertFalse(set.remove(flag1));
  121. assertEquals(flag2.mask, set.mask);
  122. assertFalse(set.contains(flag1));
  123. }
  124. @Test
  125. public void testContains() {
  126. final RevFlag flag1 = rw.newFlag("flag_1");
  127. final RevFlag flag2 = rw.newFlag("flag_2");
  128. final RevFlagSet set = new RevFlagSet();
  129. set.add(flag1);
  130. assertTrue(set.contains(flag1));
  131. assertFalse(set.contains(flag2));
  132. assertFalse(set.contains("bob"));
  133. }
  134. }