OriginFieldParser implements SdpParser<OriginField> { @Override public OriginField parse(String sdp) throws SdpException { try { String[] values = sdp.trim().substring(2).split(" "); String username = values[0]; String sessionId = values[1]; String sessionVersion = values[2]; String netType = values[3]; String addressType = values[4]; String address = values[5]; return new OriginField(username, sessionId, sessionVersion, netType, addressType, address); } catch (Exception e) { throw new SdpException(PARSE_ERROR + sdp, e); } }  @Override boolean canParse(String sdp); @Override OriginField parse(String sdp); @Override void parse(OriginField field, String sdp);  }
@Test public void testParse() throws SdpException { String line = "o=- 30 1 IN IP4 127.0.0.1\n\r"; OriginField field = parser.parse(line); Assert.assertEquals("-", field.getUsername()); Assert.assertEquals("30", field.getSessionId()); Assert.assertEquals("1", field.getSessionVersion()); Assert.assertEquals("IN", field.getNetType()); Assert.assertEquals("IP4", field.getAddressType()); Assert.assertEquals("127.0.0.1", field.getAddress()); }
@Test public void testParseOverwrite() throws SdpException { String line1 = "o=- 30 1 IN IP4 127.0.0.1\n\r"; String line2 = "o=xyz 40 2 IN IP6 0.0.0.0\n\r"; OriginField field = parser.parse(line1); parser.parse(field, line2); Assert.assertEquals("xyz", field.getUsername()); Assert.assertEquals("40", field.getSessionId()); Assert.assertEquals("2", field.getSessionVersion()); Assert.assertEquals("IN", field.getNetType()); Assert.assertEquals("IP6", field.getAddressType()); Assert.assertEquals("0.0.0.0", field.getAddress()); }
@Test(expected=SdpException.class) public void testInvalidParseMissingElement() throws SdpException { String line = "o=- 30 1 IN 127.0.0.1\n\r"; parser.parse(line); }