private static void assertEquals(byte[] expected, byte[] actual) { assertThat(actual).isEqualTo(expected); } }
private static void testDecodes(BaseEncoding encoding, String encoded, String decoded) { assertTrue(encoding.canDecode(encoded)); assertThat(encoding.decode(encoded)).isEqualTo(decoded.getBytes(UTF_8)); }
@Test public void write_withEmptyBuffer_andDataEqualToBufferSize_writesDataToStream() throws IOException { os.write(next(bufferSize)); assertThat(inner.toByteArray()).isEqualTo(all()); }
@Test public void close_withSingleByteInBuffer_writesBufferToStream() throws IOException { os.write(next()); os.close(); assertThat(inner.toByteArray()).isEqualTo(all()); }
@Test public void write_withBufferGreaterThanRemaining_lessThanLength_writesUpToBufferToStream() throws IOException { os.write(next(2)); os.write(next(bufferSize - 1)); assertThat(inner.toByteArray()).isEqualTo(upTo(bufferSize)); }
@Test public void write_withOffsetBufferGreaterThanRemaining_lessThanLength_writesUpToBuffer() throws IOException { os.write(next(2)); int offset = 5; int length = bufferSize - 1; os.write(nextWithOffset(offset, length), offset, length); assertThat(inner.toByteArray()).isEqualTo(upTo(bufferSize)); }
@Test public void write_withOffsetBufferGreaterThanRemaining_equalToLength_writesUpToBufferToStream() throws IOException { os.write(next(2)); int offset = 6; int length = bufferSize; os.write(nextWithOffset(offset, length), offset, length); assertThat(inner.toByteArray()).isEqualTo(upTo(bufferSize)); }
@Test public void write_withOffsetBufferGreaterThanRemaining_greaterThanLength_writesUpToBuffer() throws IOException { os.write(next(2)); int offset = 2; int length = bufferSize + 1; os.write(nextWithOffset(offset, length), offset, length); assertThat(inner.toByteArray()).isEqualTo(upTo(bufferSize)); }
@Test public void write_withPaddedBufferGreaterThanRemaining_greaterThanLength_writesUpToBuffer() throws IOException { os.write(next(2)); int padding = 2; int length = bufferSize + 1; os.write(nextWithPadding(length, padding), 0, length); assertThat(inner.toByteArray()).isEqualTo(upTo(bufferSize)); }
@Test public void testEncoderEncodesPngWithNullFormatAndBitmapWithAlpha() throws IOException { harness.setFormat(null); harness.bitmap.setHasAlpha(true); assertThat(harness.encode()).isEqualTo(harness.expectedData(CompressFormat.PNG, 90)); }
@Test public void write_withPaddedBufferEqualToRemaining_lessThanLength_writesToStream() throws IOException { os.write(next()); int padding = 5; int length = remaining(); os.write(nextWithPadding(length, padding), 0, length); assertThat(inner.toByteArray()).isEqualTo(all()); }
@Test public void close_afterWriteOffsetBufferMoreThanRemains_greaterThanTwiceLength_writesAll() throws IOException { os.write(next(2)); int offset = bufferSize + 1; int length = bufferSize * 2 + 2; os.write(nextWithOffset(offset, length), offset, length); os.close(); assertThat(inner.toByteArray()).isEqualTo(all()); }
@Test public void close_afterWritePaddedBufferMoreThanRemains_greaterThanTwiceLength_writesAll() throws IOException { os.write(next(2)); int padding = bufferSize + 1; int length = bufferSize * 2 + 2; os.write(nextWithPadding(length, padding), 0, length); os.close(); assertThat(inner.toByteArray()).isEqualTo(all()); }
@Test public void close_afterWriteBufferGreaterThanRemaining_lessThanLength_writesAll() throws IOException { os.write(next(2)); os.write(next(bufferSize - 1)); os.close(); assertThat(inner.toByteArray()).isEqualTo(all()); }
@Test public void close_afterWritePaddedBufferGreaterThanRemaining_lessThanLength_writesAll() throws IOException { os.write(next(2)); int padding = 5; int length = bufferSize - 1; os.write(nextWithPadding(length, padding), 0, length); os.close(); assertThat(inner.toByteArray()).isEqualTo(all()); }
@Test public void close_afterWriteBufferGreaterThanRemaining_greaterThanLength_writesAll() throws IOException { os.write(next(2)); os.write(next(bufferSize + 1)); os.close(); assertThat(inner.toByteArray()).isEqualTo(all()); }
@Test public void flush_afterWriteBufferMoreThanRemains_greaterThanTwiceLength_writesAll() throws IOException { os.write(next(2)); os.write(next(bufferSize * 2 + 1)); os.flush(); assertThat(inner.toByteArray()).isEqualTo(all()); }
@Test public void closeAfterPreviousFlush_withSingleByte_writesOnlySingleByte() throws IOException { os.write(next()); os.flush(); os.write(next()); os.close(); assertThat(inner.toByteArray()).isEqualTo(all()); }
@Test public void close_afterWriteBufferEqualToRemaining_doesNothing() throws IOException { os.write(next()); os.write(next(remaining())); os.close(); assertThat(inner.toByteArray()).isEqualTo(all()); }
@Test public void flush_afterWriteBufferEqualToRemaining_doesNothing() throws IOException { os.write(next()); os.write(next(remaining())); os.flush(); assertThat(inner.toByteArray()).isEqualTo(all()); }