@Test
public void enforceRestrictionsOnViolation() {

    // GIVEN:
    final String key = "/attributes/enforceRestrictionsOnViolation";
    final int maxAllowedValueForKey = MAX_INDEX_CONTENT_LENGTH - OVERHEAD - key.length();
    final String value = TestStringGenerator.createStringOfBytes(maxAllowedValueForKey + 1);
    // WHEN:
    final String enforcedValue = indexLengthRestrictionEnforcer.enforce(JsonPointer.of(key), JsonValue.of(value))
            .orElseThrow()
            .asString();
    final int enforcedValueBytes = enforcedValue.getBytes(StandardCharsets.UTF_8).length;
    // THEN: value is truncated to fit in the max allowed value bytes
    assertThat(value).startsWith(enforcedValue);
    assertThat(enforcedValueBytes).isLessThanOrEqualTo(maxAllowedValueForKey);
    // THEN: value is not truncated more than needed
    final int maxUtf8Bytes = 4;
    assertThat(enforcedValueBytes).isCloseTo(maxAllowedValueForKey, Offset.offset(maxUtf8Bytes));
}