JsonArrayValueValidator extends AbstractHeaderValueValidator { static JsonArrayValueValidator getInstance() { return INSTANCE; } private  JsonArrayValueValidator();   }
@Test public void tryToAcceptNullDefinition() { final JsonArrayValueValidator underTest = JsonArrayValueValidator.getInstance(); assertThatNullPointerException() .isThrownBy(() -> underTest.accept(null, validJsonArrayString)) .withMessage("The definition must not be null!") .withNoCause(); }
@Test public void tryToAcceptNullValue() { final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.REQUESTED_ACKS; final JsonArrayValueValidator underTest = JsonArrayValueValidator.getInstance(); assertThatExceptionOfType(DittoHeaderInvalidException.class) .isThrownBy(() -> underTest.accept(headerDefinition, null)) .withMessageContaining("null") .withMessageContaining(headerDefinition.getKey()) .withMessageEndingWith("is not a valid JsonArray.") .withNoCause(); }
@Test public void acceptValidCharSequence() { final JsonArrayValueValidator underTest = JsonArrayValueValidator.getInstance(); assertThatCode(() -> underTest.accept(DittoHeaderDefinition.REQUESTED_ACKS, validJsonArrayString)) .doesNotThrowAnyException(); }
@Test public void doesNotValidateAsDefinedJavaTypeIsNotJsonArray() { final JsonArrayValueValidator underTest = JsonArrayValueValidator.getInstance(); assertThatCode(() -> underTest.accept(DittoHeaderDefinition.RESPONSE_REQUIRED, validJsonArrayString)) .doesNotThrowAnyException(); }
@Test public void acceptNonJsonArrayString() { final String invalidJsonArrayString = "foo"; final JsonArrayValueValidator underTest = JsonArrayValueValidator.getInstance(); assertThatExceptionOfType(DittoHeaderInvalidException.class) .isThrownBy(() -> underTest.accept(DittoHeaderDefinition.REQUESTED_ACKS, invalidJsonArrayString)) .withMessageContaining(invalidJsonArrayString) .withMessageEndingWith("is not a valid JSON array.") .withNoCause(); }
@Test public void acceptJsonArrayStringWithNonStringItems() { final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.REQUESTED_ACKS; final JsonArray invalidJsonArray = JsonArray.newBuilder() .add("foo") .add(42) .add(true) .build(); final String invalidJsonArrayString = invalidJsonArray.toString(); final JsonArrayValueValidator underTest = JsonArrayValueValidator.getInstance(); assertThatExceptionOfType(DittoHeaderInvalidException.class) .isThrownBy(() -> underTest.accept(headerDefinition, invalidJsonArrayString)) .withMessageContaining(headerDefinition.getKey()) .withMessageEndingWith("contained non-string values!") .withNoCause(); }