ResourceLinkHelper { public static List<? extends ResourceLink> mergeResources(final List<? extends ResourceLink> resourceLinks, final List<? extends ResourceLink> other) { if (other.isEmpty()) { return resourceLinks; } else { List<? extends ResourceLink> result = resourceLinks; for (final ResourceLink resourceLink : other) { result = mergeResources(result, resourceLink); } return result; } } private  ResourceLinkHelper(); static List<? extends ResourceLink> mergeResources(final List<? extends ResourceLink> resourceLinks,
                                                    final List<? extends ResourceLink> other); static List<? extends ResourceLink> mergeResources(final List<? extends ResourceLink> resourceLinks,
                                                    final ResourceLink other);  }
@Test public void mergingIdenticalLinksShouldResultInSingleLink() throws Exception { final List<? extends ResourceLink> resourceLinks = mergeResources( asList(STOREFRONT_LINK), STOREFRONT_LINK ); assertEquals(resourceLinks, asList(STOREFRONT_LINK)); }
@Test public void mergingDifferentLinksShouldResultInMergedLinks() throws Exception { final List<? extends ResourceLink> resourceLinks = mergeResources( asList(STOREFRONT_LINK), ABOUTPAGE_LINK ); assertEquals(resourceLinks, asList(STOREFRONT_LINK, ABOUTPAGE_LINK)); }
@Test public void mergingListWithIdenticalLinksShouldResultInSingleLink() throws Exception { final List<? extends ResourceLink> resourceLinks = mergeResources( asList(STOREFRONT_LINK), asList(STOREFRONT_LINK) ); assertEquals(resourceLinks, asList(STOREFRONT_LINK)); }
@Test public void mergingListsWithDifferentLinksShouldResultInMergedLinks() throws Exception { final List<ResourceLink> first = asList(STOREFRONT_LINK, ABOUTPAGE_LINK); final List<DirectLink> second = asList(SHOPPAGES_LINK, FOO_LINK); final List<? extends ResourceLink> resourceLinks = mergeResources( first, second ); assertEquals(resourceLinks, asList(STOREFRONT_LINK, ABOUTPAGE_LINK, SHOPPAGES_LINK, FOO_LINK)); assertEquals(first.size(), 2); assertEquals(second.size(), 2); }
@Test public void mergingEmptyListWithLinksShouldResultInLinks() throws Exception { final List<? extends ResourceLink> resourceLinks = mergeResources( asList(STOREFRONT_LINK), Collections.<ResourceLink>emptyList() ); assertEquals(resourceLinks, asList(STOREFRONT_LINK)); }