@@ -524,13 +524,15 @@ static class RootContextWithIndexedProperties {
524
524
@ Nested
525
525
class IndexAccessorTests { // gh-26478
526
526
527
+ private final StandardEvaluationContext context = new StandardEvaluationContext ();
528
+ private final SpelExpressionParser parser = new SpelExpressionParser ();
529
+
527
530
@ Test
528
531
void addingAndRemovingIndexAccessors () {
529
532
ObjectMapper objectMapper = new ObjectMapper ();
530
533
IndexAccessor accessor1 = new JacksonArrayNodeIndexAccessor (objectMapper );
531
534
IndexAccessor accessor2 = new JacksonArrayNodeIndexAccessor (objectMapper );
532
535
533
- StandardEvaluationContext context = new StandardEvaluationContext ();
534
536
List <IndexAccessor > indexAccessors = context .getIndexAccessors ();
535
537
assertThat (indexAccessors ).isEmpty ();
536
538
@@ -551,10 +553,8 @@ void addingAndRemovingIndexAccessors() {
551
553
552
554
@ Test
553
555
void noSuitableIndexAccessorResultsInException () {
554
- StandardEvaluationContext context = new StandardEvaluationContext ();
555
556
assertThat (context .getIndexAccessors ()).isEmpty ();
556
557
557
- SpelExpressionParser parser = new SpelExpressionParser ();
558
558
Expression expr = parser .parseExpression ("[0]" );
559
559
assertThatExceptionOfType (SpelEvaluationException .class )
560
560
.isThrownBy (() -> expr .getValue (context , this ))
@@ -564,15 +564,13 @@ void noSuitableIndexAccessorResultsInException() {
564
564
565
565
@ Test
566
566
void canReadThrowsException () throws Exception {
567
- StandardEvaluationContext context = new StandardEvaluationContext ();
568
567
RuntimeException exception = new RuntimeException ("Boom!" );
569
568
570
569
IndexAccessor mock = mock ();
571
570
given (mock .getSpecificTargetClasses ()).willReturn (null );
572
571
given (mock .canRead (any (), eq (this ), any ())).willThrow (exception );
573
572
context .addIndexAccessor (mock );
574
573
575
- SpelExpressionParser parser = new SpelExpressionParser ();
576
574
Expression expr = parser .parseExpression ("[0]" );
577
575
assertThatExceptionOfType (SpelEvaluationException .class )
578
576
.isThrownBy (() -> expr .getValue (context , this ))
@@ -588,7 +586,6 @@ void canReadThrowsException() throws Exception {
588
586
589
587
@ Test
590
588
void readThrowsException () throws Exception {
591
- StandardEvaluationContext context = new StandardEvaluationContext ();
592
589
RuntimeException exception = new RuntimeException ("Boom!" );
593
590
594
591
IndexAccessor mock = mock ();
@@ -597,7 +594,6 @@ void readThrowsException() throws Exception {
597
594
given (mock .read (any (), eq (this ), any ())).willThrow (exception );
598
595
context .addIndexAccessor (mock );
599
596
600
- SpelExpressionParser parser = new SpelExpressionParser ();
601
597
Expression expr = parser .parseExpression ("[0]" );
602
598
assertThatExceptionOfType (SpelEvaluationException .class )
603
599
.isThrownBy (() -> expr .getValue (context , this ))
@@ -614,15 +610,13 @@ void readThrowsException() throws Exception {
614
610
615
611
@ Test
616
612
void canWriteThrowsException () throws Exception {
617
- StandardEvaluationContext context = new StandardEvaluationContext ();
618
613
RuntimeException exception = new RuntimeException ("Boom!" );
619
614
620
615
IndexAccessor mock = mock ();
621
616
given (mock .getSpecificTargetClasses ()).willReturn (null );
622
617
given (mock .canWrite (eq (context ), eq (this ), eq (0 ))).willThrow (exception );
623
618
context .addIndexAccessor (mock );
624
619
625
- SpelExpressionParser parser = new SpelExpressionParser ();
626
620
Expression expr = parser .parseExpression ("[0]" );
627
621
assertThatExceptionOfType (SpelEvaluationException .class )
628
622
.isThrownBy (() -> expr .setValue (context , this , 999 ))
@@ -638,7 +632,6 @@ void canWriteThrowsException() throws Exception {
638
632
639
633
@ Test
640
634
void writeThrowsException () throws Exception {
641
- StandardEvaluationContext context = new StandardEvaluationContext ();
642
635
RuntimeException exception = new RuntimeException ("Boom!" );
643
636
644
637
IndexAccessor mock = mock ();
@@ -647,7 +640,6 @@ void writeThrowsException() throws Exception {
647
640
doThrow (exception ).when (mock ).write (any (), any (), any (), any ());
648
641
context .addIndexAccessor (mock );
649
642
650
- SpelExpressionParser parser = new SpelExpressionParser ();
651
643
Expression expr = parser .parseExpression ("[0]" );
652
644
assertThatExceptionOfType (SpelEvaluationException .class )
653
645
.isThrownBy (() -> expr .setValue (context , this , 999 ))
@@ -664,8 +656,6 @@ void writeThrowsException() throws Exception {
664
656
665
657
@ Test
666
658
void readAndWriteIndex () {
667
- StandardEvaluationContext context = new StandardEvaluationContext ();
668
-
669
659
ObjectMapper objectMapper = new ObjectMapper ();
670
660
context .addIndexAccessor (new JacksonArrayNodeIndexAccessor (objectMapper ));
671
661
@@ -674,7 +664,6 @@ void readAndWriteIndex() {
674
664
ArrayNode arrayNode = objectMapper .createArrayNode ();
675
665
arrayNode .addAll (List .of (node0 , node1 ));
676
666
677
- SpelExpressionParser parser = new SpelExpressionParser ();
678
667
Expression expr = parser .parseExpression ("[0]" );
679
668
assertThat (expr .getValue (context , arrayNode )).isSameAs (node0 );
680
669
@@ -703,7 +692,6 @@ void readAndWriteIndexWithSimpleEvaluationContext() {
703
692
SimpleEvaluationContext context = SimpleEvaluationContext .forReadWriteDataBinding ()
704
693
.withIndexAccessors (new JacksonArrayNodeIndexAccessor (objectMapper ))
705
694
.build ();
706
- SpelExpressionParser parser = new SpelExpressionParser ();
707
695
708
696
TextNode node0 = new TextNode ("node0" );
709
697
TextNode node1 = new TextNode ("node1" );
0 commit comments