77import static org .junit .jupiter .api .Assertions .assertNull ;
88import static org .junit .jupiter .api .Assertions .assertThrows ;
99
10- import java .math .BigInteger ;
1110import java .util .HashSet ;
1211import java .util .Set ;
13- import java .util .stream .Stream ;
1412import org .junit .jupiter .params .ParameterizedTest ;
15- import org .junit .jupiter .params .provider .Arguments ;
16- import org .junit .jupiter .params .provider .MethodSource ;
17- import org .junit .jupiter .params .provider .ValueSource ;
13+ import org .tabletest .junit .TableTest ;
1814
1915class DDSpanIdTest {
2016
21- @ ParameterizedTest (name = "convert ids from/to String {0}" )
22- @ MethodSource ("convertIdsFromToStringArguments" )
23- void convertIdsFromToString (String displayName , String stringId , long expectedId ) {
17+ @ TableTest ({
18+ "scenario | stringId | expectedId " ,
19+ "zero | '0' | 0 " ,
20+ "one | '1' | 1 " ,
21+ "max | '18446744073709551615' | -1 " ,
22+ "long max | '9223372036854775807' | 9223372036854775807 " ,
23+ "long max plus one | '9223372036854775808' | -9223372036854775808"
24+ })
25+ @ ParameterizedTest
26+ void convertIdsFromToString (String stringId , long expectedId ) {
2427 long ddid = DDSpanId .from (stringId );
2528
2629 assertEquals (expectedId , ddid );
2730 assertEquals (stringId , DDSpanId .toString (ddid ));
2831 }
2932
30- static Stream <Arguments > convertIdsFromToStringArguments () {
31- return Stream .of (
32- Arguments .of ("zero" , "0" , 0L ),
33- Arguments .of ("one" , "1" , 1L ),
34- Arguments .of ("max" , "18446744073709551615" , DDSpanId .MAX ),
35- Arguments .of ("long max" , String .valueOf (Long .MAX_VALUE ), Long .MAX_VALUE ),
36- Arguments .of (
37- "long max plus one" ,
38- BigInteger .valueOf (Long .MAX_VALUE ).add (BigInteger .ONE ).toString (),
39- Long .MIN_VALUE ));
40- }
41-
42- @ ParameterizedTest (name = "fail on illegal String {0}" )
43- @ MethodSource ("failOnIllegalStringArguments" )
33+ @ TableTest ({
34+ "scenario | stringId " ,
35+ "null | " ,
36+ "empty | '' " ,
37+ "negative one | '-1' " ,
38+ "too large | '18446744073709551616'" ,
39+ "too large variant | '18446744073709551625'" ,
40+ "too large long | '184467440737095516150'" ,
41+ "contains alpha first | '18446744073709551a1' " ,
42+ "contains alpha last | '184467440737095511a' "
43+ })
44+ @ ParameterizedTest
4445 void failOnIllegalString (String stringId ) {
4546 assertThrows (NumberFormatException .class , () -> DDSpanId .from (stringId ));
4647 }
4748
48- static Stream <Arguments > failOnIllegalStringArguments () {
49- return Stream .of (
50- Arguments .of ((Object ) null ),
51- Arguments .of ("" ),
52- Arguments .of ("-1" ),
53- Arguments .of ("18446744073709551616" ),
54- Arguments .of ("18446744073709551625" ),
55- Arguments .of ("184467440737095516150" ),
56- Arguments .of ("18446744073709551a1" ),
57- Arguments .of ("184467440737095511a" ));
58- }
59-
60- @ ParameterizedTest (name = "convert ids from/to hex String {0}" )
61- @ MethodSource ("convertIdsFromToHexStringArguments" )
49+ @ TableTest ({
50+ "scenario | hexId | expectedId " ,
51+ "zero | '0' | 0 " ,
52+ "one | '1' | 1 " ,
53+ "max | 'ffffffffffffffff' | -1 " ,
54+ "long max | '7fffffffffffffff' | 9223372036854775807 " ,
55+ "long min | '8000000000000000' | -9223372036854775808" ,
56+ "long min with leading zeros | '00008000000000000000' | -9223372036854775808" ,
57+ "cafebabe | 'cafebabe' | 3405691582 " ,
58+ "fifteen hex digits | '123456789abcdef' | 81985529216486895 "
59+ })
60+ @ ParameterizedTest
6261 void convertIdsFromToHexString (String hexId , long expectedId ) {
6362 long ddid = DDSpanId .fromHex (hexId );
6463 String padded16 =
@@ -73,27 +72,22 @@ void convertIdsFromToHexString(String hexId, long expectedId) {
7372 assertEquals (padded16 , DDSpanId .toHexStringPadded (ddid ));
7473 }
7574
76- static Stream < Arguments > convertIdsFromToHexStringArguments () {
77- return Stream . of (
78- Arguments . of ( "0" , 0L ) ,
79- Arguments . of ( "1" , 1L ) ,
80- Arguments . of ( repeat ( "f" , 16 ), DDSpanId . MAX ) ,
81- Arguments . of ( "7" + repeat ( "f" , 15 ), Long . MAX_VALUE ) ,
82- Arguments . of ( "8" + repeat ( "0" , 15 ), Long . MIN_VALUE ) ,
83- Arguments . of ( repeat ( "0" , 4 ) + "8" + repeat ( "0" , 15 ), Long . MIN_VALUE ) ,
84- Arguments . of ( "cafebabe" , 3405691582L ) ,
85- Arguments . of ( "123456789abcdef" , 81985529216486895L ));
86- }
87-
88- @ ParameterizedTest ( name = "convert ids from part of hex String {0}" )
89- @ MethodSource ( "convertIdsFromPartOfHexStringArguments" )
75+ @ TableTest ( {
76+ "scenario | hexId | start | length | lowerCaseOnly | expectedId" ,
77+ "null input | | 1 | 1 | false | " ,
78+ "empty input | '' | 1 | 1 | false | " ,
79+ "negative start | '00' | -1 | 1 | false | " ,
80+ "zero length | '00' | 0 | 0 | false | " ,
81+ "single zero at index 0 | '00' | 0 | 1 | false | 0 " ,
82+ "single zero at index 1 | '00' | 1 | 1 | false | 0 " ,
83+ "single zero at index 1 duplicate | '00' | 1 | 1 | false | 0 " ,
84+ "max lower-case | 'ffffffffffffffff' | 0 | 16 | true | -1 " ,
85+ "upper-case rejected when lower-case only| 'ffffffffffffFfff' | 0 | 16 | true | " ,
86+ "upper-case accepted when lower disabled | 'ffffffffffffFfff' | 0 | 16 | false | -1 "
87+ } )
88+ @ ParameterizedTest
9089 void convertIdsFromPartOfHexString (
91- String displayName ,
92- String hexId ,
93- int start ,
94- int length ,
95- boolean lowerCaseOnly ,
96- Long expectedId ) {
90+ String hexId , int start , int length , boolean lowerCaseOnly , Long expectedId ) {
9791 Long parsedId = null ;
9892 try {
9993 parsedId = DDSpanId .fromHex (hexId , start , length , lowerCaseOnly );
@@ -108,50 +102,27 @@ void convertIdsFromPartOfHexString(
108102 }
109103 }
110104
111- static Stream <Arguments > convertIdsFromPartOfHexStringArguments () {
112- return Stream .of (
113- Arguments .of ("null input" , null , 1 , 1 , false , null ),
114- Arguments .of ("empty input" , "" , 1 , 1 , false , null ),
115- Arguments .of ("negative start" , "00" , -1 , 1 , false , null ),
116- Arguments .of ("zero length" , "00" , 0 , 0 , false , null ),
117- Arguments .of ("single zero at index 0" , "00" , 0 , 1 , false , DDSpanId .ZERO ),
118- Arguments .of ("single zero at index 1" , "00" , 1 , 1 , false , DDSpanId .ZERO ),
119- Arguments .of ("single zero at index 1 duplicate" , "00" , 1 , 1 , false , DDSpanId .ZERO ),
120- Arguments .of ("max lower-case" , repeat ("f" , 16 ), 0 , 16 , true , DDSpanId .MAX ),
121- Arguments .of (
122- "upper-case rejected when lower-case only" ,
123- repeat ("f" , 12 ) + "Ffff" ,
124- 0 ,
125- 16 ,
126- true ,
127- null ),
128- Arguments .of (
129- "upper-case accepted when lower-case disabled" ,
130- repeat ("f" , 12 ) + "Ffff" ,
131- 0 ,
132- 16 ,
133- false ,
134- DDSpanId .MAX ));
135- }
136-
137- @ ParameterizedTest (name = "fail on illegal hex String {0}" )
138- @ MethodSource ("failOnIllegalHexStringArguments" )
105+ @ TableTest ({
106+ "scenario | hexId " ,
107+ "null | " ,
108+ "empty | '' " ,
109+ "negative one | '-1' " ,
110+ "too long | '10000000000000000'" ,
111+ "invalid middle | 'ffffffffffffffzf' " ,
112+ "invalid tail | 'fffffffffffffffz' "
113+ })
114+ @ ParameterizedTest
139115 void failOnIllegalHexString (String hexId ) {
140116 assertThrows (NumberFormatException .class , () -> DDSpanId .fromHex (hexId ));
141117 }
142118
143- static Stream <Arguments > failOnIllegalHexStringArguments () {
144- return Stream .of (
145- Arguments .of ((Object ) null ),
146- Arguments .of ("" ),
147- Arguments .of ("-1" ),
148- Arguments .of ("1" + repeat ("0" , 16 )),
149- Arguments .of (repeat ("f" , 14 ) + "zf" ),
150- Arguments .of (repeat ("f" , 15 ) + "z" ));
151- }
152-
153- @ ParameterizedTest (name = "generate id with {0}" )
154- @ ValueSource (strings = {"RANDOM" , "SEQUENTIAL" , "SECURE_RANDOM" })
119+ @ TableTest ({
120+ "scenario | strategyName " ,
121+ "random | RANDOM " ,
122+ "sequential | SEQUENTIAL " ,
123+ "secure random | SECURE_RANDOM"
124+ })
125+ @ ParameterizedTest
155126 void generateIdWithStrategy (String strategyName ) {
156127 IdGenerationStrategy strategy = IdGenerationStrategy .fromName (strategyName );
157128 Set <Long > checked = new HashSet <Long >();
0 commit comments