@Test public void toJSONWritesAllInformation() throws ComponentLookupException { Attachment a1 = this.mocker.getComponentUnderTest().fromXWikiAttachment(this.attachment1); a1.addAttribute("strkey", "value"); a1.addAttribute("boolkey", Boolean.FALSE); a1.addAttribute("boolkey", Boolean.TRUE); a1.addAttribute("numkey", Integer.valueOf(42)); JSONObject json1 = a1.toJSON(true); Assert.assertEquals("a1.pdf", json1.get(JSON_FIELD_FILENAME)); Assert.assertEquals(4L, json1.get(JSON_FIELD_FILESIZE)); Assert.assertEquals("Users.padams", json1.get(JSON_FIELD_AUTHOR)); Assert.assertEquals("2017-01-01T12:00:00.000Z", json1.get(JSON_FIELD_DATE)); Assert.assertEquals("YWJjZA==", json1.get(JSON_FIELD_CONTENT)); Assert.assertEquals("value", json1.get("strkey")); Assert.assertEquals(true, json1.getBoolean("boolkey")); Assert.assertEquals(42, json1.getInt("numkey")); JSONObject json2 = this.mocker.getComponentUnderTest().fromXWikiAttachment(this.attachment2).toJSON(true); Assert.assertEquals("a2.pdf", json2.get(JSON_FIELD_FILENAME)); Assert.assertEquals(3L, json2.get(JSON_FIELD_FILESIZE)); Assert.assertEquals("genetics:Users.hmccoy", json2.get(JSON_FIELD_AUTHOR)); Assert.assertEquals("2016-08-01T14:00:00.000Z", json2.get(JSON_FIELD_DATE)); Assert.assertEquals("eHl6", json2.get(JSON_FIELD_CONTENT)); }
public Attachment fromXWikiAttachment(XWikiAttachment attachment) { if (attachment == null) { return null; } return new Attachment(attachment, this.userResolver, this.userSerializer, this.contextProvider); }
AttachmentAdapterFactory { public Attachment fromXWikiAttachment(XWikiAttachment attachment) { if (attachment == null) { return null; } return new Attachment(attachment, this.userResolver, this.userSerializer, this.contextProvider); } }
AttachmentAdapterFactory { public Attachment fromXWikiAttachment(XWikiAttachment attachment) { if (attachment == null) { return null; } return new Attachment(attachment, this.userResolver, this.userSerializer, this.contextProvider); }  }
AttachmentAdapterFactory { public Attachment fromXWikiAttachment(XWikiAttachment attachment) { if (attachment == null) { return null; } return new Attachment(attachment, this.userResolver, this.userSerializer, this.contextProvider); }  Attachment fromXWikiAttachment(XWikiAttachment attachment); Attachment fromJSON(JSONObject attachment); }
AttachmentAdapterFactory { public Attachment fromXWikiAttachment(XWikiAttachment attachment) { if (attachment == null) { return null; } return new Attachment(attachment, this.userResolver, this.userSerializer, this.contextProvider); }  Attachment fromXWikiAttachment(XWikiAttachment attachment); Attachment fromJSON(JSONObject attachment);  }