16
16
17
17
package com .mongodb .client .model .expressions ;
18
18
19
+ import org .bson .types .Decimal128 ;
19
20
import org .junit .jupiter .api .Test ;
20
21
22
+ import java .math .BigDecimal ;
23
+
21
24
import static com .mongodb .client .model .expressions .Expressions .of ;
22
25
import static org .junit .jupiter .api .Assertions .assertEquals ;
23
26
import static org .junit .jupiter .api .Assertions .assertNotEquals ;
27
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
24
28
29
+ @ SuppressWarnings ("ConstantConditions" )
25
30
class ArithmeticExpressionsFunctionalTest extends AbstractExpressionsFunctionalTest {
26
31
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/#arithmetic-expression-operators
27
32
@@ -30,13 +35,15 @@ public void literalsTest() {
30
35
assertExpression (1 , of (1 ), "1" );
31
36
assertExpression (1L , of (1L ));
32
37
assertExpression (1.0 , of (1.0 ));
38
+ assertExpression (BigDecimal .valueOf (1.0 ), of (BigDecimal .valueOf (1.0 )));
39
+ assertThrows (IllegalArgumentException .class , () -> of ((BigDecimal ) null ));
33
40
34
41
// expression equality differs from bson equality
35
42
assertExpression (true , of (1L ).eq (of (1.0 )));
36
43
assertExpression (true , of (1L ).eq (of (1 )));
37
44
38
45
// bson equality; underlying type is preserved
39
- // this is not defined by the API, but tested for clarity
46
+ // this behaviour is not defined by the API, but tested for clarity
40
47
assertEquals (toBsonValue (1 ), evaluate (of (1 )));
41
48
assertEquals (toBsonValue (1L ), evaluate (of (1L )));
42
49
assertEquals (toBsonValue (1.0 ), evaluate (of (1.0 )));
@@ -89,8 +96,6 @@ public void divideTest() {
89
96
// convenience
90
97
assertExpression (0.5 , of (1.0 ).divide (2.0 ));
91
98
assertExpression (0.5 , of (1 ).divide (2.0 ));
92
- // TODO these convenience methods are all for doubles, so while they
93
- // TODO allow longs and ints, they do not carry that through to the server:
94
99
assertExpression (0.5 , of (1 ).divide (2L ));
95
100
assertExpression (0.5 , of (1 ).divide (2 ));
96
101
}
0 commit comments