### Question:
Connection implements Cloneable { public static Connection parse(String line) throws ParseException { Matcher m = parsePattern.matcher(line); if (!m.find()) throw new ParseException("not a valid connection record", 0); Connection result = null; String tmp; try { InetAddress addr = InetAddress.getByName(m.group(3)); result = new Connection(addr); result.setNetworkType(m.group(1)); tmp = m.group(5); if (tmp != null && tmp.length() > 0) result.setTtl(Integer.parseInt(tmp)); tmp = m.group(7); if (tmp != null && tmp.length() > 0) result.setNumOfAddresses(Integer.parseInt(tmp)); } catch (UnknownHostException ex) { throw (ParseException) new ParseException("not a valid connection record", 0).initCause(ex); } return result; } Connection(InetAddress address); InetAddress getAddress(); void setAddress(InetAddress address); String getNetworkType(); void setNetworkType(String networkType); String getAddressType(); int getNumOfAddresses(); void setNumOfAddresses(int numOfAddresses); int getTtl(); void setTtl(int ttl); @Override String toString(); @Override Connection clone(); static Connection parse(String line); static final String NETWORK_TYPE_INTERNET; }### Answer:
@Test public void testParse() throws ParseException { System.out.println("SDP connection parse test..."); String[] cons = new String[] { "c=IN IP4 127.0.0.1/10/20", "c=IN IP4 127.0.0.1/10", "c=IN IP4 127.0.0.1", "c=IN\tIP4\t127.0.0.1", " c=IN IP4 127.0.0.1", "c =IN IP4 127.0.0.1", "c = IN IP4 127.0.0.1", "c= IN IP4 127.0.0.1", "c=IN 127.0.0.1", "c=IN IP4 127.0.0.1/", "c=IN IP4 127.0.0.1/10/", }; int i = 0; Connection c = Connection.parse(cons[i++]); assertEquals("IN", c.getNetworkType()); assertEquals("IP4", c.getAddressType()); assertEquals("127.0.0.1", c.getAddress().getHostAddress()); assertEquals(10, c.getTtl()); assertEquals(20, c.getNumOfAddresses()); c = Connection.parse(cons[i++]); assertEquals("IN", c.getNetworkType()); assertEquals("IP4", c.getAddressType()); assertEquals("127.0.0.1", c.getAddress().getHostAddress()); assertEquals(10, c.getTtl()); assertEquals(1, c.getNumOfAddresses()); c = Connection.parse(cons[i++]); assertEquals("IN", c.getNetworkType()); assertEquals("IP4", c.getAddressType()); assertEquals("127.0.0.1", c.getAddress().getHostAddress()); assertEquals(1, c.getTtl()); assertEquals(1, c.getNumOfAddresses()); c = Connection.parse(cons[i++]); assertEquals("IN", c.getNetworkType()); assertEquals("IP4", c.getAddressType()); assertEquals("127.0.0.1", c.getAddress().getHostAddress()); assertEquals(1, c.getTtl()); assertEquals(1, c.getNumOfAddresses()); for (; i < cons.length; i++) { try { Connection.parse(cons[i]); fail("connection: \"" + cons[i] + "\" parsed without an exception"); } catch (ParseException ex) { } } }