### Question:
ClouderaManagerSecurityService implements ClusterSecurityService { @Override public void changeOriginalCredentialsAndCreateCloudbreakUser(boolean ldapConfigured) throws CloudbreakException { LOGGER.debug("change original admin user and create cloudbreak user"); try { ApiClient client = createApiClient(); UsersResourceApi usersResourceApi = clouderaManagerApiFactory.getUserResourceApi(client); ApiUser2List userList = usersResourceApi.readUsers2("SUMMARY"); ApiUser2 oldAdminUser = getOldAdminUser(userList).orElseThrow(() -> new CloudbreakException("Can't find original admin user")); Cluster cluster = stack.getCluster(); createNewUser(usersResourceApi, oldAdminUser.getAuthRoles(), cluster.getCloudbreakAmbariUser(), cluster.getCloudbreakAmbariPassword(), userList); createNewUser(usersResourceApi, oldAdminUser.getAuthRoles(), cluster.getDpAmbariUser(), cluster.getDpAmbariPassword(), userList); if (ADMIN_USER.equals(cluster.getUserName())) { ApiUser2 oldAdmin = oldAdminUser; oldAdmin.setPassword(cluster.getPassword()); usersResourceApi.updateUser2(oldAdminUser.getName(), oldAdmin); } else if (cluster.getUserName() != null) { createUserSuppliedCMUser(userList, oldAdminUser, cluster); } removeDefaultAdminUser(ldapConfigured, Optional.ofNullable(cluster.getUserName())); } catch (ApiException | ClusterClientInitException | ClouderaManagerClientInitException e) { LOGGER.info("Can't replace original admin user due to: ", e); throw new CloudbreakException("Can't replace original admin user due to: " + e.getMessage()); } } ClouderaManagerSecurityService(Stack stack, HttpClientConfig clientConfig); @Override void replaceUserNamePassword(String newUserName, String newPassword); @Override void updateUserNamePassword(String newPassword); @Override void setupMonitoringUser(); @Override void prepareSecurity(); @Override void disableSecurity(); @Override void deregisterServices(String clusterName); @Override void changeOriginalCredentialsAndCreateCloudbreakUser(boolean ldapConfigured); @Override void setupLdapAndSSO(String primaryGatewayPublicAddress, LdapView ldapConfig, VirtualGroupRequest virtualGroupRequest); @Override String getCloudbreakClusterUserName(); @Override String getCloudbreakClusterPassword(); @Override String getDataplaneClusterUserName(); @Override String getDataplaneClusterPassword(); @Override String getClusterUserProvidedPassword(); @Override String getCertPath(); @Override String getKeystorePath(); @Override String getKeystorePassword(); @Override String getMasterKey(); @Override void rotateHostCertificates(); ApiClient getClient(Integer gatewayPort, String user, String password, HttpClientConfig clientConfig);  }### Answer:
@Test public void testChangeOriginalCredentialsAndCreateCloudbreakUserWhenUsersAlreadyCreated() throws CloudbreakException, ApiException, ClouderaManagerClientInitException { initTestInput("ambariUser"); UsersResourceApi usersResourceApi = mock(UsersResourceApi.class); UsersResourceApi newUsersResourceApi = mock(UsersResourceApi.class); ApiClient newApiClient = mock(ApiClient.class); Cluster cluster = stack.getCluster(); setUpClientCreation(cluster); when(clouderaManagerApiFactory.getUserResourceApi(apiClient)).thenReturn(usersResourceApi); setUpUsersAlreadyCreated(usersResourceApi, cluster); setUpApiClientCredentialAlreadyChanged(); when(clouderaManagerApiClientProvider.getClouderaManagerClient(clientConfig, GATEWAY_PORT, cluster.getCloudbreakAmbariUser(), cluster.getCloudbreakAmbariPassword(), ClouderaManagerApiClientProvider.API_V_31)).thenReturn(newApiClient); when(clouderaManagerApiFactory.getUserResourceApi(newApiClient)).thenReturn(newUsersResourceApi); underTest.changeOriginalCredentialsAndCreateCloudbreakUser(LDAP_DISABLED); verifyClientCreation(usersResourceApi, cluster); verify(usersResourceApi).readUsers2("SUMMARY"); verifyNoUsersCreated(usersResourceApi, newUsersResourceApi); verifyNoMoreInteractions(clouderaManagerApiClientProvider); }