MaxPacketTimeAttributeParser implements SdpParser<MaxPacketTimeAttribute> { @Override public MaxPacketTimeAttribute parse(String sdp) throws SdpException { try { int separator = sdp.indexOf(AttributeField.ATTRIBUTE_SEPARATOR); if(separator == -1) { throw new IllegalArgumentException("No value found"); } int value = Integer.parseInt(sdp.trim().substring(separator + 1)); return new MaxPacketTimeAttribute(value); } catch (Exception e) { throw new SdpException(PARSE_ERROR + sdp, e); } }  @Override boolean canParse(String sdp); @Override MaxPacketTimeAttribute parse(String sdp); @Override void parse(MaxPacketTimeAttribute field, String sdp);  }
@Test public void testParse() throws SdpException { String sdp1 = "a=maxptime:100\n\r"; MaxPacketTimeAttribute obj = parser.parse(sdp1); Assert.assertEquals("maxptime", obj.getKey()); Assert.assertEquals(100, obj.getTime()); Assert.assertEquals(sdp1.trim(), obj.toString()); }
@Test public void testParseOverwrite() throws SdpException { String sdp1 = "a=maxptime:100\n\r"; String sdp2 = "a=maxptime:123\n\r"; MaxPacketTimeAttribute obj = parser.parse(sdp1); parser.parse(obj, sdp2); Assert.assertEquals("maxptime", obj.getKey()); Assert.assertEquals(123, obj.getTime()); Assert.assertEquals(sdp2.trim(), obj.toString()); }
@Test(expected = SdpException.class) public void testParseInvalidTimeFormat() throws SdpException { String sdp1 = "a=maxptime:abc\n\r"; parser.parse(sdp1); }
@Test(expected = SdpException.class) public void testParseInexistentValue() throws SdpException { String sdp1 = "a=maxptime: "; parser.parse(sdp1); }