4
4
import java .nio .charset .StandardCharsets ;
5
5
import java .util .Arrays ;
6
6
7
+ import com .fasterxml .jackson .core .io .IOContext ;
7
8
import com .fasterxml .jackson .core .testsupport .MockDataInput ;
9
+ import com .fasterxml .jackson .core .testsupport .TestSupport ;
8
10
import com .fasterxml .jackson .core .testsupport .ThrottledInputStream ;
9
11
import com .fasterxml .jackson .core .testsupport .ThrottledReader ;
12
+ import org .junit .jupiter .api .Test ;
10
13
11
14
import static org .junit .jupiter .api .Assertions .assertEquals ;
12
15
import static org .junit .jupiter .api .Assertions .fail ;
16
19
*/
17
20
public class JUnit5TestBase
18
21
{
22
+ protected final static String FIELD_BASENAME = "f" ;
23
+
19
24
protected final static int MODE_INPUT_STREAM = 0 ;
20
25
protected final static int MODE_INPUT_STREAM_THROTTLED = 1 ;
21
26
protected final static int MODE_READER = 2 ;
@@ -228,6 +233,16 @@ public static JsonGenerator createGenerator(TokenStreamFactory f, Writer w) thro
228
233
return f .createGenerator (w );
229
234
}
230
235
236
+ /*
237
+ /**********************************************************************
238
+ /* Helper type construction
239
+ /**********************************************************************
240
+ */
241
+
242
+ public static IOContext testIOContext () {
243
+ return TestSupport .testIOContext ();
244
+ }
245
+
231
246
/*
232
247
/**********************************************************************
233
248
/* Assertions
@@ -295,18 +310,10 @@ protected String q(String str) {
295
310
return '"' +str +'"' ;
296
311
}
297
312
298
- protected static String a2q (String json ) {
313
+ public static String a2q (String json ) {
299
314
return json .replace ('\'' , '"' );
300
315
}
301
316
302
- protected static byte [] utf8Bytes (String str ) {
303
- return str .getBytes (StandardCharsets .UTF_8 );
304
- }
305
-
306
- protected String utf8String (ByteArrayOutputStream bytes ) {
307
- return new String (bytes .toByteArray (), StandardCharsets .UTF_8 );
308
- }
309
-
310
317
public static byte [] encodeInUTF32BE (String input )
311
318
{
312
319
int len = input .length ();
@@ -321,12 +328,48 @@ public static byte[] encodeInUTF32BE(String input)
321
328
return result ;
322
329
}
323
330
331
+ protected static byte [] utf8Bytes (String str ) {
332
+ return str .getBytes (StandardCharsets .UTF_8 );
333
+ }
334
+
335
+ protected String utf8String (ByteArrayOutputStream bytes ) {
336
+ return new String (bytes .toByteArray (), StandardCharsets .UTF_8 );
337
+ }
338
+
339
+ public static String fieldNameFor (int index )
340
+ {
341
+ StringBuilder sb = new StringBuilder (16 );
342
+ fieldNameFor (sb , index );
343
+ return sb .toString ();
344
+ }
345
+
346
+ private static void fieldNameFor (StringBuilder sb , int index )
347
+ {
348
+ /* let's do something like "f1.1" to exercise different
349
+ * field names (important for byte-based codec)
350
+ * Other name shuffling done mostly just for fun... :)
351
+ */
352
+ sb .append (FIELD_BASENAME );
353
+ sb .append (index );
354
+ if (index > 50 ) {
355
+ sb .append ('.' );
356
+ if (index > 200 ) {
357
+ sb .append (index );
358
+ if (index > 4000 ) { // and some even longer symbols...
359
+ sb .append ("." ).append (index );
360
+ }
361
+ } else {
362
+ sb .append (index >> 3 ); // divide by 8
363
+ }
364
+ }
365
+ }
366
+
324
367
public static byte [] readResource (String ref )
325
368
{
326
369
ByteArrayOutputStream bytes = new ByteArrayOutputStream ();
327
370
final byte [] buf = new byte [4000 ];
328
371
329
- InputStream in = BaseTest .class .getResourceAsStream (ref );
372
+ InputStream in = JUnit5TestBase .class .getResourceAsStream (ref );
330
373
if (in != null ) {
331
374
try {
332
375
int len ;
0 commit comments