@Test
public void testPreserveTimestampOnFile() throws IOException {

  FileSystem fs = FileSystem.get(config);
  EnumSet<FileAttribute> attributes = EnumSet.of(FileAttribute.TIMES);
  Path dst = new Path("/tmp/dest2");
  Path src = new Path("/tmp/src2");
  createFile(fs, src);
  createFile(fs, dst);
  fs.setPermission(src, fullPerm);
  fs.setOwner(src, "somebody", "somebody-group");
  fs.setTimes(src, 0, 0);
  fs.setReplication(src, (short) 1);
  fs.setPermission(dst, noPerm);
  fs.setOwner(dst, "nobody", "nobody-group");
  fs.setTimes(dst, 100, 100);
  fs.setReplication(dst, (short) 2);
  CopyListingFileStatus srcStatus = new CopyListingFileStatus(fs.getFileStatus(src));
  DistCpUtils.preserve(fs, dst, srcStatus, attributes, false);
  CopyListingFileStatus dstStatus = new CopyListingFileStatus(fs.getFileStatus(dst));
  // FileStatus.equals only compares path field, must explicitly compare all fields
  Assert.assertFalse(srcStatus.getPermission().equals(dstStatus.getPermission()));
  Assert.assertFalse(srcStatus.getOwner().equals(dstStatus.getOwner()));
  Assert.assertFalse(srcStatus.getGroup().equals(dstStatus.getGroup()));
  Assert.assertTrue(srcStatus.getAccessTime() == dstStatus.getAccessTime());
  Assert.assertTrue(srcStatus.getModificationTime() == dstStatus.getModificationTime());
  Assert.assertFalse(srcStatus.getReplication() == dstStatus.getReplication());
}