@Test(description = "This method tests the addUser method of UserManagementService")
public void testAddUser() throws UserStoreException, ConfigurationManagementException, DeviceManagementException {

    PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager"))
            .toReturn(this.userStoreManager);
    PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
            .toReturn(this.deviceManagementProviderService);
    Mockito.doReturn(true).when(userStoreManager).isExistingUser("admin");
    Mockito.doAnswer(new Answer() {
        private int count = 0;
        public Object answer(InvocationOnMock invocation) {
            if (count == 0) {
                count++;
                return false;
            } else {
                return true;
            }
        }
    }).when(userStoreManager).isExistingUser(TEST_USERNAME);
    Mockito.doReturn("test@test.com").when(userStoreManager)
            .getUserClaimValue(TEST_USERNAME, Constants.USER_CLAIM_EMAIL_ADDRESS, null);
    Mockito.doReturn(TEST_USERNAME).when(userStoreManager)
            .getUserClaimValue(TEST_USERNAME, Constants.USER_CLAIM_FIRST_NAME, null);
    Mockito.doReturn(TEST_USERNAME).when(userStoreManager)
            .getUserClaimValue(TEST_USERNAME, Constants.USER_CLAIM_LAST_NAME, null);
    Mockito.doNothing().when(userStoreManager)
            .addUser(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
    UserInfo userInfo = new UserInfo();
    userInfo.setUsername("admin");
    Response response = userManagementService.addUser(userInfo);
    Assert.assertEquals(response.getStatus(), Response.Status.CONFLICT.getStatusCode(),
            "Same user can be added " + "twice");
    userInfo = getUserInfo();
    Mockito.doReturn(true).when(userStoreManager).isExistingRole(DEFAULT_DEVICE_USER);
    Mockito.doNothing().when(deviceManagementProviderService).sendRegistrationEmail(Mockito.any());
    response = userManagementService.addUser(userInfo);
    Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(), "User addition failed");
}