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