@Test public void fromJSONReturnsNullForIncompleteJSON() throws ComponentLookupException { JSONObject json = new JSONObject("{" + "\"filesize\":4," + "\"date\":\"2017-01-01T12:00:00.000Z\"," + "\"content\":\"YWJjZA==\"" + "}"); Assert.assertNull(this.mocker.getComponentUnderTest().fromJSON(json)); json = new JSONObject("{" + "\"filename\":\"a1.pdf\"," + "\"date\":\"2017-01-01T12:00:00.000Z\"," + "\"content\":\"YWJjZA==\"" + "}"); Assert.assertNull(this.mocker.getComponentUnderTest().fromJSON(json)); json = new JSONObject("{" + "\"filename\":\"a1.pdf\"," + "\"filesize\":4," + "\"content\":\"YWJjZA==\"" + "}"); Assert.assertNull(this.mocker.getComponentUnderTest().fromJSON(json)); json = new JSONObject("{" + "\"filename\":\"a1.pdf\"," + "\"filesize\":4," + "\"date\":\"2017-01-01T12:00:00.000Z\"" + "}"); Assert.assertNull(this.mocker.getComponentUnderTest().fromJSON(json)); }
public Attachment fromJSON(JSONObject attachment) { if (attachment == null) { return null; } try { return new Attachment(attachment, this.userResolver, this.userSerializer, this.contextProvider); } catch (IllegalArgumentException ex) { this.logger.warn("Invalid JSON for deserializing an attachment: {}", attachment); return null; } }
AttachmentAdapterFactory { public Attachment fromJSON(JSONObject attachment) { if (attachment == null) { return null; } try { return new Attachment(attachment, this.userResolver, this.userSerializer, this.contextProvider); } catch (IllegalArgumentException ex) { this.logger.warn("Invalid JSON for deserializing an attachment: {}", attachment); return null; } } }
AttachmentAdapterFactory { public Attachment fromJSON(JSONObject attachment) { if (attachment == null) { return null; } try { return new Attachment(attachment, this.userResolver, this.userSerializer, this.contextProvider); } catch (IllegalArgumentException ex) { this.logger.warn("Invalid JSON for deserializing an attachment: {}", attachment); return null; } }  }
AttachmentAdapterFactory { public Attachment fromJSON(JSONObject attachment) { if (attachment == null) { return null; } try { return new Attachment(attachment, this.userResolver, this.userSerializer, this.contextProvider); } catch (IllegalArgumentException ex) { this.logger.warn("Invalid JSON for deserializing an attachment: {}", attachment); return null; } }  Attachment fromXWikiAttachment(XWikiAttachment attachment); Attachment fromJSON(JSONObject attachment); }
AttachmentAdapterFactory { public Attachment fromJSON(JSONObject attachment) { if (attachment == null) { return null; } try { return new Attachment(attachment, this.userResolver, this.userSerializer, this.contextProvider); } catch (IllegalArgumentException ex) { this.logger.warn("Invalid JSON for deserializing an attachment: {}", attachment); return null; } }  Attachment fromXWikiAttachment(XWikiAttachment attachment); Attachment fromJSON(JSONObject attachment);  }