1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.diff;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertFalse;
15 import static org.junit.Assert.assertSame;
16 import static org.junit.Assert.assertTrue;
17
18 import java.util.Iterator;
19
20 import org.junit.Test;
21
22 public class EditListTest {
23 @SuppressWarnings("unlikely-arg-type")
24 @Test
25 public void testEmpty() {
26 final EditList l = new EditList();
27 assertEquals(0, l.size());
28 assertTrue(l.isEmpty());
29 assertEquals("EditList[]", l.toString());
30
31 assertEquals(l, l);
32 assertEquals(new EditList(), l);
33 assertFalse(l.equals(""));
34 assertEquals(l.hashCode(), new EditList().hashCode());
35 }
36
37 @Test
38 public void testAddOne() {
39 final Edit e = new Edit(1, 2, 1, 1);
40 final EditList l = new EditList();
41 l.add(e);
42 assertEquals(1, l.size());
43 assertFalse(l.isEmpty());
44 assertSame(e, l.get(0));
45 assertSame(e, l.iterator().next());
46
47 assertEquals(l, l);
48 assertFalse(l.equals(new EditList()));
49
50 final EditList l2 = new EditList();
51 l2.add(e);
52 assertEquals(l2, l);
53 assertEquals(l, l2);
54 assertEquals(l.hashCode(), l2.hashCode());
55 }
56
57 @Test
58 public void testAddTwo() {
59 final Edit e1 = new Edit(1, 2, 1, 1);
60 final Edit e2 = new Edit(8, 8, 8, 12);
61 final EditList l = new EditList();
62 l.add(e1);
63 l.add(e2);
64 assertEquals(2, l.size());
65 assertSame(e1, l.get(0));
66 assertSame(e2, l.get(1));
67
68 final Iterator<Edit> i = l.iterator();
69 assertSame(e1, i.next());
70 assertSame(e2, i.next());
71
72 assertEquals(l, l);
73 assertFalse(l.equals(new EditList()));
74
75 final EditList l2 = new EditList();
76 l2.add(e1);
77 l2.add(e2);
78 assertEquals(l2, l);
79 assertEquals(l, l2);
80 assertEquals(l.hashCode(), l2.hashCode());
81 }
82
83 @Test
84 public void testSet() {
85 final Edit e1 = new Edit(1, 2, 1, 1);
86 final Edit e2 = new Edit(3, 4, 3, 3);
87 final EditList l = new EditList();
88 l.add(e1);
89 assertSame(e1, l.get(0));
90 assertSame(e1, l.set(0, e2));
91 assertSame(e2, l.get(0));
92 }
93
94 @Test
95 public void testRemove() {
96 final Edit e1 = new Edit(1, 2, 1, 1);
97 final Edit e2 = new Edit(8, 8, 8, 12);
98 final EditList l = new EditList();
99 l.add(e1);
100 l.add(e2);
101 l.remove(e1);
102 assertEquals(1, l.size());
103 assertSame(e2, l.get(0));
104 }
105 }