@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 testSetsDataOnParserBeforeParsingHeader() {
    ByteBuffer data = ByteBuffer.allocate(1);
    when(gifDrawable.getBuffer()).thenReturn(data);

    GifHeader header = mock(GifHeader.class);
    when(parser.parseHeader()).thenReturn(header);

    encoder.encode(resource, file, options);

    InOrder order = inOrder(parser, decoder);
    order.verify(parser).setData(eq(data));
    order.verify(parser).parseHeader();
    order.verify(decoder).setData(header, data);
  }