Source:
public void testClone() { PayloadTypePacketExtension p = new PayloadTypePacketExtension(); p.setId(101); p.setName("opus"); ParameterPacketExtension apt = new ParameterPacketExtension("apt", "100"); p.addParameter(apt); RtcpFbPacketExtension fb = new RtcpFbPacketExtension(); fb.setFeedbackType("nack"); fb.setFeedbackSubtype("pli"); p.addRtcpFeedbackType(fb); assertEquals(1, p.getRtcpFeedbackTypeList().size()); assertEquals(1, p.getParameters().size()); PayloadTypePacketExtension c = PayloadTypePacketExtension.clone(p); assertEquals(p.getChannels(), c.getChannels()); assertEquals(p.getName(), c.getName()); assertEquals(1, c.getParameters().size()); assertEquals(1, c.getRtcpFeedbackTypeList().size()); assertEquals(p.getID(), c.getID()); c.setChannels(2); assertEquals(1, p.getChannels()); assertEquals(2, c.getChannels()); c.setName("vp8"); assertEquals("opus", p.getName()); assertEquals("vp8", c.getName()); ParameterPacketExtension cApt = c.getParameters().get(0); assertTrue(apt != cApt); assertEquals(apt.getName(), cApt.getName()); assertEquals(apt.getValue(), cApt.getValue()); cApt.setName("stereo"); assertEquals("apt", apt.getName()); RtcpFbPacketExtension cFb = c.getRtcpFeedbackTypeList().get(0); assertTrue(fb != cFb); assertEquals(fb.getFeedbackType(), cFb.getFeedbackType()); assertEquals(fb.getFeedbackSubtype(), cFb.getFeedbackSubtype()); cFb.setFeedbackType("x1"); cFb.setFeedbackSubtype("x2"); assertEquals("nack", fb.getFeedbackType()); assertEquals("pli", fb.getFeedbackSubtype()); Set<String> attributeNames = new HashSet<>(p.getAttributeNames()); attributeNames.addAll(c.getAttributeNames()); attributeNames.remove(PayloadTypePacketExtension.CHANNELS_ATTR_NAME); attributeNames.remove(PayloadTypePacketExtension.ID_ATTR_NAME); attributeNames.remove(PayloadTypePacketExtension.NAME_ATTR_NAME); for (String s : attributeNames) { assertEquals(c.getAttribute(s), p.getAttribute(s)); } }

Target:
public void testClone() { PayloadTypePacketExtension p = new PayloadTypePacketExtension(); p.setId(101); p.setName("opus"); ParameterPacketExtension apt = new ParameterPacketExtension("apt", "100"); p.addParameter(apt); p.setAttribute(TEST_ATTR_NAME, TEST_ATTR_VALUE); RtcpFbPacketExtension fb = new RtcpFbPacketExtension(); fb.setFeedbackType("nack"); fb.setFeedbackSubtype("pli"); p.addRtcpFeedbackType(fb); PayloadTypePacketExtension c = PayloadTypePacketExtension.clone(p); assertEquals(p.getChannels(), c.getChannels()); assertEquals(p.getName(), c.getName()); assertEquals(1, c.getParameters().size()); assertEquals(1, c.getRtcpFeedbackTypeList().size()); assertEquals(p.getID(), c.getID()); c.setChannels(2); assertEquals(1, p.getChannels()); c.setName("vp8"); assertEquals("opus", p.getName()); ParameterPacketExtension cApt = c.getParameters().get(0); assertTrue(apt != cApt); assertEquals(apt.getName(), cApt.getName()); assertEquals(apt.getValue(), cApt.getValue()); cApt.setName("stereo"); assertEquals("apt", apt.getName()); RtcpFbPacketExtension cFb = c.getRtcpFeedbackTypeList().get(0); assertTrue(fb != cFb); assertEquals(fb.getFeedbackType(), cFb.getFeedbackType()); assertEquals(fb.getFeedbackSubtype(), cFb.getFeedbackSubtype()); cFb.setFeedbackType("x1"); cFb.setFeedbackSubtype("x2"); assertEquals("nack", fb.getFeedbackType()); assertEquals("pli", fb.getFeedbackSubtype()); Set<String> attributeNames = new HashSet<>(p.getAttributeNames()); attributeNames.addAll(c.getAttributeNames()); attributeNames.remove(PayloadTypePacketExtension.CHANNELS_ATTR_NAME); attributeNames.remove(PayloadTypePacketExtension.ID_ATTR_NAME); attributeNames.remove(PayloadTypePacketExtension.NAME_ATTR_NAME); for (String s : attributeNames) { assertEquals(c.getAttribute(s), p.getAttribute(s)); } c.setAttribute(TEST_ATTR_NAME, "WRONG"); assertEquals(p.getAttribute(TEST_ATTR_NAME), TEST_ATTR_VALUE); }