summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorHan-Wen NIenhuys <hanwen@google.com>2023-03-28 05:51:18 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2023-03-28 05:51:18 -0400
commit5166ded0986df7a99bbc9ae6bc057a27a1e7d974 (patch)
treebbee217c8ae35121a7eb124d82fbaa396029cd08 /org.eclipse.jgit.test/tst
parenta30c1da323768d62a9ce914edc62f4ab195fed26 (diff)
parent3a913a8c341aba00f6b16aa1814ba75b83273972 (diff)
downloadjgit-5166ded0986df7a99bbc9ae6bc057a27a1e7d974.tar.gz
jgit-5166ded0986df7a99bbc9ae6bc057a27a1e7d974.zip
Merge "Fix PatchApplier error handling."
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java28
1 files changed, 19 insertions, 9 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java
index 893fd61556..10b6d567e4 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java
@@ -26,8 +26,6 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.api.errors.PatchApplyException;
-import org.eclipse.jgit.api.errors.PatchFormatException;
import org.eclipse.jgit.attributes.FilterCommand;
import org.eclipse.jgit.attributes.FilterCommandFactory;
import org.eclipse.jgit.attributes.FilterCommandRegistry;
@@ -112,15 +110,17 @@ public class PatchApplierTest {
return new String(postImage, StandardCharsets.UTF_8);
}
- protected Result applyPatch()
- throws PatchApplyException, PatchFormatException, IOException {
- InputStream patchStream = getTestResource(name + ".patch");
- if (inCore) {
- try (ObjectInserter oi = db.newObjectInserter()) {
- return new PatchApplier(db, baseTip, oi).applyPatch(patchStream);
+ protected Result applyPatch() throws IOException {
+ try (InputStream patchStream = getTestResource(name + ".patch")) {
+ Patch patch = new Patch();
+ patch.parse(patchStream);
+ if (inCore) {
+ try (ObjectInserter oi = db.newObjectInserter()) {
+ return new PatchApplier(db, baseTip, oi).applyPatch(patch);
+ }
}
+ return new PatchApplier(db).applyPatch(patch);
}
- return new PatchApplier(db).applyPatch(patchStream);
}
protected static InputStream getTestResource(String patchFile) {
@@ -159,6 +159,7 @@ public class PatchApplierTest {
void verifyChange(Result result, String aName, boolean exists)
throws Exception {
+ assertEquals(0, result.getErrors().size());
assertEquals(1, result.getPaths().size());
verifyContent(result, aName, exists);
}
@@ -181,6 +182,7 @@ public class PatchApplierTest {
protected void checkBinary(Result result, int numberOfFiles)
throws Exception {
+ assertEquals(0, result.getErrors().size());
assertEquals(numberOfFiles, result.getPaths().size());
if (inCore) {
assertArrayEquals(postImage,
@@ -380,6 +382,14 @@ public class PatchApplierTest {
verifyChange(result, "X");
verifyContent(result, "Unaffected", expectedUnaffectedText);
}
+
+ @Test
+ public void testConflictFails() throws Exception {
+ init("conflict");
+
+ Result result = applyPatch();
+ assertEquals(1, result.getErrors().size());
+ }
}
public static class InCore extends Base {