ConnectionModeAttributeParser implements SdpParser<ConnectionModeAttribute> { @Override public ConnectionModeAttribute parse(String sdp) throws SdpException { try { String mode = sdp.trim().substring(2); if (!isTypeValid(mode)) { throw new IllegalArgumentException("Unknown connection mode"); } return new ConnectionModeAttribute(mode); } catch (Exception e) { throw new SdpException(PARSE_ERROR + sdp, e); } }  @Override boolean canParse(String sdp); @Override ConnectionModeAttribute parse(String sdp); @Override void parse(ConnectionModeAttribute field, String sdp);  }
@Test public void testParseSendOnly() throws SdpException { String sdp1 = "a=sendonly\n\r"; ConnectionModeAttribute obj = parser.parse(sdp1); Assert.assertEquals(ConnectionModeAttribute.SENDONLY, obj.getKey()); Assert.assertEquals("sendonly", obj.getKey()); }
@Test public void testParseRecvOnly() throws SdpException { String sdp1 = "a=recvonly\n\r"; AbstractConnectionModeAttribute obj = parser.parse(sdp1); Assert.assertEquals(ConnectionModeAttribute.RECVONLY, obj.getKey()); Assert.assertEquals("recvonly", obj.getKey()); }
@Test public void testParseSendRecv() throws SdpException { String sdp1 = "a=sendrecv\n\r"; AbstractConnectionModeAttribute obj = parser.parse(sdp1); Assert.assertEquals(ConnectionModeAttribute.SENDRECV, obj.getKey()); Assert.assertEquals("sendrecv", obj.getKey()); }
@Test public void testParseInactive() throws SdpException { String sdp1 = "a=inactive\n\r"; AbstractConnectionModeAttribute obj = parser.parse(sdp1); Assert.assertEquals(ConnectionModeAttribute.INACTIVE, obj.getKey()); Assert.assertEquals("inactive", obj.getKey()); }
@Test public void testParseOverwrite() throws SdpException { String sdp1 = "a=inactive\n\r"; String sdp2 = "a=recvonly\n\r"; ConnectionModeAttribute obj = parser.parse(sdp1); parser.parse(obj, sdp2); Assert.assertEquals(ConnectionModeAttribute.RECVONLY, obj.getKey()); Assert.assertEquals("recvonly", obj.getKey()); }