public XmlsonObject present(Merchant merchant) { final XmlsonObject root = new XmlsonObject("merchant"); root.addProperty("name", merchant.getName()); root.addProperty("id", merchant.getId()); root.addProperty("uri", String.format("/transactions/merchant/%d", merchant.getId())); return root; }
@Test public void itHasATotal() throws Exception { final XmlsonObject representation = presenter.present(accounts, USD, Locale.PRC); final XmlsonObject total = (XmlsonObject) representation.get("total"); assertThat(total.getName(), is("total")); verify(accounts).getTotal(USD, exchangeRateMap); verify(moneyPresenter).present("total", money("3460.81", USD), Locale.PRC); }
@Test public void itHasAnArrayOfAccounts() throws Exception { final XmlsonObject representation = presenter.present(accounts, USD, Locale.PRC); final XmlsonArray accounts = (XmlsonArray) representation.get("accounts"); assertThat(accounts.getMembers().size(), is(1)); final XmlsonObject account = (XmlsonObject) accounts.getMembers().get(0); assertThat(account.getName(), is("account")); verify(accountPresenter).present(this.account, Locale.PRC); }
@Test public void itHasAnArrayOfGroups() throws Exception { final XmlsonObject representation = presenter.present(accounts, USD, Locale.PRC); final XmlsonArray groups = (XmlsonArray) representation.get("account-groups"); assertThat(groups.getMembers().size(), is(1)); final XmlsonObject group = (XmlsonObject) groups.getMembers().get(0); assertThat(group.getName(), is("group")); verify(accountGroupPresenter).present(this.group, USD, Locale.PRC); }
@Test public void itHasADescription() throws Exception { final XmlsonObject representation = presenter.present(attachment); assertThat(representation.getString("description"), is("My receipt.")); }
@Test public void itHasASize() throws Exception { final XmlsonObject representation = presenter.present(attachment); assertThat(representation.getInteger("size"), is(284569)); }
@Test public void itHasAContentType() throws Exception { final XmlsonObject representation = presenter.present(attachment); assertThat(representation.getString("content-type"), is("application/pdf")); }
@Test public void itHasAFilename() throws Exception { final XmlsonObject representation = presenter.present(attachment); assertThat(representation.getString("filename"), is("receipt.pdf")); }
@Test public void itHasAGuid() throws Exception { final XmlsonObject representation = presenter.present(attachment); assertThat(representation.getString("guid"), is("1234567890")); }
@Test public void itIsNamedAttachment() throws Exception { final XmlsonObject representation = presenter.present(attachment); assertThat(representation.getName(), is("attachment")); }
@Test public void itIsNamedAccountList() throws Exception { final XmlsonObject representation = presenter.present(accounts, USD, Locale.PRC); assertThat(representation.getName(), is("account-list")); }