1
+ package org .ndviet .library .math ;
2
+
3
+ import org .junit .jupiter .params .ParameterizedTest ;
4
+ import org .junit .jupiter .params .provider .Arguments ;
5
+ import org .junit .jupiter .params .provider .CsvSource ;
6
+ import org .junit .jupiter .params .provider .MethodSource ;
7
+ import org .mockito .MockedStatic ;
8
+ import org .mockito .Mockito ;
9
+ import org .ndviet .library .configuration .ConfigurationHelpers ;
10
+
11
+ import java .util .Locale ;
12
+ import java .util .stream .Stream ;
13
+
14
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
15
+
16
+ public class MathHelpersTest {
17
+
18
+ @ ParameterizedTest
19
+ @ MethodSource ("provideParametersForNumberDecimalFormat" )
20
+ public void numberDecimalFormat (String input , String decimal , String roundingMode , String expected ) {
21
+ String result = MathHelpers .numberDecimalFormat (input , decimal , roundingMode );
22
+ assertEquals (expected , result );
23
+ }
24
+
25
+ private static Stream <Arguments > provideParametersForNumberDecimalFormat () {
26
+ return Stream .of (
27
+ Arguments .of ("1234.5678" , "#.##" , "HALF_UP" , "1234.57" ),
28
+ Arguments .of ("invalid" , "#.##" , "HALF_UP" , "invalid" ),
29
+ Arguments .of ("1234.5678" , "#.##" , null , "1234.57" ),
30
+ Arguments .of ("1234.5678" , null , "HALF_UP" , "1234.5678" )
31
+ );
32
+ }
33
+
34
+ @ ParameterizedTest
35
+ @ CsvSource ({
36
+ "1234.5678, true" ,
37
+ "0, true" ,
38
+ "-1234, true" ,
39
+ "1.23E3, true" ,
40
+ "invalid, false" ,
41
+ ", false"
42
+ })
43
+ public void isCreatable (String input , boolean expected ) {
44
+ assertEquals (expected , MathHelpers .isCreatable (input ));
45
+ }
46
+
47
+ @ ParameterizedTest
48
+ @ CsvSource ({
49
+ "'1234,5678', true" ,
50
+ "'-0,75', true" ,
51
+ })
52
+ public void isCreatable_different_locate (String input , boolean expected ) {
53
+ try (MockedStatic <ConfigurationHelpers > mockHelpers = Mockito .mockStatic (ConfigurationHelpers .class )) {
54
+ mockHelpers .when (ConfigurationHelpers ::getSystemLocale ).thenReturn (Locale .FRANCE );
55
+ assertEquals (expected , MathHelpers .isCreatable (input ));
56
+ }
57
+ }
58
+ }
0 commit comments