@Override
  public boolean encode(
      @NonNull Resource<GifDrawable> resource, @NonNull File file, @NonNull Options options) {
    GifDrawable drawable = resource.get();
    Transformation<Bitmap> transformation = drawable.getFrameTransformation();
    boolean isTransformed = !(transformation instanceof UnitTransformation);
    if (isTransformed && options.get(ENCODE_TRANSFORMATION)) {
      return encodeTransformedToFile(drawable, file);
    } else {
      return writeDataDirect(drawable.getBuffer(), file);
    }
  }
@Test
  public void testWritesBytesDirectlyToDiskIfTransformationIsUnitTransformation() {
    when(gifDrawable.getFrameTransformation()).thenReturn(UnitTransformation.<Bitmap>get());
    String expected = "expected";
    when(gifDrawable.getBuffer()).thenReturn(ByteBuffer.wrap(expected.getBytes()));

    encoder.encode(resource, file, options);

    assertThat(getEncodedData()).isEqualTo(expected);

    verify(gifEncoder, never()).start(any(OutputStream.class));
    verify(parser, never()).setData(any(byte[].class));
    verify(parser, never()).parseHeader();
  }