ByteBufUtilTest test failure

Motivation:
ByteBufUtilTest.notEqualsBufferSubsections is testing non-equality but just uses random numbers to assume they will not be equal. Even after the random bytes are generated we should check they are infact not equal so the test has no chance of failing when it should not.

Modifications:
- Loop through bytes in notEqualsBufferSubsections after they are randomly generated to ensure there is atleast 1 difference.

Result:
More reliable unit tests.
This commit is contained in:
Scott Mitchell 2015-10-02 17:49:09 -07:00
parent 6d9aff28e2
commit eb51ac15f1

View File

@ -52,7 +52,20 @@ public class ByteBufUtilTest {
final int iB1 = b1.length / 2;
final int iB2 = iB1 + b1.length;
final int length = b1.length - iB1;
System.arraycopy(b1, iB1, b2, iB2, length - 1);
// Even though we choose random values...make sure they are not equal.
final int copyLength = length - 1;
final int end = iB1 + copyLength;
boolean foundDiff = false;
for (int i = iB1, j = iB2; i < end; ++i, ++j) {
if (b1[i] != b2[j]) {
foundDiff = true;
break;
}
}
if (!foundDiff) {
++b1[iB1];
}
System.arraycopy(b1, iB1, b2, iB2, copyLength);
assertFalse(ByteBufUtil.equals(Unpooled.wrappedBuffer(b1), iB1, Unpooled.wrappedBuffer(b2), iB2, length));
}