33import com .binance .connector .futures .client .utils .UrlBuilder ;
44import java .util .ArrayList ;
55import java .util .LinkedHashMap ;
6+ import java .util .Locale ;
67import static org .junit .Assert .assertEquals ;
78import org .junit .Test ;
89
910public class TestUrlBuilder {
1011 private final String baseUrl = "www.test.com" ;
1112 private final String urlPath = "/url/path" ;
12- private final double key3 = 0.0006 ;
13- private final double key4 = 0.000000000000000000001 ;
14- private final int value2 = 2 ;
13+ private final double doubleValue = 0.0006 ;
14+ private final double extensiveDecimalsDouble = 1.123456789101112 ;
15+ private final double highDouble = 10000.1 ;
16+ private final int intValue = 2 ;
1517 private final LinkedHashMap <String , Object > mockParameters = new LinkedHashMap <String , Object >() {{
1618 put ("key1" , "value1" );
17- put ("key2" , value2 );
18- put ("key3" , key3 );
19+ put ("key2" , intValue );
20+ put ("key3" , doubleValue );
1921 }};
20- private final ArrayList <String > mockStreams = new ArrayList <String >() {{
22+ private final LinkedHashMap <String , Object > mockDoubleParameters = new LinkedHashMap <String , Object >() {{
23+ put ("key1" , extensiveDecimalsDouble );
24+ put ("key2" , highDouble );
25+
26+ }};
27+ private final ArrayList <String > mockStreams = new ArrayList <String >() {{
2128 add ("stream1" );
2229 add ("stream2" );
2330 add ("stream3" );
@@ -43,8 +50,9 @@ public void testJoinQueryParameters() {
4350
4451 @ Test
4552 public void testJoinLargeQueryParameters () {
46- mockParameters .put ("key4" , key4 );
47- String joinedQuery = "key1=value1&key2=2&key3=0.0006&key4=0.000000000000000000001" ;
53+ mockParameters .put ("key4" , extensiveDecimalsDouble );
54+ mockParameters .put ("key5" , highDouble );
55+ String joinedQuery = "key1=value1&key2=2&key3=0.0006&key4=1.123456789101112&key5=10000.1" ;
4856 assertEquals (joinedQuery , UrlBuilder .joinQueryParameters (mockParameters ));
4957 }
5058
@@ -53,6 +61,20 @@ public void testJoinQueryParametersWithoutParams() {
5361 assertEquals ("" , UrlBuilder .joinQueryParameters (null ));
5462 }
5563
64+ /**
65+ * Tests the JoinQueryParameters with Locale.IT to ensure that the originated Double maintains the '.' decimal separator instead of being changed to a ','.
66+ * Additionally, the test verifies that there is no dropping of zeros, addition of group separators (','), and limitation on the number of decimal places.
67+ */
68+ @ Test
69+ public void testJoinQueryParametersWithLocaleIT () {
70+
71+ Locale .setDefault (new Locale ("it" , "IT" ));
72+
73+ String joinedQuery = String .format ("key1=%s&key2=%s" , extensiveDecimalsDouble , highDouble );
74+ String buildQuery = UrlBuilder .joinQueryParameters (mockDoubleParameters );
75+ assertEquals (joinedQuery , buildQuery );
76+ }
77+
5678 @ Test
5779 public void testBuildStreamUrl () {
5880 String streamUrl = "www.test.com?streams=stream1/stream2/stream3" ;
0 commit comments