LinkConverter { public static Map<String, String> linkToJson(final Link link) { final Map<String, String> json = new LinkedHashMap<>(); json.put("href", link.getHref().toString()); if (!link.getTitle().isEmpty()) { json.put("title", link.getTitle()); } return json; } private  LinkConverter(); static Map<String, String> linkToJson(final Link link); static Link jsonToLink(final Map<String, String> json); static List<Map<String,String>> linksToJson(final Collection<Link> links); static List<Link> jsonToLinks(final Collection<Map<String,String>> json);  }
@Test public void shouldConvertToMap() throws Exception { final Link link = new Link(create("http: final Map<String, String> map = linkToJson(link); assertEquals(map.get("href"), "http: assertEquals(map.get("title"), "Foo"); }
@Test(expectedExceptions = NullPointerException.class) public void shouldThrowExceptionIfHrefIsNull() throws Exception { final Link link = new Link(null, "Foo"); linkToJson(link); }
@Test(expectedExceptions = IllegalArgumentException.class) public void shouldThrowExceptionIfHrefIsRelative() throws Exception { final Link link = new Link(create("service"), "Foo"); linkToJson(link); }
@Test public void shouldHandleNullTitleProperly() throws Exception { final Link link = new Link(create("http: final Map<String, String> map = linkToJson(link); assertEquals(map.get("href"), "http: assertEquals(map.containsKey("title"), false); }