@Test
public void testValidateAndSplitUpdateResourceRequests() {

  List<UpdateContainerRequest> updateRequests = new ArrayList<>();
  int containerVersion = 10;
  int resource = 10;
  Resource maxAllocation = Resource.newInstance(resource, resource);
  UpdateContainerRequestPBImpl updateContainerRequestPBFail =
      new UpdateContainerRequestPBImpl();
  updateContainerRequestPBFail.setContainerVersion(containerVersion);
  updateContainerRequestPBFail
      .setCapability(Resource.newInstance(resource + 1, resource + 1));
  updateContainerRequestPBFail
      .setContainerId(Mockito.mock(ContainerId.class));
  ContainerId containerIdOk = Mockito.mock(ContainerId.class);
  Resource capabilityOk = Resource.newInstance(resource - 1, resource - 1);
  UpdateContainerRequestPBImpl updateContainerRequestPBOk =
      new UpdateContainerRequestPBImpl();
  updateContainerRequestPBOk.setContainerVersion(containerVersion);
  updateContainerRequestPBOk.setCapability(capabilityOk);
  updateContainerRequestPBOk.setContainerUpdateType(INCREASE_RESOURCE);
  updateContainerRequestPBOk.setContainerId(containerIdOk);
  updateRequests.add(updateContainerRequestPBOk);
  updateRequests.add(updateContainerRequestPBFail);
  Dispatcher dispatcher = Mockito.mock(Dispatcher.class);
  RMContext rmContext = Mockito.mock(RMContext.class);
  ResourceScheduler scheduler = Mockito.mock(ResourceScheduler.class);
  Mockito.when(rmContext.getScheduler()).thenReturn(scheduler);
  Mockito.when(rmContext.getDispatcher()).thenReturn(dispatcher);
  RMContainer rmContainer = Mockito.mock(RMContainer.class);
  Mockito.when(scheduler.getRMContainer(Mockito.any()))
      .thenReturn(rmContainer);
  Container container = Mockito.mock(Container.class);
  Mockito.when(container.getVersion()).thenReturn(containerVersion);
  Mockito.when(rmContainer.getContainer()).thenReturn(container);
  Mockito.when(scheduler.getNormalizedResource(capabilityOk, maxAllocation))
      .thenReturn(capabilityOk);
  AllocateRequest allocateRequest =
      AllocateRequest.newInstance(1, 0.5f, new ArrayList<ResourceRequest>(),
          new ArrayList<ContainerId>(), updateRequests, null);
  List<UpdateContainerError> updateErrors = new ArrayList<>();
  ContainerUpdates containerUpdates =
      RMServerUtils.validateAndSplitUpdateResourceRequests(rmContext,
          allocateRequest, maxAllocation, updateErrors);
  Assert.assertEquals(1, updateErrors.size());
  Assert.assertEquals(resource + 1, updateErrors.get(0)
      .getUpdateContainerRequest().getCapability().getMemorySize());
  Assert.assertEquals(resource + 1, updateErrors.get(0)
      .getUpdateContainerRequest().getCapability().getVirtualCores());
  Assert.assertEquals(RESOURCE_OUTSIDE_ALLOWED_RANGE,
      updateErrors.get(0).getReason());
  Assert.assertEquals(1, containerUpdates.getIncreaseRequests().size());
  UpdateContainerRequest increaseRequest =
      containerUpdates.getIncreaseRequests().get(0);
  Assert.assertEquals(capabilityOk.getVirtualCores(),
      increaseRequest.getCapability().getVirtualCores());
  Assert.assertEquals(capabilityOk.getMemorySize(),
      increaseRequest.getCapability().getMemorySize());
  Assert.assertEquals(containerIdOk, increaseRequest.getContainerId());
}