ConnectionFieldParser implements SdpParser<ConnectionField> { @Override public ConnectionField parse(String sdp) throws SdpException { try { String[] values = sdp.trim().substring(2).split(" "); String networkType = values[0]; String addressType = values[1]; String address = values[2]; return new ConnectionField(networkType, addressType, address); } catch (Exception e) { throw new SdpException(PARSE_ERROR + sdp, e); } }  @Override boolean canParse(String sdp); @Override ConnectionField parse(String sdp); @Override void parse(ConnectionField field, String sdp);  }
@Test public void testValidParse() throws SdpException { String line = "c=IN IP6 0.0.0.0\n\r"; ConnectionField connection = parser.parse(line); Assert.assertEquals("IN", connection.getNetworkType()); Assert.assertEquals("IP6", connection.getAddressType()); Assert.assertEquals("0.0.0.0", connection.getAddress()); }
@Test public void testValidParseOverwrite() throws SdpException { String line1 = "c=IN IP6 0.0.0.0\n\r"; String line2 = "c=IN IP4 127.0.0.1\n\r"; ConnectionField connection = parser.parse(line1); parser.parse(connection, line2); Assert.assertEquals("IN", connection.getNetworkType()); Assert.assertEquals("IP4", connection.getAddressType()); Assert.assertEquals("127.0.0.1", connection.getAddress()); }
@Test(expected = SdpException.class) public void testInvalidParseMissingElement() throws SdpException { String line = "o=IN 127.0.0.1\n\r"; parser.parse(line); }