Skip to content

Commit c03925e

Browse files
dnskrtdcmeehan
authored andcommitted
Use platform dependent expected values in json tests
1 parent 1016fbd commit c03925e

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

json/src/test/java/com/facebook/airlift/json/TestJsonCodec.java

+12-9
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,11 @@ public void testToJsonWithLengthLimitSimple()
228228
JsonCodec<ImmutablePerson> jsonCodec = jsonCodec(ImmutablePerson.class);
229229
ImmutablePerson person = new ImmutablePerson(Strings.repeat("a", 1000), false);
230230

231+
int jsonNoLimitLength = jsonCodec.toJson(person).length();
232+
231233
assertFalse(jsonCodec.toJsonWithLengthLimit(person, 0).isPresent());
232-
assertFalse(jsonCodec.toJsonWithLengthLimit(person, 1000).isPresent());
233-
assertFalse(jsonCodec.toJsonWithLengthLimit(person, 1035).isPresent());
234-
assertTrue(jsonCodec.toJsonWithLengthLimit(person, 1036).isPresent());
234+
assertFalse(jsonCodec.toJsonWithLengthLimit(person, jsonNoLimitLength - 1).isPresent());
235+
assertTrue(jsonCodec.toJsonWithLengthLimit(person, jsonNoLimitLength).isPresent());
235236
}
236237

237238
@Test
@@ -240,10 +241,11 @@ public void testToJsonWithLengthLimitNonAscii()
240241
JsonCodec<ImmutablePerson> jsonCodec = jsonCodec(ImmutablePerson.class);
241242
ImmutablePerson person = new ImmutablePerson(Strings.repeat("\u0158", 1000), false);
242243

244+
int jsonNoLimitLength = jsonCodec.toJson(person).length();
245+
243246
assertFalse(jsonCodec.toJsonWithLengthLimit(person, 0).isPresent());
244-
assertFalse(jsonCodec.toJsonWithLengthLimit(person, 1000).isPresent());
245-
assertFalse(jsonCodec.toJsonWithLengthLimit(person, 1035).isPresent());
246-
assertTrue(jsonCodec.toJsonWithLengthLimit(person, 1036).isPresent());
247+
assertFalse(jsonCodec.toJsonWithLengthLimit(person, jsonNoLimitLength - 1).isPresent());
248+
assertTrue(jsonCodec.toJsonWithLengthLimit(person, jsonNoLimitLength).isPresent());
247249
}
248250

249251
@Test
@@ -253,9 +255,10 @@ public void testToJsonWithLengthLimitComplex()
253255
ImmutablePerson person = new ImmutablePerson(Strings.repeat("a", 1000), false);
254256
List<ImmutablePerson> people = Collections.nCopies(10, person);
255257

258+
int jsonNoLimitLength = jsonCodec.toJson(people).length();
259+
256260
assertFalse(jsonCodec.toJsonWithLengthLimit(people, 0).isPresent());
257-
assertFalse(jsonCodec.toJsonWithLengthLimit(people, 5000).isPresent());
258-
assertFalse(jsonCodec.toJsonWithLengthLimit(people, 10381).isPresent());
259-
assertTrue(jsonCodec.toJsonWithLengthLimit(people, 10382).isPresent());
261+
assertFalse(jsonCodec.toJsonWithLengthLimit(people, jsonNoLimitLength - 1).isPresent());
262+
assertTrue(jsonCodec.toJsonWithLengthLimit(people, jsonNoLimitLength).isPresent());
260263
}
261264
}

0 commit comments

Comments
 (0)