public static void rename(FileSystem fs, String oldName, String newName)
    throws IOException {
    Path oldDir = new Path(oldName);
    Path newDir = new Path(newName);
    if (!fs.rename(oldDir, newDir)) {
      throw new IOException("Could not rename " + oldDir + " to " + newDir);
    }
  }
@Test
  public void testRenameWithFalse() {
    final String ERROR_MESSAGE = "Could not rename";
    final String NEW_FILE_NAME = "test-new.mapfile";
    final String OLD_FILE_NAME = "test-old.mapfile";
    MapFile.Writer writer = null;
    try {
      FileSystem fs = FileSystem.getLocal(conf);
      FileSystem spyFs = spy(fs);

      writer = createWriter(OLD_FILE_NAME, IntWritable.class, IntWritable.class);
      writer.close();

      Path oldDir = new Path(TEST_DIR, OLD_FILE_NAME);
      Path newDir = new Path(TEST_DIR, NEW_FILE_NAME);
      when(spyFs.rename(oldDir, newDir)).thenReturn(false);

      MapFile.rename(spyFs, oldDir.toString(), newDir.toString());
      fail("testRenameWithException no exception error !!!");
    } catch (IOException ex) {
      assertTrue("testRenameWithFalse invalid IOExceptionMessage error !!!", ex
          .getMessage().startsWith(ERROR_MESSAGE));
    } finally {
      IOUtils.cleanupWithLogger(LOG, writer);
    }
  }