From eb51ac15f17e0dcaae8e9272f217b49393de13db Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Fri, 2 Oct 2015 17:49:09 -0700 Subject: [PATCH] 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. --- .../java/io/netty/buffer/ByteBufUtilTest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/buffer/src/test/java/io/netty/buffer/ByteBufUtilTest.java b/buffer/src/test/java/io/netty/buffer/ByteBufUtilTest.java index 9507d815b4..9cc68e22d4 100644 --- a/buffer/src/test/java/io/netty/buffer/ByteBufUtilTest.java +++ b/buffer/src/test/java/io/netty/buffer/ByteBufUtilTest.java @@ -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)); }