UserQuery sampleUserQuery = mock(UserQuery.class);
when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
when(sampleUserQuery.singleResult()).thenReturn(initialUser);
UserProfileDto updateDto = UserProfileDto.fromUser(userUpdate);
given()
.pathParam("id", MockProvider.EXAMPLE_USER_ID)
.body(updateDto).contentType(ContentType.JSON)
.then()
.statusCode(Status.NO_CONTENT.getStatusCode())
.when()
.put(USER_PROFILE_URL);
// password was updated
verify(initialUser).setEmail(updateDto.getEmail());
verify(initialUser).setFirstName(updateDto.getFirstName());
verify(initialUser).setLastName(updateDto.getLastName());
// and then saved
verify(identityServiceMock).saveUser(initialUser);
}