24
24
import org .junit .jupiter .api .Test ;
25
25
import org .junit .jupiter .api .extension .ExtendWith ;
26
26
import org .mockito .Mock ;
27
+ import org .mockito .Mockito ;
27
28
import org .mockito .junit .jupiter .MockitoExtension ;
28
29
29
30
import java .io .FileNotFoundException ;
@@ -390,14 +391,19 @@ public void shouldIncludeLocationAndTextInExecutionException() {
390
391
);
391
392
}
392
393
393
- private void assertStrictness (final Metafix .Strictness strictness , final String fixDef , final Consumer <Supplier <StreamReceiver >> out ) {
394
+ private void assertStrictness (final Metafix .Strictness strictness , final String fixDef , final boolean stubLogging , final Consumer <Supplier <StreamReceiver >> out ) {
394
395
MetafixTestHelpers .assertFix (streamReceiver , Arrays .asList (
395
396
"add_field('before', '')" ,
396
397
fixDef ,
397
398
"add_field('after', '')"
398
399
),
399
400
i -> {
400
- i .setStrictness (strictness );
401
+ final Metafix .Strictness strictnessSpy = Mockito .spy (strictness );
402
+ i .setStrictness (strictnessSpy );
403
+
404
+ if (stubLogging ) {
405
+ Mockito .doNothing ().when (strictnessSpy ).log (Mockito .any (), Mockito .any ());
406
+ }
401
407
402
408
i .startRecord ("1" );
403
409
i .literal ("data" , "foo" );
@@ -418,13 +424,13 @@ private void assertStrictness(final Metafix.Strictness strictness, final String
418
424
// TODO: Test logging statements
419
425
}
420
426
421
- private void assertStrictness (final Metafix .Strictness strictness , final Consumer <Supplier <StreamReceiver >> out ) {
422
- assertStrictness (strictness , "upcase('data')" , out );
427
+ private void assertStrictness (final Metafix .Strictness strictness , final boolean stubLogging , final Consumer <Supplier <StreamReceiver >> out ) {
428
+ assertStrictness (strictness , "upcase('data')" , stubLogging , out );
423
429
}
424
430
425
431
@ Test
426
432
public void shouldSkipExpressionOnExecutionException () {
427
- assertStrictness (Metafix .Strictness .EXPRESSION , o -> {
433
+ assertStrictness (Metafix .Strictness .EXPRESSION , true , o -> {
428
434
o .get ().startRecord ("1" );
429
435
o .get ().literal ("before" , "" );
430
436
o .get ().literal ("data" , "FOO" );
@@ -446,7 +452,7 @@ public void shouldSkipExpressionOnExecutionException() {
446
452
447
453
@ Test
448
454
public void shouldSkipRecordOnExecutionException () {
449
- assertStrictness (Metafix .Strictness .RECORD , o -> {
455
+ assertStrictness (Metafix .Strictness .RECORD , true , o -> {
450
456
o .get ().startRecord ("1" );
451
457
o .get ().literal ("before" , "" );
452
458
o .get ().literal ("data" , "FOO" );
@@ -464,15 +470,15 @@ public void shouldSkipRecordOnExecutionException() {
464
470
@ Test
465
471
public void shouldAbortProcessOnExecutionException () {
466
472
MetafixTestHelpers .assertExecutionException (IllegalStateException .class , "Expected String, got Array" , () ->
467
- assertStrictness (Metafix .Strictness .PROCESS , o -> {
473
+ assertStrictness (Metafix .Strictness .PROCESS , false , o -> {
468
474
})
469
475
);
470
476
}
471
477
472
478
@ Test
473
479
public void shouldAbortProcessOnProcessException () {
474
480
MetafixTestHelpers .assertProcessException (IllegalArgumentException .class , "No enum constant org.metafacture.metafix.FixMethod.foo" , () ->
475
- assertStrictness (Metafix .Strictness .EXPRESSION , "foo()" , o -> {
481
+ assertStrictness (Metafix .Strictness .EXPRESSION , "foo()" , false , o -> {
476
482
})
477
483
);
478
484
}
0 commit comments