UsersClientImpl implements org.symphonyoss.symphony.clients.UsersClient { @Override public void updateUserAvatar(long userId, byte[] avatar) throws UsersClientException { if (avatar != null) { UserApi usersApi = new UserApi(apiClient); try { String sessionToken = getSessionToken(); String image = Base64.getEncoder().encodeToString(avatar); AvatarUpdate avatarUpdate = new AvatarUpdate(); avatarUpdate.setImage(image); SuccessResponse response = usersApi.v1AdminUserUidAvatarUpdatePost(sessionToken, userId, avatarUpdate); if (!"OK".equals(response.getMessage())) { throw new IllegalStateException( "The message differs from expected OK message. Response message: " + response.getMessage()); } } catch (ApiException e) { String message = "API error communicating with POD, while updating avatar"; logger.error(message, e); throw new UsersClientException(message, new RestException(usersApi.getApiClient().getBasePath(), e.getCode(), e)); } catch (IllegalStateException e) { String message = "Avatar update failed"; logger.error(message, e); throw new UsersClientException(message); } } } UsersClientImpl(SymAuth symAuth, SymphonyClientConfig config);  UsersClientImpl(SymAuth symAuth, SymphonyClientConfig config, Client httpClient); @Override SymUser getUserFromEmail(String email); @Override SymUser getUserFromId(Long userId); @Override SymUser getUserFromName(String userName); @Override Set<SymUser> getUsersFromStream(String streamId); @SuppressWarnings("unused") @Override Set<SymUser> getAllUsers(); @Override Set<SymUser> getAllUsersWithDetails(); @Override void setUserStatus(long userId, UserStatus userStatus); @Override SymUser updateUser(long userId, SymUser symUser); @Override SymUser createUser(UserCreate userCreate); @Override SymUser getUserBySession(SymAuth symAuth); @Override void updateUserAvatar(long userId, byte[] avatar);  }
@Test(expected = UsersClientException.class) public void unsuccessfulAvatarUpdate() throws ApiException, UsersClientException { mockSessionToken(); mockUserApi(NOT_OK_RESPONSE); usersClient.updateUserAvatar(USER_ID, generateImageData()); verify(LOG, times(1)).error(eq(AVATAR_UPDATE_FAILED), any(IllegalStateException.class)); }
@Test(expected = UsersClientException.class) public void apiExceptionAvatarUpdate() throws ApiException, UsersClientException { mockSessionToken(); mockUserApiException(); usersClient.updateUserAvatar(USER_ID, generateImageData()); verify(LOG, times(1)).error(eq(API_ERROR_COMMUNICATING_WITH_POD_WHILE_UPDATING_AVATAR), any(ApiException.class)); }
@Test public void avatarArryIsNull() throws Exception { usersClient.updateUserAvatar(USER_ID, null); verifyNew(UserApi.class, times(0)).withArguments(eq(apiClientMock)); }
@Test public void successfulAvatarUpdate() throws ApiException, UsersClientException { mockSessionToken(); mockUserApi(OK_RESPONSE); usersClient.updateUserAvatar(USER_ID, generateImageData()); verify(LOG, times(0)).error(anyString(), any(Exception.class)); }