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.

EditListTest.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (C) 2009, Google Inc. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.diff;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertFalse;
  13. import static org.junit.Assert.assertSame;
  14. import static org.junit.Assert.assertTrue;
  15. import java.util.Iterator;
  16. import org.junit.Test;
  17. public class EditListTest {
  18. @SuppressWarnings("unlikely-arg-type")
  19. @Test
  20. public void testEmpty() {
  21. final EditList l = new EditList();
  22. assertEquals(0, l.size());
  23. assertTrue(l.isEmpty());
  24. assertEquals("EditList[]", l.toString());
  25. assertEquals(l, l);
  26. assertEquals(new EditList(), l);
  27. assertFalse(l.equals(""));
  28. assertEquals(l.hashCode(), new EditList().hashCode());
  29. }
  30. @Test
  31. public void testAddOne() {
  32. final Edit e = new Edit(1, 2, 1, 1);
  33. final EditList l = new EditList();
  34. l.add(e);
  35. assertEquals(1, l.size());
  36. assertFalse(l.isEmpty());
  37. assertSame(e, l.get(0));
  38. assertSame(e, l.iterator().next());
  39. assertEquals(l, l);
  40. assertFalse(l.equals(new EditList()));
  41. final EditList l2 = new EditList();
  42. l2.add(e);
  43. assertEquals(l2, l);
  44. assertEquals(l, l2);
  45. assertEquals(l.hashCode(), l2.hashCode());
  46. }
  47. @Test
  48. public void testAddTwo() {
  49. final Edit e1 = new Edit(1, 2, 1, 1);
  50. final Edit e2 = new Edit(8, 8, 8, 12);
  51. final EditList l = new EditList();
  52. l.add(e1);
  53. l.add(e2);
  54. assertEquals(2, l.size());
  55. assertSame(e1, l.get(0));
  56. assertSame(e2, l.get(1));
  57. final Iterator<Edit> i = l.iterator();
  58. assertSame(e1, i.next());
  59. assertSame(e2, i.next());
  60. assertEquals(l, l);
  61. assertFalse(l.equals(new EditList()));
  62. final EditList l2 = new EditList();
  63. l2.add(e1);
  64. l2.add(e2);
  65. assertEquals(l2, l);
  66. assertEquals(l, l2);
  67. assertEquals(l.hashCode(), l2.hashCode());
  68. }
  69. @Test
  70. public void testSet() {
  71. final Edit e1 = new Edit(1, 2, 1, 1);
  72. final Edit e2 = new Edit(3, 4, 3, 3);
  73. final EditList l = new EditList();
  74. l.add(e1);
  75. assertSame(e1, l.get(0));
  76. assertSame(e1, l.set(0, e2));
  77. assertSame(e2, l.get(0));
  78. }
  79. @Test
  80. public void testRemove() {
  81. final Edit e1 = new Edit(1, 2, 1, 1);
  82. final Edit e2 = new Edit(8, 8, 8, 12);
  83. final EditList l = new EditList();
  84. l.add(e1);
  85. l.add(e2);
  86. l.remove(e1);
  87. assertEquals(1, l.size());
  88. assertSame(e2, l.get(0));
  89. }
  90. }