// NB: This method assumes
 // base == target.base
 // offset == target.offset
 // values.length == target.length
 private void doTestSet(byte[] base, int offset, ByteArray target, byte[] values) {
   for (int i = 0; i < values.length; ++i) {
     target.set(i, values[i]);
     assertEquals("Set wrong value [index = " + i + "].", values[i], target.get(i));
     assertEquals(
         "Didn't set value in original base array " + "[index = " + i + "].",
         values[i],
         base[offset + i]);
   }
 }
  private void doTestSetBufferBoundaryCases(ByteArray target) {
    try {
      target.set(0, null); // Null always checked b/f index.
      fail("Shouldn't accept null.");
    } catch (NullPointerException npe) {
    }
    target.set(0, new byte[] {}); // buf.len == 0 always checked b/f
    // index.

    byte[] values = new byte[] {25, -1};
    if (target.length == 0) {
      try {
        target.set(0, values);
        fail("Shouldn't accept index 0 if length is 0.");
      } catch (ArrayIndexOutOfBoundsException aiobe) {
      }
    }
    try {
      target.set(-1, values);
      fail("Shouldn't accept negative index.");
    } catch (ArrayIndexOutOfBoundsException aiobe) {
    }
    try {
      target.set(target.length, values);
      fail("Shouldn't accept index greater than length-1.");
    } catch (ArrayIndexOutOfBoundsException aiobe) {
    }
    if (0 < target.length) {
      byte original = target.get(target.length - 1);
      values[0] = (byte) (original + 1);
      try {
        target.set(target.length - 1, values);
        fail("Shouldn't accept a buffer that doesn't fit " + "into the slice.");
      } catch (ArrayIndexOutOfBoundsException aiobe) {
        // Ok, but check that no value has been copied:
        assertEquals(
            "No value should be copied if the buffer " + "doesn't fit into the slice.",
            original,
            target.get(target.length - 1));
      }
    }
  }
 // NB: This method assumes
 // base == target.base
 // offset == target.offset
 // offset+index+values.length <= target.length
 // valuesToCheck <= values.length
 private void verifySetStream(
     byte[] base, int offset, int index, ByteArray target, int valuesToCheck) {
   for (int i = 0; i < valuesToCheck; ++i) {
     assertEquals("Set wrong value [index = " + i + "].", 1, target.get(index + i));
     assertEquals(
         "Didn't set value in original base array " + "[index = " + i + "].",
         1,
         base[offset + index + i]);
   }
   // NOTE: expected value is 1 b/c mock read writes 1 into the buffer.
 }