From 7bf213b211117ea97a4c4434711580923bc8577a Mon Sep 17 00:00:00 2001 From: dnskr Date: Sun, 21 Apr 2024 20:34:49 +0200 Subject: [PATCH] Use platform dependent expected values in json tests --- .../facebook/airlift/json/TestJsonCodec.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/json/src/test/java/com/facebook/airlift/json/TestJsonCodec.java b/json/src/test/java/com/facebook/airlift/json/TestJsonCodec.java index 701867e21f..9c386b9489 100644 --- a/json/src/test/java/com/facebook/airlift/json/TestJsonCodec.java +++ b/json/src/test/java/com/facebook/airlift/json/TestJsonCodec.java @@ -228,10 +228,11 @@ public void testToJsonWithLengthLimitSimple() JsonCodec jsonCodec = jsonCodec(ImmutablePerson.class); ImmutablePerson person = new ImmutablePerson(Strings.repeat("a", 1000), false); + int jsonNoLimitLength = jsonCodec.toJson(person).length(); + assertFalse(jsonCodec.toJsonWithLengthLimit(person, 0).isPresent()); - assertFalse(jsonCodec.toJsonWithLengthLimit(person, 1000).isPresent()); - assertFalse(jsonCodec.toJsonWithLengthLimit(person, 1035).isPresent()); - assertTrue(jsonCodec.toJsonWithLengthLimit(person, 1036).isPresent()); + assertFalse(jsonCodec.toJsonWithLengthLimit(person, jsonNoLimitLength - 1).isPresent()); + assertTrue(jsonCodec.toJsonWithLengthLimit(person, jsonNoLimitLength).isPresent()); } @Test @@ -240,10 +241,11 @@ public void testToJsonWithLengthLimitNonAscii() JsonCodec jsonCodec = jsonCodec(ImmutablePerson.class); ImmutablePerson person = new ImmutablePerson(Strings.repeat("\u0158", 1000), false); + int jsonNoLimitLength = jsonCodec.toJson(person).length(); + assertFalse(jsonCodec.toJsonWithLengthLimit(person, 0).isPresent()); - assertFalse(jsonCodec.toJsonWithLengthLimit(person, 1000).isPresent()); - assertFalse(jsonCodec.toJsonWithLengthLimit(person, 1035).isPresent()); - assertTrue(jsonCodec.toJsonWithLengthLimit(person, 1036).isPresent()); + assertFalse(jsonCodec.toJsonWithLengthLimit(person, jsonNoLimitLength - 1).isPresent()); + assertTrue(jsonCodec.toJsonWithLengthLimit(person, jsonNoLimitLength).isPresent()); } @Test @@ -253,9 +255,10 @@ public void testToJsonWithLengthLimitComplex() ImmutablePerson person = new ImmutablePerson(Strings.repeat("a", 1000), false); List people = Collections.nCopies(10, person); + int jsonNoLimitLength = jsonCodec.toJson(people).length(); + assertFalse(jsonCodec.toJsonWithLengthLimit(people, 0).isPresent()); - assertFalse(jsonCodec.toJsonWithLengthLimit(people, 5000).isPresent()); - assertFalse(jsonCodec.toJsonWithLengthLimit(people, 10381).isPresent()); - assertTrue(jsonCodec.toJsonWithLengthLimit(people, 10382).isPresent()); + assertFalse(jsonCodec.toJsonWithLengthLimit(people, jsonNoLimitLength - 1).isPresent()); + assertTrue(jsonCodec.toJsonWithLengthLimit(people, jsonNoLimitLength).isPresent()); } }