@Test
  public void testUpdateContainer() throws Exception {
    assumeTrue(!useNewZNodePath);
    accountService = mockHelixAccountServiceFactory.getAccountService();
    assertEquals("The number of account in HelixAccountService is incorrect", 0,
        accountService.getAllAccounts().size());
    // add an account with single container
    accountService.updateAccounts(Collections.singletonList(refAccount));

    // 1. Update existing container (success case)
    Container modifiedContainer = new ContainerBuilder(refContainer).setDescription("Different than before").build();
    Collection<Container> updatedContainers =
        accountService.updateContainers(refAccountName, Collections.singleton(modifiedContainer));
    assertEquals("Mismatch in return count", 1, updatedContainers.size());
    assertEquals("Mismatch in container data", modifiedContainer, updatedContainers.iterator().next());

    // 2. Update container with invalid name
    Container badContainer =
        new ContainerBuilder(refContainerId, "Unknown container", ContainerStatus.ACTIVE, "foo", refAccountId).build();
    try {
      accountService.updateContainers(refAccountName, Collections.singleton(badContainer));
      fail("should fail because container is not found");
    } catch (AccountServiceException e) {
      assertEquals("Mismatch in error code", AccountServiceErrorCode.NotFound, e.getErrorCode());
    }

    // 3. Update container with valid name and wrong id
    badContainer = new ContainerBuilder(refContainer).setId((short) (refContainerId + 7)).build();
    try {
      accountService.updateContainers(refAccountName, Collections.singleton(badContainer));
      fail("should fail due to wrong id");
    } catch (AccountServiceException e) {
      assertEquals("Mismatch in error code", AccountServiceErrorCode.ResourceConflict, e.getErrorCode());
    }
  }
Test updating an existing container (id specified).
ambry-account/src/test/java/com/github/ambry/account/HelixAccountServiceTest.java