@@ -228,10 +228,11 @@ public void testToJsonWithLengthLimitSimple()
228
228
JsonCodec <ImmutablePerson > jsonCodec = jsonCodec (ImmutablePerson .class );
229
229
ImmutablePerson person = new ImmutablePerson (Strings .repeat ("a" , 1000 ), false );
230
230
231
+ int jsonNoLimitLength = jsonCodec .toJson (person ).length ();
232
+
231
233
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 ());
235
236
}
236
237
237
238
@ Test
@@ -240,10 +241,11 @@ public void testToJsonWithLengthLimitNonAscii()
240
241
JsonCodec <ImmutablePerson > jsonCodec = jsonCodec (ImmutablePerson .class );
241
242
ImmutablePerson person = new ImmutablePerson (Strings .repeat ("\u0158 " , 1000 ), false );
242
243
244
+ int jsonNoLimitLength = jsonCodec .toJson (person ).length ();
245
+
243
246
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 ());
247
249
}
248
250
249
251
@ Test
@@ -253,9 +255,10 @@ public void testToJsonWithLengthLimitComplex()
253
255
ImmutablePerson person = new ImmutablePerson (Strings .repeat ("a" , 1000 ), false );
254
256
List <ImmutablePerson > people = Collections .nCopies (10 , person );
255
257
258
+ int jsonNoLimitLength = jsonCodec .toJson (people ).length ();
259
+
256
260
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 ());
260
263
}
261
264
}
0 commit comments