@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 testReturnsFalseIfFinishingFails() {
    when(gifEncoder.start(any(OutputStream.class))).thenReturn(true);
    when(gifEncoder.finish()).thenReturn(false);

    assertFalse(encoder.encode(resource, file, options));
  }