@Nullable
    public String ensureUser(String userName, String password, String firstName, String lastName, String email,
                             Set<String> expectedRoles) {
        return ensureUser(userName, password, firstName, lastName, email, expectedRoles, false);
    }
@Test
    public void ensureUser() throws Exception {
        final Permissions permissions = new Permissions(ImmutableSet.of());

        when(userService.load("test-user")).thenReturn(null);
        when(userService.create()).thenReturn(newUser(permissions));
        when(userService.save(any(User.class))).thenReturn("new-id");

        assertThat(migrationHelpers.ensureUser("test-user", "pass", "Test", "User",
                                               "test@example.com", ImmutableSet.of("54e3deadbeefdeadbeef0001",
                                                                                   "54e3deadbeefdeadbeef0002")))
                .isEqualTo("new-id");

        final ArgumentCaptor<User> userArg = ArgumentCaptor.forClass(User.class);

        verify(userService, times(1)).save(userArg.capture());

        assertThat(userArg.getValue()).satisfies(user -> {
            assertThat(user.getName()).describedAs("user name").isEqualTo("test-user");
            assertThat(user.getFullName()).describedAs("user full-name").isEqualTo("Test User");
            assertThat(user.getHashedPassword()).describedAs("user hashed password").isNotBlank();
            assertThat(user.getEmail()).describedAs("user email").isEqualTo("test@example.com");
            assertThat(user.isReadOnly()).describedAs("user is read-only").isFalse();
            assertThat(user.getPermissions()).describedAs("user permissions")
                    .containsOnlyElementsOf(permissions.userSelfEditPermissions("test-user"));
            assertThat(user.getRoleIds()).describedAs("user roles").containsOnly(
                    "54e3deadbeefdeadbeef0001",
                    "54e3deadbeefdeadbeef0002"
            );
            assertThat(user.getTimeZone()).describedAs("user timezone").isEqualTo(DateTimeZone.UTC);
        });
    }