package <%=packageName%>.service;
<% if (databaseType == 'cassandra') { %>
import <%=packageName%>.AbstractCassandraTest;<% } %>
import <%=packageName%>.Application;<% if (databaseType == 'mongodb') { %>
import <%=packageName%>.config.MongoConfiguration;<% } %><% if ((databaseType == 'sql' || databaseType == 'mongodb') && authenticationType == 'session') { %>
import <%=packageName%>.domain.PersistentToken;<% } %>
import <%=packageName%>.domain.User;<% if ((databaseType == 'sql' || databaseType == 'mongodb') && authenticationType == 'session') { %>
import <%=packageName%>.repository.PersistentTokenRepository;<% } %>
import <%=packageName%>.repository.UserRepository;
import org.joda.time.DateTime;<% if (databaseType == 'sql' || databaseType == 'mongodb') { %>
import org.joda.time.LocalDate;<% } %>
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;<% if (databaseType == 'mongodb') { %>
import org.springframework.context.annotation.Import;<% } %><% if (databaseType == 'sql') { %>
import org.springframework.transaction.annotation.Transactional;<% } %>
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import javax.inject.Inject;<% if ((databaseType == 'sql' || databaseType == 'mongodb') && javaVersion == '8') { %>
import java.util.Optional;<%}%>
import java.util.List;

import static org.assertj.core.api.Assertions.*;

/**
 * Test class for the UserResource REST controller.
 *
 * @see UserService
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest<% if (databaseType == 'mongodb') { %>
@Import(MongoConfiguration.class)<% } %><% if (databaseType == 'sql') { %>
@Transactional<% } %>
public class UserServiceTest <% if (databaseType == 'cassandra') { %>extends AbstractCassandraTest <% } %>{<% if ((databaseType == 'sql' || databaseType == 'mongodb') && authenticationType == 'session') { %>

    @Inject
    private PersistentTokenRepository persistentTokenRepository;<% } %>

    @Inject
    private UserRepository userRepository;

    @Inject
    private UserService userService;<% if ((databaseType == 'sql' || databaseType == 'mongodb') && authenticationType == 'session') { %>

    @Test
    public void testRemoveOldPersistentTokens() {<% if (javaVersion == '8') { %>
        User admin = userRepository.findOneByLogin("admin").get();<% } else { %>
        User admin = userRepository.findOneByLogin("admin");<% } %>
        int existingCount = persistentTokenRepository.findByUser(admin).size();
        generateUserToken(admin, "1111-1111", new LocalDate());
        LocalDate now = new LocalDate();
        generateUserToken(admin, "2222-2222", now.minusDays(32));
        assertThat(persistentTokenRepository.findByUser(admin)).hasSize(existingCount + 2);
        userService.removeOldPersistentTokens();
        assertThat(persistentTokenRepository.findByUser(admin)).hasSize(existingCount + 1);
    }<% } %><% if (databaseType == 'sql' || databaseType == 'mongodb') { %>

    @Test
    public void testFindNotActivatedUsersByCreationDateBefore() {
        userService.removeNotActivatedUsers();
        DateTime now = new DateTime();
        List<User> users = userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(now.minusDays(3));
        assertThat(users).isEmpty();
    }<% } %><% if ((databaseType == 'sql' || databaseType == 'mongodb') && authenticationType == 'session') { %>

    private void generateUserToken(User user, String tokenSeries, LocalDate localDate) {
        PersistentToken token = new PersistentToken();
        token.setSeries(tokenSeries);
        token.setUser(user);
        token.setTokenValue(tokenSeries + "-data");
        token.setTokenDate(localDate);
        token.setIpAddress("127.0.0.1");
        token.setUserAgent("Test agent");<% if (databaseType == 'sql') { %>
        persistentTokenRepository.saveAndFlush(token);<% } %><% if (databaseType == 'mongodb') { %>
        persistentTokenRepository.save(token);<% } %>
    }<% } %>
}

@@ -3193,32 +3193,1051 @@
 mongodb') %7B %25%3E%0A%0A
+    @Test%0A    public void assertThatUserMustExistToResetPassword() %7B%0A        %3C%25 if (javaVersion == '8') %7B %25%3E%0A        Optional%3CUser%3E maybeUser = userService.requestPasswordReset(%22john.doe@localhost%22);%0A        assertThat(maybeUser.isPresent()).isFalse();%0A%0A        maybeUser = userService.requestPasswordReset(%22admin@localhost%22);%0A        assertThat(maybeUser.isPresent()).isTrue();%0A%0A        assertThat(maybeUser.get().getEmail()).isEqualTo(%22admin@localhost%22);%0A        assertThat(maybeUser.get().getResetDate()).isNotNull();%0A        assertThat(maybeUser.get().getResetKey()).isNotNull();%0A        %3C%25 %7D else %7B %25%3E%0A        User user = userService.requestPasswordReset(%22john.doe@localhost%22);%0A        assertThat(user).isNull();%0A%0A        user = userService.requestPasswordReset(%22admin@localhost%22);%0A        assertThat(user).isNotNull();%0A        assertThat(user.getEmail()).isEqualTo(%22admin@localhost%22);%0A        assertThat(user.getResetDate()).isNotNull();%0A        assertThat(user.getResetKey()).isNotNull();%0A        %3C%25 %7D %25%3E%0A    %7D%0A%0A
     @Test%0A    pu

Add first service tests