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:
parent
d4680c55d8
commit
67ddb61eca
@ -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));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user