### Question:
NetworkRegistryHandler extends RegistryHandler { @Override List<Redirect> generateRedirects(String key, List<String> registryUrls) { List<Redirect> redirects = new ArrayList<Redirect>(); if (!removeEmptyUrlsAndValidate(registryUrls)) { logger.error("ignore this key/urls:{},{}. Urls are empty.", key, registryUrls); return redirects; } NetworkRedirect networkRedirect = new NetworkRedirect(registryUrls); IpVersion ipVersion = IpUtil.getIpVersionOfNetwork(key); if (ipVersion.isNotValidIp()) { logger.error("ignore this key/urls:{},{}. Invalid network:{}", key, registryUrls); return redirects; } try { QueryParam queryParam = NetworkQueryParam.generateQueryParam(key); if (null == queryParam) { logger.error( "ignore this key/urls:{},{}. generate networkQueryParam error:{}", key, registryUrls); return redirects; } networkRedirect .setNetworkQueryParam((NetworkQueryParam) queryParam); redirects.add(networkRedirect); } catch (Exception e) { logger.error("ignore this key/urls:{},{}. Invalid network:{}", key, registryUrls); } return redirects; }    }### Answer:
@Test public void testGenerateRedirects_normal() { List<String> registryUrls = new ArrayList<String>(); registryUrls.add("URL1"); registryUrls.add("URL2"); List<Redirect> redirects = handler.generateRedirects("1.0.0.0/8", registryUrls); assertNotNull(redirects); assertEquals(1, redirects.size()); List<String> results = redirects.get(0).getUrls(); assertEquals(2, results.size()); assertThat(results, CoreMatchers.hasItems("URL1", "URL2")); }
@Test public void testGenerateRedirects_empty_key() { List<String> registryUrls = new ArrayList<String>(); registryUrls.add("URL1"); registryUrls.add("URL2"); List<Redirect> redirects = handler.generateRedirects(null, registryUrls); assertNotNull(redirects); assertEquals(0, redirects.size()); redirects = handler.generateRedirects("", registryUrls); assertNotNull(redirects); assertEquals(0, redirects.size()); }
@Test public void testGenerateRedirects_all_urls_are_empty() { List<String> registryUrls = new ArrayList<String>(); registryUrls.add(null); registryUrls.add(""); List<Redirect> redirects = handler.generateRedirects("1.0.0.0/8", registryUrls); assertNotNull(redirects); assertEquals(0, redirects.size()); registryUrls = null; redirects = handler.generateRedirects("1.0.0.0/8", registryUrls); assertNotNull(redirects); assertEquals(0, redirects.size()); }
@Test public void testGenerateRedirects_one_url_is_empty() { List<String> registryUrls = new ArrayList<String>(); registryUrls.add(null); registryUrls.add("URL1"); List<Redirect> redirects = handler.generateRedirects("1.0.0.0/8", registryUrls); assertEquals(1, redirects.size()); List<String> results = redirects.get(0).getUrls(); assertEquals(1, results.size()); assertThat(results, CoreMatchers.hasItems("URL1")); }