@@ -500,7 +500,7 @@ public void optionalAndRequiredWithAnnotatedMethod() throws Exception {
500
500
Method method = service .getClass ().getMethod ("optionalAndRequiredHeader" , String .class , Integer .class );
501
501
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor (service , method );
502
502
processor .setUseSpelInvoker (true );
503
- optionalAndRequiredWithAnnotatedMethodGuts (processor , false );
503
+ optionalAndRequiredWithAnnotatedMethodGuts (processor );
504
504
}
505
505
506
506
@ Test
@@ -510,14 +510,13 @@ public void compiledOptionalAndRequiredWithAnnotatedMethod() throws Exception {
510
510
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor (service , method );
511
511
processor .setUseSpelInvoker (true );
512
512
DirectFieldAccessor compilerConfigAccessor = compileImmediate (processor );
513
- optionalAndRequiredWithAnnotatedMethodGuts (processor , true );
513
+ optionalAndRequiredWithAnnotatedMethodGuts (processor );
514
514
assertThat (TestUtils .getPropertyValue (processor , "delegate.handlerMethod.expression.compiledAst" )).isNotNull ();
515
- optionalAndRequiredWithAnnotatedMethodGuts (processor , true );
515
+ optionalAndRequiredWithAnnotatedMethodGuts (processor );
516
516
compilerConfigAccessor .setPropertyValue ("compilerMode" , SpelCompilerMode .OFF );
517
517
}
518
518
519
- private void optionalAndRequiredWithAnnotatedMethodGuts (MethodInvokingMessageProcessor processor ,
520
- boolean compiled ) {
519
+ private void optionalAndRequiredWithAnnotatedMethodGuts (MethodInvokingMessageProcessor processor ) {
521
520
522
521
processor .setBeanFactory (mock (BeanFactory .class ));
523
522
Message <String > message = MessageBuilder .withPayload ("foo" )
@@ -531,21 +530,14 @@ private void optionalAndRequiredWithAnnotatedMethodGuts(MethodInvokingMessagePro
531
530
.build ();
532
531
result = processor .processMessage (message );
533
532
assertThat (result ).isEqualTo ("bar42" );
534
- message = MessageBuilder .withPayload ("foo" )
535
- .setHeader ("prop" , "bar" )
536
- .build ();
537
- try {
538
- result = processor .processMessage (message );
539
- fail ("Expected MessageHandlingException" );
540
- }
541
- catch (MessageHandlingException e ) {
542
- if (compiled ) {
543
- assertThat (e .getCause ().getMessage ()).isEqualTo ("required header not available: num" );
544
- }
545
- else {
546
- assertThat (e .getCause ().getCause ().getMessage ()).isEqualTo ("required header not available: num" );
547
- }
548
- }
533
+
534
+ assertThatExceptionOfType (MessageHandlingException .class )
535
+ .isThrownBy (() ->
536
+ processor .processMessage (
537
+ MessageBuilder .withPayload ("foo" )
538
+ .setHeader ("prop" , "bar" )
539
+ .build ()))
540
+ .withStackTraceContaining ("required header not available: num" );
549
541
}
550
542
551
543
@ Test
@@ -555,7 +547,7 @@ public void optionalAndRequiredDottedWithAnnotatedMethod() throws Exception {
555
547
String .class );
556
548
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor (service , method );
557
549
processor .setUseSpelInvoker (true );
558
- optionalAndRequiredDottedWithAnnotatedMethodGuts (processor , false );
550
+ optionalAndRequiredDottedWithAnnotatedMethodGuts (processor );
559
551
}
560
552
561
553
@ Test
@@ -566,14 +558,13 @@ public void compiledOptionalAndRequiredDottedWithAnnotatedMethod() throws Except
566
558
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor (service , method );
567
559
processor .setUseSpelInvoker (true );
568
560
DirectFieldAccessor compilerConfigAccessor = compileImmediate (processor );
569
- optionalAndRequiredDottedWithAnnotatedMethodGuts (processor , true );
561
+ optionalAndRequiredDottedWithAnnotatedMethodGuts (processor );
570
562
assertThat (TestUtils .getPropertyValue (processor , "delegate.handlerMethod.expression.compiledAst" )).isNotNull ();
571
- optionalAndRequiredDottedWithAnnotatedMethodGuts (processor , true );
563
+ optionalAndRequiredDottedWithAnnotatedMethodGuts (processor );
572
564
compilerConfigAccessor .setPropertyValue ("compilerMode" , SpelCompilerMode .OFF );
573
565
}
574
566
575
- private void optionalAndRequiredDottedWithAnnotatedMethodGuts (MethodInvokingMessageProcessor processor ,
576
- boolean compiled ) {
567
+ private void optionalAndRequiredDottedWithAnnotatedMethodGuts (MethodInvokingMessageProcessor processor ) {
577
568
578
569
processor .setBeanFactory (mock (BeanFactory .class ));
579
570
Message <String > message = MessageBuilder .withPayload ("hello" )
@@ -589,22 +580,15 @@ private void optionalAndRequiredDottedWithAnnotatedMethodGuts(MethodInvokingMess
589
580
.build ();
590
581
result = processor .processMessage (message );
591
582
assertThat (result ).isEqualTo ("bar42dotted" );
592
- message = MessageBuilder .withPayload ("hello" )
593
- .setHeader ("dot1" , new DotBean ())
594
- .setHeader ("dotted.literal" , "dotted" )
595
- .build ();
596
- try {
597
- result = processor .processMessage (message );
598
- fail ("Expected MessageHandlingException" );
599
- }
600
- catch (MessageHandlingException e ) {
601
- if (compiled ) {
602
- assertThat (e .getCause ().getMessage ()).isEqualTo ("required header not available: dot2" );
603
- }
604
- else { // interpreted
605
- assertThat (e .getCause ().getCause ().getMessage ()).isEqualTo ("required header not available: dot2" );
606
- }
607
- }
583
+
584
+ assertThatExceptionOfType (MessageHandlingException .class )
585
+ .isThrownBy (() ->
586
+ processor .processMessage (
587
+ MessageBuilder .withPayload ("hello" )
588
+ .setHeader ("dot1" , new DotBean ())
589
+ .setHeader ("dotted.literal" , "dotted" )
590
+ .build ()))
591
+ .withStackTraceContaining ("required header not available: dot2" );
608
592
}
609
593
610
594
@ Test
0 commit comments