Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use platform dependent expected values in json tests #82

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions json/src/test/java/com/facebook/airlift/json/TestJsonCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,11 @@ public void testToJsonWithLengthLimitSimple()
JsonCodec<ImmutablePerson> 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
Expand All @@ -240,10 +241,11 @@ public void testToJsonWithLengthLimitNonAscii()
JsonCodec<ImmutablePerson> 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
Expand All @@ -253,9 +255,10 @@ public void testToJsonWithLengthLimitComplex()
ImmutablePerson person = new ImmutablePerson(Strings.repeat("a", 1000), false);
List<ImmutablePerson> 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());
}
}
Loading