|
7 | 7 |
|
8 | 8 | import tools.jackson.core.*; |
9 | 9 | import tools.jackson.core.json.JsonFactory; |
| 10 | +import tools.jackson.core.testutil.JacksonTestUtilBase; |
10 | 11 | import tools.jackson.databind.*; |
11 | 12 | import tools.jackson.databind.cfg.MapperConfig; |
12 | 13 | import tools.jackson.databind.introspect.AnnotatedMember; |
|
22 | 23 | * as part of JUnit 5 migration. |
23 | 24 | */ |
24 | 25 | public class DatabindTestUtil |
| 26 | + extends JacksonTestUtilBase |
25 | 27 | { |
26 | 28 | // @since 2.18 |
27 | 29 | // Helper annotation to work around lack of implicit name access with Jackson 2.x |
@@ -407,37 +409,12 @@ protected String serializeAsString(Object value) |
407 | 409 | return serializeAsString(sharedMapper(), value); |
408 | 410 | } |
409 | 411 |
|
410 | | - /* |
411 | | - /********************************************************************** |
412 | | - /* Encoding or String representations |
413 | | - /********************************************************************** |
414 | | - */ |
415 | | - |
416 | | - public static String a2q(String json) { |
417 | | - return json.replace("'", "\""); |
418 | | - } |
419 | | - |
420 | | - public static String q(String str) { |
421 | | - return '"'+str+'"'; |
422 | | - } |
423 | | - |
424 | | - public static byte[] utf8Bytes(String str) { |
425 | | - return str.getBytes(StandardCharsets.UTF_8); |
426 | | - } |
427 | | - |
428 | 412 | /* |
429 | 413 | /********************************************************************** |
430 | 414 | /* Additional assertion methods |
431 | 415 | /********************************************************************** |
432 | 416 | */ |
433 | 417 |
|
434 | | - public static void assertToken(JsonToken expToken, JsonToken actToken) |
435 | | - { |
436 | | - if (actToken != expToken) { |
437 | | - fail("Expected token "+expToken+", current token "+actToken); |
438 | | - } |
439 | | - } |
440 | | - |
441 | 418 | public static void assertValidLocation(TokenStreamLocation location) { |
442 | 419 | assertNotNull(location, "Should have non-null location"); |
443 | 420 | assertTrue(location.getLineNr() > 0, "Should have positive line number"); |
@@ -478,78 +455,6 @@ protected void assertStandardEquals(Object o) |
478 | 455 | o.hashCode(); |
479 | 456 | } |
480 | 457 |
|
481 | | - /** |
482 | | - * @param e Exception to check |
483 | | - * @param anyMatches Array of Strings of which AT LEAST ONE ("any") has to be included |
484 | | - * in {@code e.getMessage()} -- using case-INSENSITIVE comparison |
485 | | - */ |
486 | | - public static void verifyException(Throwable e, String... anyMatches) |
487 | | - { |
488 | | - String msg = e.getMessage(); |
489 | | - String lmsg = (msg == null) ? "" : msg.toLowerCase(); |
490 | | - for (String match : anyMatches) { |
491 | | - String lmatch = match.toLowerCase(); |
492 | | - if (lmsg.contains(lmatch)) { |
493 | | - return; |
494 | | - } |
495 | | - } |
496 | | - fail("Expected an exception with one of substrings (" |
497 | | - + Arrays.asList(anyMatches)+"): got one (of type "+e.getClass().getName() |
498 | | - +") with message \""+msg+"\""); |
499 | | - } |
500 | | - |
501 | | - /** |
502 | | - * Method that gets textual contents of the current token using |
503 | | - * available methods, and ensures results are consistent, before |
504 | | - * returning them |
505 | | - */ |
506 | | - protected static String getAndVerifyText(JsonParser jp) |
507 | | - { |
508 | | - // Ok, let's verify other accessors |
509 | | - int actLen = jp.getStringLength(); |
510 | | - char[] ch = jp.getStringCharacters(); |
511 | | - String str2 = new String(ch, jp.getStringOffset(), actLen); |
512 | | - String str = jp.getString(); |
513 | | - |
514 | | - if (str.length() != actLen) { |
515 | | - fail("Internal problem (jp.token == "+jp.currentToken()+"): jp.getText().length() ['"+str+"'] == "+str.length()+"; jp.getTextLength() == "+actLen); |
516 | | - } |
517 | | - assertEquals(str, str2, "String access via getText(), getTextXxx() must be the same"); |
518 | | - |
519 | | - return str; |
520 | | - } |
521 | | - |
522 | | - /* |
523 | | - /********************************************************** |
524 | | - /* JDK ser/deser |
525 | | - /********************************************************** |
526 | | - */ |
527 | | - |
528 | | - public static byte[] jdkSerialize(Object o) |
529 | | - { |
530 | | - ByteArrayOutputStream bytes = new ByteArrayOutputStream(2000); |
531 | | - try (ObjectOutputStream obOut = new ObjectOutputStream(bytes)) { |
532 | | - obOut.writeObject(o); |
533 | | - obOut.close(); |
534 | | - return bytes.toByteArray(); |
535 | | - } catch (IOException e) { |
536 | | - throw new UncheckedIOException(e); |
537 | | - } |
538 | | - } |
539 | | - |
540 | | - @SuppressWarnings("unchecked") |
541 | | - public static <T> T jdkDeserialize(byte[] raw) |
542 | | - { |
543 | | - try (ObjectInputStream objIn = new ObjectInputStream(new ByteArrayInputStream(raw))) { |
544 | | - return (T) objIn.readObject(); |
545 | | - } catch (ClassNotFoundException e) { |
546 | | - fail("Missing class: "+e.getMessage()); |
547 | | - return null; |
548 | | - } catch (IOException e) { |
549 | | - throw new UncheckedIOException(e); |
550 | | - } |
551 | | - } |
552 | | - |
553 | 458 | /* |
554 | 459 | /********************************************************************** |
555 | 460 | /* Helper methods, other |
|
0 commit comments