### Question:
Provisioner { public int tryAddTenantAssignments(String tenantId, int numToAdd) { if (capacityFree < 1) { return 0; } int actualNumToAdd = Math.min(capacityFree, numToAdd); if (assignments.containsKey(tenantId)) { assignments.put(tenantId, assignments.get(tenantId) + actualNumToAdd); } else { assignments.put(tenantId, actualNumToAdd); } capacityFree -= actualNumToAdd; return actualNumToAdd; } Provisioner(String id, String host, Integer port, Integer capacityTotal, Map<String, Integer> usage,
                     Map<String, Integer> assignments); String getId(); String getHost(); int getPort(); int getCapacityTotal(); int getCapacityFree(); Map<String, Integer> getUsage(); Set<String> getAssignedTenants(); Set<String> getLiveTenants(); void removeTenantAssignments(String tenantId); int tryAddTenantAssignments(String tenantId, int numToAdd); int tryRemoveTenantAssignments(String tenantId, int numToRemove); int getAssignedWorkers(String tenantId); int getLiveWorkers(String tenantId); void setUsage(Map<String, Integer> usage); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void testTryAddTenantAssignments() { Provisioner provisioner = new Provisioner( "id", "host", 12345, 100, ImmutableMap.<String, Integer>of("t1", 5, "t2", 10, "t3", 20), ImmutableMap.<String, Integer>of("t1", 5, "t2", 10, "t3", 25) ); Assert.assertEquals(10, provisioner.tryAddTenantAssignments("t4", 10)); Assert.assertEquals(50, provisioner.getCapacityFree()); Assert.assertEquals(5, provisioner.getAssignedWorkers("t1")); Assert.assertEquals(10, provisioner.getAssignedWorkers("t2")); Assert.assertEquals(25, provisioner.getAssignedWorkers("t3")); Assert.assertEquals(10, provisioner.getAssignedWorkers("t4")); Assert.assertEquals(30, provisioner.tryAddTenantAssignments("t1", 30)); Assert.assertEquals(20, provisioner.getCapacityFree()); Assert.assertEquals(35, provisioner.getAssignedWorkers("t1")); Assert.assertEquals(10, provisioner.getAssignedWorkers("t2")); Assert.assertEquals(25, provisioner.getAssignedWorkers("t3")); Assert.assertEquals(10, provisioner.getAssignedWorkers("t4")); Assert.assertEquals(20, provisioner.tryAddTenantAssignments("t2", 30)); Assert.assertEquals(0, provisioner.getCapacityFree()); Assert.assertEquals(35, provisioner.getAssignedWorkers("t1")); Assert.assertEquals(30, provisioner.getAssignedWorkers("t2")); Assert.assertEquals(25, provisioner.getAssignedWorkers("t3")); Assert.assertEquals(10, provisioner.getAssignedWorkers("t4")); }