SendEventRequestValidator { void validateContext(Map<String, String> context, int maxContextValueLength) { for (Map.Entry<String, String> entry : context.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (value.length() > maxContextValueLength) throw new BadRequestException(format("context value is too long, key={}, value={}...(truncated)", key, Strings.truncate(value, 200)), "EVENT_TOO_LARGE"); } }    }
@Test void validateContext() { assertThatThrownBy(() -> validator.validateContext(Map.of("context", "12345"), 3)) .isInstanceOf(BadRequestException.class) .hasMessageContaining("too long"); }