public void rename(
      Iterable<String> srcFilenames, Iterable<String> destFilenames, MoveOptions... moveOptions)
      throws IOException {
    // Rename is implemented as a rewrite followed by deleting the source. If the new object is in
    // the same location, the copy is a metadata-only operation.
    Set<MoveOptions> moveOptionSet = Sets.newHashSet(moveOptions);
    final boolean ignoreMissingSrc =
        moveOptionSet.contains(StandardMoveOptions.IGNORE_MISSING_FILES);
    final boolean ignoreExistingDest =
        moveOptionSet.contains(StandardMoveOptions.SKIP_IF_DESTINATION_EXISTS);
    rewriteHelper(
        srcFilenames, destFilenames, /*deleteSource=*/ true, ignoreMissingSrc, ignoreExistingDest);
  }
@Test
  public void testRename() throws IOException {
    GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
    GcsUtil gcsUtil = pipelineOptions.getGcsUtil();

    Storage mockStorage = Mockito.mock(Storage.class);
    gcsUtil.setStorageClient(mockStorage);
    gcsUtil.setBatchRequestSupplier(FakeBatcher::new);

    Storage.Objects mockStorageObjects = Mockito.mock(Storage.Objects.class);
    Storage.Objects.Rewrite mockStorageRewrite = Mockito.mock(Storage.Objects.Rewrite.class);
    Storage.Objects.Delete mockStorageDelete1 = Mockito.mock(Storage.Objects.Delete.class);
    Storage.Objects.Delete mockStorageDelete2 = Mockito.mock(Storage.Objects.Delete.class);

    when(mockStorage.objects()).thenReturn(mockStorageObjects);
    when(mockStorageObjects.rewrite("bucket", "s0", "bucket", "d0", null))
        .thenReturn(mockStorageRewrite);
    when(mockStorageRewrite.execute())
        .thenThrow(new InvalidObjectException("Test exception"))
        .thenReturn(new RewriteResponse().setDone(true));
    when(mockStorageObjects.delete("bucket", "s0"))
        .thenReturn(mockStorageDelete1)
        .thenReturn(mockStorageDelete2);

    when(mockStorageDelete1.execute()).thenThrow(new InvalidObjectException("Test exception"));

    gcsUtil.rename(makeStrings("s", 1), makeStrings("d", 1));
    verify(mockStorageRewrite, times(2)).execute();
    verify(mockStorageDelete1, times(1)).execute();
    verify(mockStorageDelete2, times(1)).execute();
  }