@Test
public void testUpdateQuotaAndCollectBlocks() {

  FileDiffList diffs = new FileDiffList();
  FileWithSnapshotFeature sf = new FileWithSnapshotFeature(diffs);
  FileDiff diff = mock(FileDiff.class);
  BlockStoragePolicySuite bsps = mock(BlockStoragePolicySuite.class);
  BlockStoragePolicy bsp = mock(BlockStoragePolicy.class);
  BlockInfo[] blocks = new BlockInfo[] {
      new BlockInfoContiguous(new Block(1, BLOCK_SIZE, 1), REPL_1)
  };
  BlockManager bm = mock(BlockManager.class);
  // No snapshot
  INodeFile file = mock(INodeFile.class);
  when(file.getFileWithSnapshotFeature()).thenReturn(sf);
  when(file.getBlocks()).thenReturn(blocks);
  when(file.getStoragePolicyID()).thenReturn((byte) 1);
  Whitebox.setInternalState(file, "header", (long) REPL_1 << 48);
  when(file.getPreferredBlockReplication()).thenReturn(REPL_1);
  when(bsps.getPolicy(anyByte())).thenReturn(bsp);
  INode.BlocksMapUpdateInfo collectedBlocks = mock(
      INode.BlocksMapUpdateInfo.class);
  ArrayList<INode> removedINodes = new ArrayList<>();
  INode.ReclaimContext ctx = new INode.ReclaimContext(
      bsps, collectedBlocks, removedINodes, null);
  sf.updateQuotaAndCollectBlocks(ctx, file, diff);
  QuotaCounts counts = ctx.quotaDelta().getCountsCopy();
  Assert.assertEquals(0, counts.getStorageSpace());
  Assert.assertTrue(counts.getTypeSpaces().allLessOrEqual(0));
  // INode only exists in the snapshot
  INodeFile snapshotINode = mock(INodeFile.class);
  Whitebox.setInternalState(snapshotINode, "header", (long) REPL_3 << 48);
  Whitebox.setInternalState(diff, "snapshotINode", snapshotINode);
  when(diff.getSnapshotINode()).thenReturn(snapshotINode);
  when(bsp.chooseStorageTypes(REPL_1))
      .thenReturn(Lists.newArrayList(SSD));
  when(bsp.chooseStorageTypes(REPL_3))
      .thenReturn(Lists.newArrayList(DISK));
  blocks[0].setReplication(REPL_3);
  sf.updateQuotaAndCollectBlocks(ctx, file, diff);
  counts = ctx.quotaDelta().getCountsCopy();
  Assert.assertEquals((REPL_3 - REPL_1) * BLOCK_SIZE,
                      counts.getStorageSpace());
  Assert.assertEquals(BLOCK_SIZE, counts.getTypeSpaces().get(DISK));
  Assert.assertEquals(-BLOCK_SIZE, counts.getTypeSpaces().get(SSD));
}