### Question:
AddServicesChange implements ClusterLayoutChange { @Override public ClusterLayout applyChange(ClusterLayout originalLayout) { Multiset<NodeLayout> newLayout = HashMultiset.create(originalLayout.getLayout()); for (Multiset.Entry<NodeLayout> entry : countsPerNodeLayout.entrySet()) { NodeLayout originalNodeLayout = entry.getElement(); NodeLayout expandedNodeLayout = NodeLayout.addServicesToNodeLayout(originalNodeLayout, services); newLayout.add(expandedNodeLayout, entry.getCount()); newLayout.setCount(originalNodeLayout, originalLayout.getLayout().count(originalNodeLayout) - entry.getCount()); } return new ClusterLayout(originalLayout.getConstraints(), newLayout); } AddServicesChange(Multiset<NodeLayout> countsPerNodeLayout, String service);  AddServicesChange(Multiset<NodeLayout> countsPerNodeLayout, Set<String> services); @Override boolean canApplyChange(ClusterLayout layout); @Override ClusterLayout applyChange(ClusterLayout originalLayout); @Override Set<Node> applyChange(Cluster cluster, Set<Node> clusterNodes, Map<String, Service> serviceMap); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void testApplyChangeToClusterLayout() { NodeLayout masterNodeLayout = new NodeLayout("large-mem", "centos6", ImmutableSet.of("namenode")); NodeLayout slaveLayout = new NodeLayout("medium", "centos6", ImmutableSet.of("datanode")); Multiset<NodeLayout> counts = HashMultiset.create(); counts.add(masterNodeLayout); counts.add(slaveLayout, 50); ClusterLayout layout = new ClusterLayout(constraints, counts); NodeLayout expandedMasterNodeLayout = new NodeLayout("large-mem", "centos6", ImmutableSet.of("namenode", "resourcemanager")); NodeLayout expandedSlaveNodeLayout = new NodeLayout("medium", "centos6", ImmutableSet.of("datanode", "nodemanager")); Multiset<NodeLayout> addCounts = HashMultiset.create(); addCounts.add(masterNodeLayout, 1); AddServicesChange change = new AddServicesChange(addCounts, "resourcemanager"); ClusterLayout expanded = change.applyChange(layout); Multiset<NodeLayout> expectedCounts = HashMultiset.create(); expectedCounts.add(expandedMasterNodeLayout, 1); expectedCounts.add(slaveLayout, 50); ClusterLayout expected = new ClusterLayout(constraints, expectedCounts); Assert.assertEquals(expected, expanded); addCounts = HashMultiset.create(); addCounts.add(slaveLayout, 25); change = new AddServicesChange(addCounts, "nodemanager"); expanded = change.applyChange(expanded); expectedCounts = HashMultiset.create(); expectedCounts.add(expandedMasterNodeLayout, 1); expectedCounts.add(slaveLayout, 25); expectedCounts.add(expandedSlaveNodeLayout, 25); expected = new ClusterLayout(constraints, expectedCounts); Assert.assertEquals(expected, expanded); expanded = change.applyChange(expanded); expectedCounts = HashMultiset.create(); expectedCounts.add(expandedMasterNodeLayout, 1); expectedCounts.add(expandedSlaveNodeLayout, 50); expected = new ClusterLayout(constraints, expectedCounts); Assert.assertEquals(expected, expanded); }