@Test
public void testUpdateClustersToggleKerberos_Fail() throws Exception {

  // member state mocks
  Capture<AmbariManagementController> controllerCapture = EasyMock.newCapture();
  Injector injector = createStrictMock(Injector.class);
  Cluster cluster = createMock(Cluster.class);
  ActionManager actionManager = createNiceMock(ActionManager.class);
  ClusterRequest clusterRequest = createNiceMock(ClusterRequest.class);
  // requests
  Set<ClusterRequest> setRequests = Collections.singleton(clusterRequest);
  KerberosHelper kerberosHelper = createStrictMock(KerberosHelper.class);
  // expectations
  injector.injectMembers(capture(controllerCapture));
  expect(injector.getInstance(Gson.class)).andReturn(null);
  expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null);
  expect(injector.getInstance(KerberosHelper.class)).andReturn(kerberosHelper);
  expect(clusterRequest.getClusterId()).andReturn(1L).times(6);
  expect(clusterRequest.getSecurityType()).andReturn(SecurityType.NONE).anyTimes();
  expect(clusters.getClusterById(1L)).andReturn(cluster).times(2);
  expect(cluster.getResourceId()).andReturn(1L).times(3);
  expect(cluster.getClusterName()).andReturn("cluster").times(1);
  expect(cluster.getSecurityType()).andReturn(SecurityType.KERBEROS).anyTimes();
  expect(cluster.getCurrentClusterVersion()).andReturn(null).anyTimes();
  expect(cluster.getCurrentStackVersion()).andReturn(null).anyTimes();
  expect(cluster.getDesiredStackVersion()).andReturn(null).anyTimes();
  cluster.setCurrentStackVersion(anyObject(StackId.class));
  expectLastCall().once();
  cluster.setClusterName(anyObject(String.class));
  expectLastCall().once();
  cluster.addSessionAttributes(EasyMock.<Map<String, Object>>anyObject());
  expectLastCall().once();
  expect(kerberosHelper.shouldExecuteCustomOperations(SecurityType.NONE, null))
      .andReturn(false)
      .once();
  expect(kerberosHelper.getForceToggleKerberosDirective(EasyMock.<Map<String, String>>anyObject()))
      .andReturn(false)
      .once();
  expect(kerberosHelper.getManageIdentitiesDirective(EasyMock.<Map<String, String>>anyObject()))
      .andReturn(null)
      .once();
  expect(kerberosHelper.toggleKerberos(anyObject(Cluster.class), anyObject(SecurityType.class), anyObject(RequestStageContainer.class), anyBoolean()))
      .andThrow(new IllegalArgumentException("bad args!"))
      .once();
  // replay mocks
  replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper);
  // test
  AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager, clusters, injector);
  try {
    controller.updateClusters(setRequests, null);
    Assert.fail("IllegalArgumentException not thrown");
  } catch (IllegalArgumentException e) {
    // This is expected
  }
  // assert and verify
  assertSame(controller, controllerCapture.getValue());
  verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper);
}