1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.patch;
45
46 import static java.lang.Integer.valueOf;
47 import static java.lang.Long.valueOf;
48 import static org.junit.Assert.assertEquals;
49 import static org.junit.Assert.assertSame;
50 import static org.junit.Assert.assertTrue;
51 import static org.junit.Assert.fail;
52
53 import java.io.IOException;
54 import java.io.InputStream;
55 import java.text.MessageFormat;
56
57 import org.eclipse.jgit.internal.JGitText;
58 import org.eclipse.jgit.junit.JGitTestUtil;
59 import org.junit.Test;
60
61 public class PatchCcErrorTest {
62 @Test
63 public void testError_CcTruncatedOld() throws IOException {
64 final Patch p = parseTestPatchFile();
65 assertEquals(1, p.getFiles().size());
66 assertEquals(3, p.getErrors().size());
67 {
68 final FormatError e = p.getErrors().get(0);
69 assertSame(FormatError.Severity.ERROR, e.getSeverity());
70 assertEquals(MessageFormat.format(
71 JGitText.get().truncatedHunkLinesMissingForAncestor,
72 valueOf(1), valueOf(1)), e.getMessage());
73 assertEquals(346, e.getOffset());
74 assertTrue(e.getLineText().startsWith(
75 "@@@ -55,12 -163,13 +163,15 @@@ public "));
76 }
77 {
78 final FormatError e = p.getErrors().get(1);
79 assertSame(FormatError.Severity.ERROR, e.getSeverity());
80 assertEquals(MessageFormat.format(
81 JGitText.get().truncatedHunkLinesMissingForAncestor,
82 valueOf(2), valueOf(2)), e.getMessage());
83 assertEquals(346, e.getOffset());
84 assertTrue(e.getLineText().startsWith(
85 "@@@ -55,12 -163,13 +163,15 @@@ public "));
86 }
87 {
88 final FormatError e = p.getErrors().get(2);
89 assertSame(FormatError.Severity.ERROR, e.getSeverity());
90 assertEquals("Truncated hunk, at least 3 new lines is missing", e
91 .getMessage());
92 assertEquals(346, e.getOffset());
93 assertTrue(e.getLineText().startsWith(
94 "@@@ -55,12 -163,13 +163,15 @@@ public "));
95 }
96 }
97
98 private Patch parseTestPatchFile() throws IOException {
99 final String patchFile = JGitTestUtil.getName() + ".patch";
100 final InputStream in = getClass().getResourceAsStream(patchFile);
101 if (in == null) {
102 fail("No " + patchFile + " test vector");
103 return null;
104 }
105 try {
106 final Patch p = new Patch();
107 p.parse(in);
108 return p;
109 } finally {
110 in.close();
111 }
112 }
113
114 }