### Question:
IPv6 { public static String expand(String ipStr, int nwords) throws IPStringConversionException { StringBuilder sb; String hex; int[] vals; int[] expanded_vals; int i; sb = new StringBuilder(); vals = splitvals(ipStr); if (vals == null) { throw new IPStringConversionException("Error converting hex to binary in IPv6 ip"); } expanded_vals = expand(vals, nwords); for (i = 0; i < nwords - 1; i++) { hex = String.format("%s:", IPUtils.int16bit2hex(expanded_vals[i])); sb.append(hex); } hex = String.format("%s", IPUtils.int16bit2hex(expanded_vals[nwords - 1])); sb.append(hex); return sb.toString(); } IPv6();  IPv6(String ip);  IPv6(byte[] in); static int[] splitvals(String ipStr); static int countnegatives(int[] in); static String expand(String ipStr, int nwords); String expand(); static int[] expand(int[] vals, int nwords); static byte[] IpString2bytes(String ipStr); static String bytes2IpString(byte[] in); void setIp(byte[] in); String getString(); byte[] getBytes(); void setIp(String ip);  }### Answer:
@Test public void testRightCompress() throws IPStringConversionException { assertTrue("Expected right Compression to work", right_uncompressed.equals(IPv6.expand(right_compressed, 8))); }
@Test public void testLeftCompress() throws IPStringConversionException { assertTrue("Expected left compression to work ", left_uncompressed.equals(IPv6.expand(left_compressed, 8))); }
@Test public void testAllZeroCompress() throws IPStringConversionException { assertTrue("Expected All Zero compression to work", zero_uncompressed.equals(IPv6.expand(zero_compressed, 8))); }
@Test public void testMiddleCompress() throws IPStringConversionException { assertTrue("Expected middle compress to work", middle_uncompressed.equals(IPv6.expand(middle_compressed, 8))); }
@Test(expected = IPStringConversionException.class) public void testNotEnoughintVals() throws IPStringConversionException { IPv6.expand(":", 8); }
@Test(expected = IPStringConversionException.class) public void testRejectMultipleZeroCompress() throws IPStringConversionException { IPv6.expand("1234::5678::FFFF", 8); }
@Test(expected = IPStringConversionException.class) public void testRejectInvalidHex() throws IPStringConversionException { IPv6.expand("1234:x:23::", 8); }
@Test(expected = IPStringConversionException.class) public void testRejectHexNot16bit() throws IPStringConversionException { IPv6.expand("fffff::", 8); }
@Test(expected = IPStringConversionException.class) public void testRejectTrailingNewline() throws IPStringConversionException { IPv6.expand(middle_compressed+"\n", 8); }
@Test public void testExpand() throws IPStringConversionException { IPv6 ip = new IPv6(ipv4Mixed_compressed); String expanded_str = ip.expand(); assertNotNull("Expected non null expanded ip string",expanded_str); assertTrue("Expected uncompressed ip to match ip.expand()",expanded_str.equals(ipv4Mixed_uncompressed)); }