Skip to content

Commit b63e8a7

Browse files
committed
Add unit test for strictnessHandlesProcessExceptions. (#253)
1 parent 55d14c7 commit b63e8a7

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

metafix/src/test/java/org/metafacture/metafix/MetafixScriptTest.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,17 @@ public void shouldIncludeLocationAndTextInExecutionException() {
435435
);
436436
}
437437

438-
private void assertStrictness(final Metafix.Strictness strictness, final String fixDef, final boolean stubLogging, final Consumer<Supplier<StreamReceiver>> out) {
438+
private void assertStrictness(final Metafix.Strictness strictness, final String fixDef, final boolean stubLogging, final Consumer<Metafix> in, final Consumer<Supplier<StreamReceiver>> out) {
439439
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
440440
"add_field('before', '')",
441441
fixDef,
442442
"add_field('after', '')"
443443
),
444444
i -> {
445+
if (in != null) {
446+
in.accept(i);
447+
}
448+
445449
final Metafix.Strictness strictnessSpy = Mockito.spy(strictness);
446450
i.setStrictness(strictnessSpy);
447451

@@ -469,7 +473,7 @@ private void assertStrictness(final Metafix.Strictness strictness, final String
469473
}
470474

471475
private void assertStrictness(final Metafix.Strictness strictness, final boolean stubLogging, final Consumer<Supplier<StreamReceiver>> out) {
472-
assertStrictness(strictness, "upcase('data')", stubLogging, out);
476+
assertStrictness(strictness, "upcase('data')", stubLogging, null, out);
473477
}
474478

475479
@Test
@@ -524,11 +528,35 @@ public void shouldAbortProcessOnExecutionException() {
524528
@Test
525529
public void shouldAbortProcessOnProcessException() {
526530
MetafixTestHelpers.assertProcessException(IllegalArgumentException.class, "No enum constant org.metafacture.metafix.FixMethod.foo", () ->
527-
assertStrictness(Metafix.Strictness.EXPRESSION, "foo()", false, o -> {
531+
assertStrictness(Metafix.Strictness.EXPRESSION, "foo()", false, null, o -> {
528532
})
529533
);
530534
}
531535

536+
@Test
537+
public void shouldOptionallySkipExpressionOnProcessException() {
538+
assertStrictness(Metafix.Strictness.EXPRESSION, "upcase()", true, i -> i.setStrictnessHandlesProcessExceptions(true), o -> {
539+
o.get().startRecord("1");
540+
o.get().literal("data", "foo");
541+
o.get().literal("before", "");
542+
o.get().literal("after", "");
543+
o.get().endRecord();
544+
545+
o.get().startRecord("2");
546+
o.get().literal("data", "foo");
547+
o.get().literal("data", "bar");
548+
o.get().literal("before", "");
549+
o.get().literal("after", "");
550+
o.get().endRecord();
551+
552+
o.get().startRecord("3");
553+
o.get().literal("data", "bar");
554+
o.get().literal("before", "");
555+
o.get().literal("after", "");
556+
o.get().endRecord();
557+
});
558+
}
559+
532560
private void assertVar(final String fixDef, final Map<String, String> vars, final Map<String, String> result) {
533561
assertFix(fixDef, vars, f -> result.forEach((k, v) -> Assertions.assertEquals(v, f.getVars().get(k))));
534562
}

0 commit comments

Comments
 (0)