23
23
import org .junit .jupiter .api .BeforeEach ;
24
24
import org .junit .jupiter .api .Disabled ;
25
25
import org .junit .jupiter .api .Test ;
26
+
26
27
import org .springframework .data .mongodb .core .Person ;
27
- import org .springframework .lang .Nullable ;
28
28
29
29
/**
30
30
* Unit tests for {@link SpelExpressionTransformer}.
@@ -152,8 +152,8 @@ void shouldRenderBinaryExpressionWithMixedSignsCorrectly() {
152
152
@ Test // DATAMONGO-774
153
153
void shouldRenderConsecutiveOperationsInComplexExpression () {
154
154
155
- assertThat (transform ("1 + 1 + (1 + 1 + 1) / q" )). isEqualTo (
156
- Document .parse ("{ \" $add\" : [ 1 , 1 , { \" $divide\" : [ { \" $add\" : [ 1 , 1 , 1]} , \" $q\" ]}]}" ));
155
+ assertThat (transform ("1 + 1 + (1 + 1 + 1) / q" ))
156
+ . isEqualTo ( Document .parse ("{ \" $add\" : [ 1 , 1 , { \" $divide\" : [ { \" $add\" : [ 1 , 1 , 1]} , \" $q\" ]}]}" ));
157
157
}
158
158
159
159
@ Test // DATAMONGO-774
@@ -189,8 +189,7 @@ void shouldRenderCompoundExpressionsWithIndexerAndFieldReference() {
189
189
190
190
Person person = new Person ();
191
191
person .setAge (10 );
192
- assertThat (transform ("[0].age + a.c" , person ))
193
- .isEqualTo (Document .parse ("{ \" $add\" : [ 10 , \" $a.c\" ] }" ));
192
+ assertThat (transform ("[0].age + a.c" , person )).isEqualTo (Document .parse ("{ \" $add\" : [ 10 , \" $a.c\" ] }" ));
194
193
}
195
194
196
195
@ Test // DATAMONGO-840
@@ -216,8 +215,7 @@ void shouldRenderMethodReferenceNodeNot() {
216
215
217
216
@ Test // DATAMONGO-1530
218
217
void shouldRenderMethodReferenceNodeSetEquals () {
219
- assertThat (transform ("setEquals(a, b)" ))
220
- .isEqualTo (Document .parse ("{ \" $setEquals\" : [ \" $a\" , \" $b\" ]}" ));
218
+ assertThat (transform ("setEquals(a, b)" )).isEqualTo (Document .parse ("{ \" $setEquals\" : [ \" $a\" , \" $b\" ]}" ));
221
219
}
222
220
223
221
@ Test // DATAMONGO-1530
@@ -379,8 +377,7 @@ void shouldRenderMethodReferenceTrunc() {
379
377
380
378
@ Test // DATAMONGO-1530
381
379
void shouldRenderMethodReferenceNodeConcat () {
382
- assertThat (transform ("concat(a, b, 'c')" ))
383
- .isEqualTo (Document .parse ("{ \" $concat\" : [ \" $a\" , \" $b\" , \" c\" ]}" ));
380
+ assertThat (transform ("concat(a, b, 'c')" )).isEqualTo (Document .parse ("{ \" $concat\" : [ \" $a\" , \" $b\" , \" c\" ]}" ));
384
381
}
385
382
386
383
@ Test // DATAMONGO-1530
@@ -400,8 +397,7 @@ void shouldRenderMethodReferenceToUpper() {
400
397
401
398
@ Test // DATAMONGO-1530
402
399
void shouldRenderMethodReferenceNodeStrCaseCmp () {
403
- assertThat (transform ("strcasecmp(a, b)" ))
404
- .isEqualTo (Document .parse ("{ \" $strcasecmp\" : [ \" $a\" , \" $b\" ]}" ));
400
+ assertThat (transform ("strcasecmp(a, b)" )).isEqualTo (Document .parse ("{ \" $strcasecmp\" : [ \" $a\" , \" $b\" ]}" ));
405
401
}
406
402
407
403
@ Test // DATAMONGO-1530
@@ -411,8 +407,7 @@ void shouldRenderMethodReferenceMeta() {
411
407
412
408
@ Test // DATAMONGO-1530
413
409
void shouldRenderMethodReferenceNodeArrayElemAt () {
414
- assertThat (transform ("arrayElemAt(a, 10)" ))
415
- .isEqualTo (Document .parse ("{ \" $arrayElemAt\" : [ \" $a\" , 10]}" ));
410
+ assertThat (transform ("arrayElemAt(a, 10)" )).isEqualTo (Document .parse ("{ \" $arrayElemAt\" : [ \" $a\" , 10]}" ));
416
411
}
417
412
418
413
@ Test // DATAMONGO-1530
@@ -511,15 +506,14 @@ void shouldRenderMethodReferenceMillisecond() {
511
506
512
507
@ Test // DATAMONGO-1530
513
508
void shouldRenderMethodReferenceDateToString () {
514
- assertThat (transform ("dateToString('%Y-%m-%d', $date)" )). isEqualTo (
515
- Document .parse ("{ \" $dateToString\" : { \" format\" : \" %Y-%m-%d\" , \" date\" : \" $date\" }}" ));
509
+ assertThat (transform ("dateToString('%Y-%m-%d', $date)" ))
510
+ . isEqualTo ( Document .parse ("{ \" $dateToString\" : { \" format\" : \" %Y-%m-%d\" , \" date\" : \" $date\" }}" ));
516
511
}
517
512
518
513
@ Test // DATAMONGO-1530
519
514
void shouldRenderMethodReferenceCond () {
520
515
assertThat (transform ("cond(qty > 250, 30, 20)" )).isEqualTo (
521
- Document
522
- .parse ("{ \" $cond\" : { \" if\" : { \" $gt\" : [ \" $qty\" , 250]} , \" then\" : 30 , \" else\" : 20}}" ));
516
+ Document .parse ("{ \" $cond\" : { \" if\" : { \" $gt\" : [ \" $qty\" , 250]} , \" then\" : 30 , \" else\" : 20}}" ));
523
517
}
524
518
525
519
@ Test // DATAMONGO-1530
@@ -633,8 +627,7 @@ void shouldRenderOperationNodeAnd() {
633
627
@ Test // DATAMONGO-1530
634
628
void shouldRenderComplexOperationNodeAnd () {
635
629
assertThat (transform ("1+2 && concat(a, b) && true" )).isEqualTo (
636
- Document
637
- .parse ("{ \" $and\" : [ { \" $add\" : [ 1 , 2]} , { \" $concat\" : [ \" $a\" , \" $b\" ]} , true]}" ));
630
+ Document .parse ("{ \" $and\" : [ { \" $add\" : [ 1 , 2]} , { \" $concat\" : [ \" $a\" , \" $b\" ]} , true]}" ));
638
631
}
639
632
640
633
@ Test // DATAMONGO-1530
@@ -644,8 +637,7 @@ void shouldRenderNotCorrectly() {
644
637
645
638
@ Test // DATAMONGO-1530
646
639
void shouldRenderComplexNotCorrectly () {
647
- assertThat (transform ("!(foo > 10)" ))
648
- .isEqualTo (Document .parse ("{ \" $not\" : [ { \" $gt\" : [ \" $foo\" , 10]}]}" ));
640
+ assertThat (transform ("!(foo > 10)" )).isEqualTo (Document .parse ("{ \" $not\" : [ { \" $gt\" : [ \" $foo\" , 10]}]}" ));
649
641
}
650
642
651
643
@ Test // DATAMONGO-1548
@@ -951,12 +943,14 @@ void shouldRenderRoundWithPlace() {
951
943
952
944
@ Test // GH-3712
953
945
void shouldRenderCovariancePop () {
954
- assertThat (transform ("covariancePop(field1, field2)" )).isEqualTo (Document .parse ("{ \" $covariancePop\" : [\" $field1\" , \" $field2\" ]}" ));
946
+ assertThat (transform ("covariancePop(field1, field2)" ))
947
+ .isEqualTo (Document .parse ("{ \" $covariancePop\" : [\" $field1\" , \" $field2\" ]}" ));
955
948
}
956
949
957
950
@ Test // GH-3712
958
951
void shouldRenderCovarianceSamp () {
959
- assertThat (transform ("covarianceSamp(field1, field2)" )).isEqualTo (Document .parse ("{ \" $covarianceSamp\" : [\" $field1\" , \" $field2\" ]}" ));
952
+ assertThat (transform ("covarianceSamp(field1, field2)" ))
953
+ .isEqualTo (Document .parse ("{ \" $covarianceSamp\" : [\" $field1\" , \" $field2\" ]}" ));
960
954
}
961
955
962
956
@ Test // GH-3715
@@ -988,20 +982,21 @@ void rendersShiftWithDefault() {
988
982
.isEqualTo (Document .parse ("{ $shift: { output: \" $quantity\" , by: 1, default: \" Not available\" } }" ));
989
983
}
990
984
991
- @ Nullable
992
985
@ Test // GH-3716
993
986
void shouldRenderDerivative () {
994
- assertThat (transform ("derivative(miles, 'hour')" )).isEqualTo (Document .parse ("{ \" $derivative\" : { input : '$miles', unit : 'hour'} }" ));
987
+ assertThat (transform ("derivative(miles, 'hour')" ))
988
+ .isEqualTo (Document .parse ("{ \" $derivative\" : { input : '$miles', unit : 'hour'} }" ));
995
989
}
996
990
997
991
@ Test // GH-3721
998
- public void shouldRenderIntegral () {
992
+ void shouldRenderIntegral () {
999
993
assertThat (transform ("integral(field)" )).isEqualTo (Document .parse ("{ \" $integral\" : { \" input\" : \" $field\" }}" ));
1000
994
}
1001
995
1002
996
@ Test // GH-3721
1003
- public void shouldIntegralWithUnit () {
1004
- assertThat (transform ("integral(field, 'hour')" )).isEqualTo (Document .parse ("{ \" $integral\" : { \" input\" : \" $field\" , \" unit\" : \" hour\" }}" ));
997
+ void shouldRenderIntegralWithUnit () {
998
+ assertThat (transform ("integral(field, 'hour')" ))
999
+ .isEqualTo (Document .parse ("{ \" $integral\" : { \" input\" : \" $field\" , \" unit\" : \" hour\" }}" ));
1005
1000
}
1006
1001
1007
1002
private Object transform (String expression , Object ... params ) {
0 commit comments