@Test
public void testMerge() {
DestinationSequence seq = new DestinationSequence(id, ref, destination);
List<AcknowledgementRange> ranges = seq.getAcknowledgment().getAcknowledgementRange();
AcknowledgementRange r;
for (int i = 0; i < 5; i++) {
r = new AcknowledgementRange();
r.setLower(new BigInteger(Integer.toString(3 * i + 1)));
r.setUpper(new BigInteger(Integer.toString(3 * i + 3)));
ranges.add(r);
}
seq.mergeRanges();
assertEquals(1, ranges.size());
r = ranges.get(0);
assertEquals(BigInteger.ONE, r.getLower());
assertEquals(new BigInteger("15"), r.getUpper());
ranges.clear();
for (int i = 0; i < 5; i++) {
r = new AcknowledgementRange();
r.setLower(new BigInteger(Integer.toString(3 * i + 1)));
r.setUpper(new BigInteger(Integer.toString(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 BigInteger(Integer.toString(3 * i + 1)));
r.setUpper(new BigInteger(Integer.toString(3 * i + 3)));
ranges.add(r);
}
}
seq.mergeRanges();
assertEquals(2, ranges.size());
r = ranges.get(0);
assertEquals(BigInteger.ONE, r.getLower());
assertEquals(new BigInteger("6"), r.getUpper());
r = ranges.get(1);
assertEquals(BigInteger.TEN, r.getLower());
assertEquals(new BigInteger("15"), r.getUpper());
}