### Question:
OerLengthSerializer { public static void writeLength(final int length, final OutputStream outputStream) throws IOException { Objects.requireNonNull(outputStream); if (length <= 0) { outputStream.write(0); } else { if (length >= 0 && length < 128) { outputStream.write(length); } else { if (length <= 127) { outputStream.write(length); } else if (length <= 255) { outputStream.write(128 + 1); outputStream.write(length); } else if (length <= 65535) { outputStream.write(128 + 2); outputStream.write((length >> 8)); outputStream.write(length); } else if (length <= 16777215) { outputStream.write(128 + 3); outputStream.write((length >> 16)); outputStream.write((length >> 8)); outputStream.write(length); } else { outputStream.write(128 + 4); outputStream.write((length >> 24)); outputStream.write((length >> 16)); outputStream.write((length >> 8)); outputStream.write(length); } } } }  static int readLength(final InputStream inputStream); static void writeLength(final int length, final OutputStream outputStream);  }### Answer:
@Test public void write() throws Exception { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); OerLengthSerializer.writeLength(expectedPayloadLength, outputStream); assertThat(this.asn1OerBytes).isEqualTo(outputStream.toByteArray()); }
@Test public void writeNegativeLength() throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); OerLengthSerializer.writeLength(Integer.MIN_VALUE, outputStream); assertThat(BaseEncoding.base16().decode("00")).isEqualTo(outputStream.toByteArray()); outputStream = new ByteArrayOutputStream(); OerLengthSerializer.writeLength(-1, outputStream); assertThat(BaseEncoding.base16().decode("00")).isEqualTo(outputStream.toByteArray()); }