ResourceLinkConverter { public static Map<String, Map<String, Object>> toRepresentation(final ResourceLink resourceLink, final JsonHomeMediaType mediaType) { if (resourceLink.isDirectLink()) { return directLinkToJsonHome(resourceLink.asDirectLink(), mediaType); } else { return templatedLinkToJsonHome(resourceLink.asTemplatedLink(), mediaType); } }  static Map<String, Map<String, Object>> toRepresentation(final ResourceLink resourceLink,
                                                                    final JsonHomeMediaType mediaType); static Map<String, Map<String, Object>> templatedLinkToJsonHome(final TemplatedLink resourceLink,
                                                                           final JsonHomeMediaType mediaType); static Map<String, Map<String, Object>> directLinkToJsonHome(final DirectLink resourceLink,
                                                                        final JsonHomeMediaType mediaType);  }
@Test public void shouldConvertDirectLink() { final DirectLink storefrontLink = STOREFRONT_LINK; final Map<String,?> json = toRepresentation(storefrontLink, APPLICATION_JSONHOME); assertNotNull(json); assertEquals(json.keySet().size(), 1); @SuppressWarnings("unchecked") final Map<String, ?> resource = (Map<String, ?>) json.get("http: assertEquals(resource.keySet().size(), 2); assertEquals(resource.get("href"), ABS_STOREFRONT_HREF.toString()); final Map hints = (Map) resource.get("hints"); assertNotNull(hints); assertEquals(hints.get("allow"), of(GET)); assertEquals(hints.get("representations"), Arrays.asList("text/html", "application/json")); }
@Test public void shouldConvertTemplatedLink() { final TemplatedLink aboutPageLink = ABOUTPAGE_LINK; Map<String, ?> json = toRepresentation(aboutPageLink, APPLICATION_JSONHOME); assertNotNull(json); assertEquals(json.keySet().size(), 1); @SuppressWarnings("unchecked") final Map<String, ?> resource = (Map<String, ?>) json.get("http: assertEquals(resource.keySet().size(), 3); assertNull(resource.get("href")); assertEquals(resource.get("href-template"), REL_PAGE_HREF); assertEquals(resource.get("href-vars"), singletonMap("pageId", "http: final Map hints = (Map) resource.get("hints"); assertNotNull(hints); assertEquals(hints.get("allow"), of(GET)); assertEquals(hints.get("representations"), Arrays.asList("text/html", "application/json")); }