@Test
public void testMerge() {
DestinationSequence seq = new DestinationSequence(id, ref, destination,
ProtocolVariation.RM10WSA200408);
List<AcknowledgementRange> ranges = seq.getAcknowledgment().getAcknowledgementRange();
AcknowledgementRange r;
for (int i = 0; i < 5; i++) {
r = new AcknowledgementRange();
r.setLower(new Long(3 * i + 1));
r.setUpper(new Long(3 * i + 3));
ranges.add(r);
}
seq.mergeRanges();
assertEquals(1, ranges.size());
r = ranges.get(0);
assertEquals(new Long(1), r.getLower());
assertEquals(new Long(15), r.getUpper());
ranges.clear();
for (int i = 0; i < 5; i++) {
r = new AcknowledgementRange();
r.setLower(new Long(3 * i + 1));
r.setUpper(new Long(3 * i + 2));
ranges.add(r);
}
seq.mergeRanges();
assertEquals(5, ranges.size());
ranges.clear();
for (int i = 0; i < 5; i++) {
if (i != 2) {
r = new AcknowledgementRange();
r.setLower(new Long(3 * i + 1));
r.setUpper(new Long(3 * i + 3));
ranges.add(r);
}
}
seq.mergeRanges();
assertEquals(2, ranges.size());
r = ranges.get(0);
assertEquals(new Long(1), r.getLower());
assertEquals(new Long(6), r.getUpper());
r = ranges.get(1);
assertEquals(new Long(10), r.getLower());
assertEquals(new Long(15), r.getUpper());
}