1+ package io .swagger .v3 .oas .models .media ;
2+
3+ import org .testng .annotations .Test ;
4+
5+ import java .util .Locale ;
6+
7+ import static org .testng .Assert .*;
8+
9+ public class IntegerSchemaTest {
10+
11+ private static final IntegerSchema INTEGER_SCHEMA = new IntegerSchema ();
12+ private static final Locale SWEDISH_LOCALE = new Locale ("se" );
13+ private static final String INTEGER_STRING = "123" ;
14+ private static final String LONG_STRING = "1111111111111111111" ;
15+ private static final String NEGATIVE_INTEGER = "-123" ;
16+ private static final String INTEGER_WITH_SPACE_THOUSAND_SEPARATOR = "2 000" ;
17+ private static final String INTEGER_WITH_DECIMAL_THOUSAND_SEPARATOR = "2.000" ;
18+ private static final String INTEGER_WITH_COMMA_THOUSAND_SEPARATOR = "2,000" ;
19+ private static final Integer NUMBER = 123 ;
20+ private static final Integer NEGATIVE_NUMBER = -123 ;
21+ private static final Long LONG = 1111111111111111111L ;
22+
23+ @ Test
24+ public void testCastInteger () {
25+ assertEquals (INTEGER_SCHEMA .cast (INTEGER_STRING ), NUMBER );
26+ }
27+
28+ @ Test
29+ public void testCastLong () {
30+ assertEquals (INTEGER_SCHEMA .cast (LONG_STRING ), LONG );
31+ }
32+
33+ @ Test
34+ public void testCastNegativeInteger () {
35+ assertEquals (INTEGER_SCHEMA .cast (NEGATIVE_INTEGER ), NEGATIVE_NUMBER );
36+ }
37+
38+ @ Test
39+ public void testCastIntegerWithSpaceThousandSeparatorFailsWithNull () {
40+ assertNull (INTEGER_SCHEMA .cast (INTEGER_WITH_SPACE_THOUSAND_SEPARATOR ));
41+ }
42+
43+ @ Test
44+ public void testCastIntegerWithDecimalThousandSeparatorFailsWithNull () {
45+ assertNull (INTEGER_SCHEMA .cast (INTEGER_WITH_DECIMAL_THOUSAND_SEPARATOR ));
46+ }
47+
48+ @ Test
49+ public void testCastIntegerWithCommaThousandSeparatorFailsWithNull () {
50+ assertNull (INTEGER_SCHEMA .cast (INTEGER_WITH_COMMA_THOUSAND_SEPARATOR ));
51+ }
52+
53+ @ Test
54+ public void testCastIntegerWithSwedishLocale () {
55+ Locale defaultLocale = Locale .getDefault ();
56+ try {
57+ Locale .setDefault (SWEDISH_LOCALE );
58+ assertEquals (new IntegerSchema ().cast (INTEGER_STRING ), NUMBER );
59+ } finally {
60+ Locale .setDefault (defaultLocale );
61+ }
62+ }
63+
64+ @ Test
65+ public void testCastLongWithSwedishLocale () {
66+ Locale defaultLocale = Locale .getDefault ();
67+ try {
68+ Locale .setDefault (SWEDISH_LOCALE );
69+ assertEquals (new IntegerSchema ().cast (LONG_STRING ), LONG );
70+ } finally {
71+ Locale .setDefault (defaultLocale );
72+ }
73+ }
74+
75+ @ Test
76+ public void testCastNegativeIntegerWithSwedishLocale () {
77+ Locale defaultLocale = Locale .getDefault ();
78+ try {
79+ Locale .setDefault (SWEDISH_LOCALE );
80+ assertEquals (new IntegerSchema ().cast (NEGATIVE_INTEGER ), NEGATIVE_NUMBER );
81+ } finally {
82+ Locale .setDefault (defaultLocale );
83+ }
84+ }
85+
86+ }
0 commit comments