### Question:
Packet implements Freezable<Packet>, Sizeable { @Override public Packet clone() { Packet clone = new Packet(); clone.transmissionAck = transmissionAck; clone.precedingTransmissionAcks = precedingTransmissionAcks; for (int i = 0, l = segments.size(); i < l; ++i) clone.addLastSegment(segments.get(i).clone()); return clone; } Packet(); List<Segment> getSegments(); Segment getFirstSegment(); Segment getLastSegment(); Short getTransmissionAck(); long getPrecedingTransmissionAcks(); @Override String toString(); String toDebugString(); static void writeExternalStatic(Packet packet, ObjectOutput out); static Packet readExternalStatic(ObjectInput in); @Override void writeExternal(ObjectOutput out); @Override void readExternal(ObjectInput in); @Override Packet clone(); @Override int getSize(); static final transient int MAX_DATAS_PER_PACKET; }### Answer:
@Test @Parameters public final void testClone(Short ack, Integer lastAcks) throws Exception { Packet original = new Packet(); original.setTransmissionAck(ack); original.setPrecedingTransmissionAcks(lastAcks); Segment segment = new Segment(); Deencapsulation.setField(segment, "dataId", Short.MIN_VALUE); Deencapsulation.invoke(segment, "addTransmissionId", Short.MIN_VALUE); original.addLastSegment(segment); Packet clone = original.clone(); assertEquals("ack mismatch", original.getTransmissionAck(), clone.getTransmissionAck()); assertEquals("lastAck mismatch", original.getPrecedingTransmissionAcks(), clone.getPrecedingTransmissionAcks()); assertNotSame("datas are different objects", original.getFirstSegment(), clone.getFirstSegment()); original.setTransmissionAck((short) -1); original.setPrecedingTransmissionAcks(-1); original.addLastSegment(new Segment()); assertEquals("Original ack did change", (short) -1, original.getTransmissionAck().shortValue()); assertEquals("Original lastAck did change", -1, original.getPrecedingTransmissionAcks()); assertEquals("Original segments size did change", 2, original.getSegments().size()); assertEquals("Cloned ack did not change", ack.shortValue(), clone.getTransmissionAck().shortValue()); assertEquals("Cloned lastAck did not change", lastAcks.intValue(), clone.getPrecedingTransmissionAcks()); assertEquals("Cloned datas size did not change", 1, clone.getSegments().size()); }