### Question:
UnsynchronizedBuffer { public static int nextArraySize(int i) { if (i < 0) throw new IllegalArgumentException(); if (i > (1 << 30)) { return Integer.MAX_VALUE - 8; } if (i == 0) { return 1; } int ret = i; ret--; ret |= ret >> 1; ret |= ret >> 2; ret |= ret >> 4; ret |= ret >> 8; ret |= ret >> 16; ret++; return ret; }  static int nextArraySize(int i); static void writeVInt(DataOutput out, byte[] workBuffer, int i); static void writeVLong(DataOutput out, byte[] workBuffer, long i); static int writeVInt(byte[] dest, int offset, int i); static int writeVLong(byte[] dest, int offset, long value);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testNextArraySizeNegative() { UnsynchronizedBuffer.nextArraySize(-1); }
@Test public void testNextArraySize() { assertEquals(1, UnsynchronizedBuffer.nextArraySize(0)); assertEquals(1, UnsynchronizedBuffer.nextArraySize(1)); assertEquals(2, UnsynchronizedBuffer.nextArraySize(2)); for (int exp = 1; exp < 30; ++exp) { int nextExp = exp + 1; assertEquals(1 << nextExp, UnsynchronizedBuffer.nextArraySize((1 << exp) + 1)); assertEquals(1 << nextExp, UnsynchronizedBuffer.nextArraySize(1 << nextExp)); } assertEquals(Integer.MAX_VALUE - 8, UnsynchronizedBuffer.nextArraySize((1 << 30) + 1)); assertEquals(Integer.MAX_VALUE - 8, UnsynchronizedBuffer.nextArraySize(Integer.MAX_VALUE - 9)); assertEquals(Integer.MAX_VALUE - 8, UnsynchronizedBuffer.nextArraySize(Integer.MAX_VALUE - 8)); assertEquals(Integer.MAX_VALUE - 8, UnsynchronizedBuffer.nextArraySize(Integer.MAX_VALUE)); }