@Test public void fromJsonNodeShouldSetValidationResultWhenPatchIsInvalid() { UpdateMessagePatchValidator stubValidator = mock(UpdateMessagePatchValidator.class); when(stubValidator.isValid(any(ObjectNode.class))).thenReturn(false); ImmutableSet<ValidationResult> nonEmptyValidationResult = ImmutableSet.of(ValidationResult.builder().build()); when(stubValidator.validate(any(ObjectNode.class))).thenReturn(nonEmptyValidationResult); UpdateMessagePatchConverter sut = new UpdateMessagePatchConverter(null, stubValidator); ObjectNode dummynode = JsonNodeFactory.instance.objectNode(); UpdateMessagePatch result = sut.fromJsonNode(dummynode); assertThat(result).extracting(UpdateMessagePatch::getValidationErrors) .asList() .isNotEmpty(); }
public UpdateMessagePatch fromJsonNode(ObjectNode updatePatchNode) { if (updatePatchNode == null || updatePatchNode.isNull() || updatePatchNode.isMissingNode()) { throw new IllegalArgumentException("updatePatchNode"); } if (! validator.isValid(updatePatchNode)) { return UpdateMessagePatch.builder() .validationResult(validator.validate(updatePatchNode)) .build(); } try { return jsonParser.readerFor(UpdateMessagePatch.class).<UpdateMessagePatch>readValue(updatePatchNode); } catch (IOException e) { throw new RuntimeException(e); } }
UpdateMessagePatchConverter { public UpdateMessagePatch fromJsonNode(ObjectNode updatePatchNode) { if (updatePatchNode == null || updatePatchNode.isNull() || updatePatchNode.isMissingNode()) { throw new IllegalArgumentException("updatePatchNode"); } if (! validator.isValid(updatePatchNode)) { return UpdateMessagePatch.builder() .validationResult(validator.validate(updatePatchNode)) .build(); } try { return jsonParser.readerFor(UpdateMessagePatch.class).<UpdateMessagePatch>readValue(updatePatchNode); } catch (IOException e) { throw new RuntimeException(e); } } }
UpdateMessagePatchConverter { public UpdateMessagePatch fromJsonNode(ObjectNode updatePatchNode) { if (updatePatchNode == null || updatePatchNode.isNull() || updatePatchNode.isMissingNode()) { throw new IllegalArgumentException("updatePatchNode"); } if (! validator.isValid(updatePatchNode)) { return UpdateMessagePatch.builder() .validationResult(validator.validate(updatePatchNode)) .build(); } try { return jsonParser.readerFor(UpdateMessagePatch.class).<UpdateMessagePatch>readValue(updatePatchNode); } catch (IOException e) { throw new RuntimeException(e); } } @Inject @VisibleForTesting  UpdateMessagePatchConverter(ObjectMapper jsonParser, UpdateMessagePatchValidator validator); }
UpdateMessagePatchConverter { public UpdateMessagePatch fromJsonNode(ObjectNode updatePatchNode) { if (updatePatchNode == null || updatePatchNode.isNull() || updatePatchNode.isMissingNode()) { throw new IllegalArgumentException("updatePatchNode"); } if (! validator.isValid(updatePatchNode)) { return UpdateMessagePatch.builder() .validationResult(validator.validate(updatePatchNode)) .build(); } try { return jsonParser.readerFor(UpdateMessagePatch.class).<UpdateMessagePatch>readValue(updatePatchNode); } catch (IOException e) { throw new RuntimeException(e); } } @Inject @VisibleForTesting  UpdateMessagePatchConverter(ObjectMapper jsonParser, UpdateMessagePatchValidator validator); UpdateMessagePatch fromJsonNode(ObjectNode updatePatchNode); }
UpdateMessagePatchConverter { public UpdateMessagePatch fromJsonNode(ObjectNode updatePatchNode) { if (updatePatchNode == null || updatePatchNode.isNull() || updatePatchNode.isMissingNode()) { throw new IllegalArgumentException("updatePatchNode"); } if (! validator.isValid(updatePatchNode)) { return UpdateMessagePatch.builder() .validationResult(validator.validate(updatePatchNode)) .build(); } try { return jsonParser.readerFor(UpdateMessagePatch.class).<UpdateMessagePatch>readValue(updatePatchNode); } catch (IOException e) { throw new RuntimeException(e); } } @Inject @VisibleForTesting  UpdateMessagePatchConverter(ObjectMapper jsonParser, UpdateMessagePatchValidator validator); UpdateMessagePatch fromJsonNode(ObjectNode updatePatchNode);  }