JsonObjectValueValidator extends AbstractHeaderValueValidator { static JsonObjectValueValidator getInstance() { return INSTANCE; } private  JsonObjectValueValidator();   }
@Test public void tryToAcceptNullDefinition() { final JsonObjectValueValidator underTest = JsonObjectValueValidator.getInstance(); assertThatNullPointerException() .isThrownBy(() -> underTest.accept(null, validJsonObjectString)) .withMessage("The definition must not be null!") .withNoCause(); }
@Test public void tryToAcceptNullValue() { final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.AUTHORIZATION_CONTEXT; final JsonObjectValueValidator underTest = JsonObjectValueValidator.getInstance(); assertThatExceptionOfType(DittoHeaderInvalidException.class) .isThrownBy(() -> underTest.accept(headerDefinition, null)) .withMessageContaining("null") .withMessageContaining(headerDefinition.getKey()) .withMessageEndingWith("is not a valid JsonObject.") .withNoCause(); }
@Test public void acceptValidCharSequence() { final JsonObjectValueValidator underTest = JsonObjectValueValidator.getInstance(); assertThatCode(() -> underTest.accept(DittoHeaderDefinition.AUTHORIZATION_CONTEXT, validJsonObjectString)) .doesNotThrowAnyException(); }
@Test public void doesNotValidateAsDefinedJavaTypeIsNotJsonObject() { final JsonObjectValueValidator underTest = JsonObjectValueValidator.getInstance(); assertThatCode(() -> underTest.accept(DittoHeaderDefinition.RESPONSE_REQUIRED, validJsonObjectString)) .doesNotThrowAnyException(); }
@Test public void acceptNonJsonObjectString() { final String invalidJsonObjectString = "foo"; final JsonObjectValueValidator underTest = JsonObjectValueValidator.getInstance(); assertThatExceptionOfType(DittoHeaderInvalidException.class) .isThrownBy(() -> underTest.accept(DittoHeaderDefinition.AUTHORIZATION_CONTEXT, invalidJsonObjectString)) .withMessageContaining(invalidJsonObjectString) .withMessageEndingWith("is not a valid JSON object.") .withNoCause(); }