### Question:
AbstractByteBufAllocator implements ByteBufAllocator { @Override public int calculateNewCapacity(int minNewCapacity, int maxCapacity) { checkPositiveOrZero(minNewCapacity, "minNewCapacity"); if (minNewCapacity > maxCapacity) { throw new IllegalArgumentException(String.format( "minNewCapacity: %d (expected: not greater than maxCapacity(%d)", minNewCapacity, maxCapacity)); } final int threshold = CALCULATE_THRESHOLD; if (minNewCapacity == threshold) { return threshold; } if (minNewCapacity > threshold) { int newCapacity = minNewCapacity / threshold * threshold; if (newCapacity > maxCapacity - threshold) { newCapacity = maxCapacity; } else { newCapacity += threshold; } return newCapacity; } int newCapacity = 64; while (newCapacity < minNewCapacity) { newCapacity <<= 1; } return Math.min(newCapacity, maxCapacity); } protected  AbstractByteBufAllocator(); protected  AbstractByteBufAllocator(boolean preferDirect); @Override ByteBuf buffer(); @Override ByteBuf buffer(int initialCapacity); @Override ByteBuf buffer(int initialCapacity, int maxCapacity); @Override ByteBuf ioBuffer(); @Override ByteBuf ioBuffer(int initialCapacity); @Override ByteBuf ioBuffer(int initialCapacity, int maxCapacity); @Override ByteBuf heapBuffer(); @Override ByteBuf heapBuffer(int initialCapacity); @Override ByteBuf heapBuffer(int initialCapacity, int maxCapacity); @Override ByteBuf directBuffer(); @Override ByteBuf directBuffer(int initialCapacity); @Override ByteBuf directBuffer(int initialCapacity, int maxCapacity); @Override CompositeByteBuf compositeBuffer(); @Override CompositeByteBuf compositeBuffer(int maxNumComponents); @Override CompositeByteBuf compositeHeapBuffer(); @Override CompositeByteBuf compositeHeapBuffer(int maxNumComponents); @Override CompositeByteBuf compositeDirectBuffer(); @Override CompositeByteBuf compositeDirectBuffer(int maxNumComponents); @Override String toString(); @Override int calculateNewCapacity(int minNewCapacity, int maxCapacity);  }### Answer:
@Test public void testCalculateNewCapacity() { testCalculateNewCapacity(true); testCalculateNewCapacity(false); }