@Test
  public void testRetryableFSCalls() throws Exception {
    try (MockedStatic<UserGroupInformation> userGroupInformationMockedStatic = mockStatic(UserGroupInformation.class);
         MockedStatic<ReplChangeManager> replChangeManagerMockedStatic = mockStatic(ReplChangeManager.class)) {
      userGroupInformationMockedStatic.when(UserGroupInformation::getCurrentUser).thenReturn(mock(UserGroupInformation.class));
      HiveConf conf = mock(HiveConf.class);
      conf.set(HiveConf.ConfVars.REPL_RETRY_INTIAL_DELAY.varname, "1s");
      FileSystem fs = mock(FileSystem.class);
      Path source = mock(Path.class);
      Path destination = mock(Path.class);
      ContentSummary cs = mock(ContentSummary.class);

      replChangeManagerMockedStatic.when(() -> ReplChangeManager.checksumFor(source, fs)).thenThrow(new IOException("Failed")).thenReturn("dummy");
      when(fs.exists(same(source))).thenThrow(new IOException("Failed")).thenReturn(true);
      when(fs.delete(same(source), anyBoolean())).thenThrow(new IOException("Failed")).thenReturn(true);
      when(fs.mkdirs(same(source))).thenThrow(new IOException("Failed")).thenReturn(true);
      when(fs.rename(same(source), same(destination))).thenThrow(new IOException("Failed")).thenReturn(true);
      when(fs.getContentSummary(same(source))).thenThrow(new IOException("Failed")).thenReturn(cs);

      CopyUtils copyUtils = new CopyUtils(UserGroupInformation.getCurrentUser().getUserName(), conf, fs);
      CopyUtils copyUtilsSpy = Mockito.spy(copyUtils);
      assertEquals (true, copyUtilsSpy.exists(fs, source));
      Mockito.verify(fs, Mockito.times(2)).exists(source);
      assertEquals (true, copyUtils.delete(fs, source, true));
      Mockito.verify(fs, Mockito.times(2)).delete(source, true);
      assertEquals (true, copyUtils.mkdirs(fs, source));
      Mockito.verify(fs, Mockito.times(2)).mkdirs(source);
      assertEquals (true, copyUtils.rename(fs, source, destination));
      Mockito.verify(fs, Mockito.times(2)).rename(source, destination);
      assertEquals (cs, copyUtilsSpy.getContentSummary(fs, source));
      Mockito.verify(fs, Mockito.times(2)).getContentSummary(source);
      assertEquals ("dummy", copyUtilsSpy.checkSumFor(source, fs));
    }
  }
Unit Test class for CopyUtils class.
ql/src/test/org/apache/hadoop/hive/ql/parse/repl/TestCopyUtils.java