private void testByteRangeCreationLastNBytes(long lastNBytes, boolean expectSuccess) throws Exception {
    List<LongFunction<ByteRange>> factories = Arrays.asList(ByteRange::fromLastNBytes, ByteRanges::fromLastNBytes);
    for (LongFunction<ByteRange> factory : factories) {
      if (expectSuccess) {
        ByteRange byteRange = factory.apply(lastNBytes);
        assertEquals("Wrong range type", ByteRange.ByteRangeType.LAST_N_BYTES, byteRange.getType());
        assertEquals("Wrong lastNBytes", lastNBytes, byteRange.getLastNBytes());
        assertEquals("Wrong range size", lastNBytes, byteRange.getRangeSize());
        TestUtils.assertException(UnsupportedOperationException.class, byteRange::getStartOffset, null);
        TestUtils.assertException(UnsupportedOperationException.class, byteRange::getEndOffset, null);
      } else {
        TestUtils.assertException(IllegalArgumentException.class, () -> factory.apply(lastNBytes), null);
      }
    }
  }
Test that {@link ByteRange} works as expected for byte ranges encoding the number of bytes to read from the end
of an object.
@param lastNBytes the number of bytes to read from the end of an object.
@param expectSuccess {@code true} if the {@link ByteRange} creation should succeed.
@throws Exception
ambry-api/src/test/java/com/github/ambry/router/ByteRangeTest.java