LinkConverter { public static Link jsonToLink(final Map<String, String> json) { return new Link( create(json.get("href")), json.get("title") ); } 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 shouldConvertMapToLink() throws Exception { final Map<String, String> map = new HashMap<String, String>(); map.put("href", "http: map.put("title", "Foo"); final Link link = jsonToLink(map); assertEquals(link, new Link(create("http: }
@Test public void shouldConvertMapWithoutTitleToLink() throws Exception { final Map<String, String> map = new HashMap<String, String>(); map.put("href", "http: final Link link = jsonToLink(map); assertEquals(link, new Link(create("http: }
@Test(expectedExceptions = NullPointerException.class) public void shouldFailToConvertMapWithoutHref() throws Exception { final Map<String, String> map = new HashMap<String, String>(); map.put("title", "Foo"); jsonToLink(map); }
@Test(expectedExceptions = NullPointerException.class) public void shouldFailToConvertMapWithNullHref() throws Exception { final Map<String, String> map = new HashMap<String, String>(); map.put("href", null); map.put("title", "Foo"); jsonToLink(map); }
@Test(expectedExceptions = IllegalArgumentException.class) public void shouldFailToConvertMapWithRelativeHref() throws Exception { final Map<String, String> map = new HashMap<String, String>(); map.put("href", "foo"); map.put("title", "Foo"); jsonToLink(map); }