IcePwdAttributeParser implements SdpParser<IcePwdAttribute> { @Override public IcePwdAttribute parse(String sdp) throws SdpException { try { int separator = sdp.indexOf(AttributeField.ATTRIBUTE_SEPARATOR); if(separator == -1) { throw new IllegalArgumentException("Attribute has no value"); } String password = sdp.trim().substring(separator + 1); if(password.isEmpty()) { throw new IllegalArgumentException("Value is empty"); } return new IcePwdAttribute(password); } catch (Exception e) { throw new SdpException(PARSE_ERROR + sdp, e); } }  @Override boolean canParse(String sdp); @Override IcePwdAttribute parse(String sdp); @Override void parse(IcePwdAttribute field, String sdp);  }
@Test public void testParse() throws SdpException { String sdp1 = "a=ice-pwd:P4ssW0rD\n\r"; IcePwdAttribute obj = parser.parse(sdp1); Assert.assertEquals("P4ssW0rD", obj.getPassword()); }
@Test public void testParseOverwrite() throws SdpException { String sdp1 = "a=ice-pwd:P4ssW0rD\n\r"; String sdp2 = "a=ice-pwd:N3wP4sS\n\r"; IcePwdAttribute obj = parser.parse(sdp1); parser.parse(obj, sdp2); Assert.assertEquals("N3wP4sS", obj.getPassword()); }
@Test(expected=SdpException.class) public void testParseMissingPassword() throws SdpException { String sdp1 = "a=ice-pwd:\n\r"; parser.parse(sdp1); }