### Question:
HDFSBlocksDistribution { public void add(HDFSBlocksDistribution otherBlocksDistribution) { Map<String,HostAndWeight> otherHostAndWeights = otherBlocksDistribution.getHostAndWeights(); for (Map.Entry<String, HostAndWeight> otherHostAndWeight: otherHostAndWeights.entrySet()) { addHostAndBlockWeight(otherHostAndWeight.getValue().host, otherHostAndWeight.getValue().weight); } addUniqueWeight(otherBlocksDistribution.getUniqueBlocksTotalWeight()); } HDFSBlocksDistribution(); @Override synchronized String toString(); void addHostsAndBlockWeight(String[] hosts, long weight); Map<String,HostAndWeight> getHostAndWeights(); long getWeight(String host); long getUniqueBlocksTotalWeight(); float getBlockLocalityIndex(String host); void add(HDFSBlocksDistribution otherBlocksDistribution); List<String> getTopHosts();  }### Answer:
@Test public void testAdd() throws Exception { HDFSBlocksDistribution distribution = new HDFSBlocksDistribution(); distribution.add(new MockHDFSBlocksDistribution()); assertEquals("Expecting no hosts weights", 0, distribution.getHostAndWeights().size()); distribution.addHostsAndBlockWeight(new String[]{"test"}, 10); assertEquals("Should be one host", 1, distribution.getHostAndWeights().size()); distribution.add(new MockHDFSBlocksDistribution()); assertEquals("Should be one host", 1, distribution.getHostAndWeights().size()); assertEquals("Total weight should be 10", 10, distribution.getUniqueBlocksTotalWeight()); }