@Nullable
  public static Extractor getExtractorInstance(
      @NonNull Context context,
      @NonNull File file,
      @NonNull String outputPath,
      @NonNull Extractor.OnUpdate listener,
      @NonNull UpdatePosition updatePosition) {
    Extractor extractor;
    String type = getExtension(file.getPath());

    if (isZip(type)) {
      extractor = new ZipExtractor(context, file.getPath(), outputPath, listener, updatePosition);
    } else if (BuildConfig.FLAVOR.equals("play") && isRar(type)) {
      extractor = new RarExtractor(context, file.getPath(), outputPath, listener, updatePosition);
    } else if (isTar(type)) {
      extractor = new TarExtractor(context, file.getPath(), outputPath, listener, updatePosition);
    } else if (isGzippedTar(type)) {
      extractor = new TarGzExtractor(context, file.getPath(), outputPath, listener, updatePosition);
    } else if (isBzippedTar(type)) {
      extractor =
          new TarBzip2Extractor(context, file.getPath(), outputPath, listener, updatePosition);
    } else if (isXzippedTar(type)) {
      extractor = new TarXzExtractor(context, file.getPath(), outputPath, listener, updatePosition);
    } else if (isLzippedTar(type)) {
      extractor =
          new TarLzmaExtractor(context, file.getPath(), outputPath, listener, updatePosition);
    } else if (is7zip(type)) {
      extractor =
          new SevenZipExtractor(context, file.getPath(), outputPath, listener, updatePosition);
    } else if (isLzma(type)) {
      extractor = new LzmaExtractor(context, file.getPath(), outputPath, listener, updatePosition);
    } else if (isXz(type)) {
      extractor = new XzExtractor(context, file.getPath(), outputPath, listener, updatePosition);
    } else if (isGzip(type)) {
      extractor = new GzipExtractor(context, file.getPath(), outputPath, listener, updatePosition);
    } else if (isBzip2(type)) {
      extractor = new Bzip2Extractor(context, file.getPath(), outputPath, listener, updatePosition);
    } else {
      if (BuildConfig.DEBUG) {
        throw new IllegalArgumentException("The compressed file has no way of opening it: " + file);
      }
      LOG.error("The compressed file has no way of opening it: " + file);
      extractor = null;
    }

    return extractor;
  }
@Test
  public void getExtractorInstance() {
    UpdatePosition updatePosition = ServiceWatcherUtil.UPDATE_POSITION;

    File file = new File("/test/test.zip"); // .zip used by ZipExtractor
    Extractor result =
        CompressedHelper.getExtractorInstance(
            context, file, "/test2", emptyUpdateListener, updatePosition);
    assertEquals(result.getClass(), ZipExtractor.class);
    file = new File("/test/test.jar"); // .jar used by ZipExtractor
    result =
        CompressedHelper.getExtractorInstance(
            context, file, "/test2", emptyUpdateListener, updatePosition);
    assertEquals(result.getClass(), ZipExtractor.class);
    file = new File("/test/test.apk"); // .apk used by ZipExtractor
    result =
        CompressedHelper.getExtractorInstance(
            context, file, "/test2", emptyUpdateListener, updatePosition);
    assertEquals(result.getClass(), ZipExtractor.class);
    file = new File("/test/test.tar"); // .tar used by TarExtractor
    result =
        CompressedHelper.getExtractorInstance(
            context, file, "/test2", emptyUpdateListener, updatePosition);
    assertEquals(result.getClass(), TarExtractor.class);
    file = new File("/test/test.tar.gz"); // .tar.gz used by GzipExtractor
    result =
        CompressedHelper.getExtractorInstance(
            context, file, "/test2", emptyUpdateListener, updatePosition);
    assertEquals(result.getClass(), TarGzExtractor.class);
    file = new File("/test/test.tgz"); // .tgz used by GzipExtractor
    result =
        CompressedHelper.getExtractorInstance(
            context, file, "/test2", emptyUpdateListener, updatePosition);
    assertEquals(result.getClass(), TarGzExtractor.class);
    if (BuildConfig.FLAVOR == "play") {
      file = new File("/test/test.rar"); // .rar used by RarExtractor
      result =
          CompressedHelper.getExtractorInstance(
              context, file, "/test2", emptyUpdateListener, updatePosition);
      assertEquals(result.getClass(), RarExtractor.class);
    }
    file = new File("/test/test.tar.bz2"); // .rar used by RarExtractor
    result =
        CompressedHelper.getExtractorInstance(
            context, file, "/test2", emptyUpdateListener, updatePosition);
    assertEquals(result.getClass(), TarBzip2Extractor.class);
    file = new File("/test/test.tbz"); // .rar used by RarExtractor
    result =
        CompressedHelper.getExtractorInstance(
            context, file, "/test2", emptyUpdateListener, updatePosition);
    assertEquals(result.getClass(), TarBzip2Extractor.class);
    file = new File("/test/test.7z");
    result =
        CompressedHelper.getExtractorInstance(
            context, file, "/test2", emptyUpdateListener, updatePosition);
    assertEquals(result.getClass(), SevenZipExtractor.class);
    file = new File("/test/test.tar.xz");
    result =
        CompressedHelper.getExtractorInstance(
            context, file, "/test2", emptyUpdateListener, updatePosition);
    assertEquals(result.getClass(), TarXzExtractor.class);
    file = new File("/test/test.tar.lzma");
    result =
        CompressedHelper.getExtractorInstance(
            context, file, "/test2", emptyUpdateListener, updatePosition);
    assertEquals(result.getClass(), TarLzmaExtractor.class);
  }