@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 testAdvancesDecoderBeforeAttemptingToGetFirstFrame() {
    when(gifEncoder.start(any(OutputStream.class))).thenReturn(true);
    when(decoder.getFrameCount()).thenReturn(1);
    when(decoder.getNextFrame()).thenReturn(Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888));

    encoder.encode(resource, file, options);

    InOrder order = inOrder(decoder);
    order.verify(decoder).advance();
    order.verify(decoder).getNextFrame();
  }