CandidateAttributeParser implements SdpParser<CandidateAttribute> { @Override public boolean canParse(String sdp) { if(sdp == null || sdp.isEmpty()) { return false; } return PATTERN.matcher(sdp.trim()).matches(); }  @Override boolean canParse(String sdp); @Override CandidateAttribute parse(String sdp); @Override void parse(CandidateAttribute field, String sdp);  }
@Test public void testCanParse() { String validHost = "a=candidate:1995739850 1 udp 2113937151 192.168.1.65 54550 typ host generation 0\n\r"; String validHost2 = "a=candidate:xyz 1 udp 2113937151 192.168.1.65 54550 typ host generation 0\n\r"; String validHost3 = "a=candidate:9473510980 1 tcp 1518280447 192.168.1.65 0 typ host tcptype active generation 0"; String invalidHost2 = "a=candidate:1995739850 x udp 2113937151 192.168.1.65 54550 typ host generation 0\n\r"; String invalidHost3 = "a=candidate:1995739850 1 udp xyz 192.168.1.65 54550 typ host generation 0\n\r"; String validSrflx = "a=candidate:2162486046 1 udp 1845501695 85.241.121.60 60495 typ srflx raddr 192.168.1.65 rport 54550 generation 0\n\r"; String invalidSrflx1 = "a=candidate:2162486046 1 udp 1845501695 85.241.121.60 60495 typ srflx rport 54550 generation 0\n\r"; String invalidSrflx2 = "a=candidate:2162486046 1 udp 1845501695 85.241.121.60 60495 typ srflx raddr 192.168.1.65 generation 0\n\r"; String invalidSrflx3 = "a=candidate:2162486046 1 udp 1845501695 85.241.121.60 60495 typ srflx raddr 192.168.1.65 rport 54550\n\r"; String validRelay = "a=candidate:2564697628 1 udp 33562367 75.126.93.124 53056 typ relay raddr 85.241.121.60 rport 55027 generation 0\n\r"; Assert.assertTrue(parser.canParse(validHost)); Assert.assertTrue(parser.canParse(validHost2)); Assert.assertTrue(parser.canParse(validHost3)); Assert.assertFalse(parser.canParse(invalidHost2)); Assert.assertFalse(parser.canParse(invalidHost3)); Assert.assertTrue(parser.canParse(validSrflx)); Assert.assertFalse(parser.canParse(invalidSrflx1)); Assert.assertFalse(parser.canParse(invalidSrflx2)); Assert.assertFalse(parser.canParse(invalidSrflx3)); Assert.assertTrue(parser.canParse(validRelay)); }