gt:         User testUser = userList.get(userList.size() - 1);
context: package ua.sgkhmja.wboard.web.rest;
  
  import ua.sgkhmja.wboard.WBoardApp;
  import ua.sgkhmja.wboard.domain.User;
  import ua.sgkhmja.wboard.repository.UserRepository;
  import ua.sgkhmja.wboard.repository.search.UserSearchRepository;
  import ua.sgkhmja.wboard.service.MailService;
  import ua.sgkhmja.wboard.service.UserService;
  import ua.sgkhmja.wboard.web.rest.errors.ExceptionTranslator;
  import ua.sgkhmja.wboard.web.rest.vm.ManagedUserVM;
  import org.apache.commons.lang3.RandomStringUtils;
  import org.junit.Before;
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.mockito.MockitoAnnotations;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.test.context.SpringBootTest;
  import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
  import org.springframework.http.MediaType;
  import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
  import org.springframework.test.context.junit4.SpringRunner;
  import org.springframework.test.web.servlet.MockMvc;
  import org.springframework.test.web.servlet.setup.MockMvcBuilders;
  import org.springframework.transaction.annotation.Transactional;
  
  import javax.persistence.EntityManager;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Set;
  
  import static org.assertj.core.api.Assertions.assertThat;
  import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
  import static org.assertj.core.api.Assertions.assertThat;
  import static org.hamcrest.Matchers.hasItem;
  import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
  import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
  
  /**
   * Test class for the UserResource REST controller.
   *
   * @see UserResource
   */
  @RunWith(SpringRunner.class)
  @SpringBootTest(classes = WBoardApp.class)
  public class UserResourceIntTest {
  
      private static final String DEFAULT_LOGIN = "johndoe";
      private static final String UPDATED_LOGIN = "jhipster";
  
      private static final String DEFAULT_PASSWORD = "passjohndoe";
      private static final String UPDATED_PASSWORD = "passjhipster";
  
      private static final String DEFAULT_EMAIL = "johndoe@localhost";
      private static final String UPDATED_EMAIL = "jhipster@localhost";
  
      private static final String DEFAULT_FIRSTNAME = "john";
      private static final String UPDATED_FIRSTNAME = "jhipsterFirstName";
  
      private static final String DEFAULT_LASTNAME = "doe";
      private static final String UPDATED_LASTNAME = "jhipsterLastName";
  
      private static final String DEFAULT_IMAGEURL = "http://placehold.it/50x50";
      private static final String UPDATED_IMAGEURL = "http://placehold.it/40x40";
  
      private static final String DEFAULT_LANGKEY = "en";
      private static final String UPDATED_LANGKEY = "fr";
  
      @Autowired
      private UserRepository userRepository;
  
      @Autowired
      private UserSearchRepository userSearchRepository;
  
      @Autowired
      private MailService mailService;
  
      @Autowired
      private UserService userService;
  
      @Autowired
      private MappingJackson2HttpMessageConverter jacksonMessageConverter;
  
      @Autowired
      private PageableHandlerMethodArgumentResolver pageableArgumentResolver;
  
      @Autowired
      private ExceptionTranslator exceptionTranslator;
  
      @Autowired
      private EntityManager em;
  
      private MockMvc restUserMockMvc;
  
      private User user;
  
      @Before
      public void setup() {
          MockitoAnnotations.initMocks(this);
          UserResource userResource = new UserResource(userRepository, mailService, userService, userSearchRepository);
          this.restUserMockMvc = MockMvcBuilders.standaloneSetup(userResource)
              .setCustomArgumentResolvers(pageableArgumentResolver)
              .setControllerAdvice(exceptionTranslator)
              .setMessageConverters(jacksonMessageConverter)
              .build();
      }
  
      /**
       * Create a User.
       *
       * This is a static method, as tests for other entities might also need it,
       * if they test an entity which has a required relationship to the User entity.
       */
      public static User createEntity(EntityManager em) {
          User user = new User();
          user.setLogin(DEFAULT_LOGIN);
          user.setPassword(RandomStringUtils.random(60));
          user.setActivated(true);
          user.setEmail(DEFAULT_EMAIL);
          user.setFirstName(DEFAULT_FIRSTNAME);
          user.setLastName(DEFAULT_LASTNAME);
          user.setImageUrl(DEFAULT_IMAGEURL);
          user.setLangKey(DEFAULT_LANGKEY);
          return user;
      }
  
      @Before
      public void initTest() {
          user = createEntity(em);
      }
  
      @Test
      @Transactional
      public void createUser() throws Exception {
          int databaseSizeBeforeCreate = userRepository.findAll().size();
  
          // Create the User
          Set<String> authorities = new HashSet<>();
          authorities.add("ROLE_USER");
          ManagedUserVM managedUserVM = new ManagedUserVM(
              null,
              DEFAULT_LOGIN,
              DEFAULT_PASSWORD,
              DEFAULT_FIRSTNAME,
              DEFAULT_LASTNAME,
              DEFAULT_EMAIL,
              true,
              DEFAULT_IMAGEURL,
              DEFAULT_LANGKEY,
              null,
              null,
              null,
              null,
              authorities);
  
          restUserMockMvc.perform(post("/api/users")
              .contentType(TestUtil.APPLICATION_JSON_UTF8)
              .content(TestUtil.convertObjectToJsonBytes(managedUserVM)))
              .andExpect(status().isCreated());
  
          // Validate the User in the database
          List<User> userList = userRepository.findAll();
          assertThat(userList).hasSize(databaseSizeBeforeCreate + 1);
          User testUser = userList.get(userList.size() - 1);
          assertThat(testUser.getLogin()).isEqualTo(DEFAULT_LOGIN);
          assertThat(testUser.getFirstName()).isEqualTo(DEFAULT_FIRSTNAME);
          assertThat(testUser.getLastName()).isEqualTo(DEFAULT_LASTNAME);
          assertThat(testUser.getEmail()).isEqualTo(DEFAULT_EMAIL);
          assertThat(testUser.getImageUrl()).isEqualTo(DEFAULT_IMAGEURL);
          assertThat(testUser.getLangKey()).isEqualTo(DEFAULT_LANGKEY);
      }
  
      @Test
      @Transactional
      public void createUserWithExistingId() throws Exception {
          int databaseSizeBeforeCreate = userRepository.findAll().size();
  
          Set<String> authorities = new HashSet<>();
          authorities.add("ROLE_USER");
          ManagedUserVM managedUserVM = new ManagedUserVM(
              1L,
              DEFAULT_LOGIN,
              DEFAULT_PASSWORD,
              DEFAULT_FIRSTNAME,
              DEFAULT_LASTNAME,
              DEFAULT_EMAIL,
              true,
              DEFAULT_IMAGEURL,
              DEFAULT_LANGKEY,
              null,
              null,
              null,
              null,
              authorities);
  
          // An entity with an existing ID cannot be created, so this API call must fail
          restUserMockMvc.perform(post("/api/users")
              .contentType(TestUtil.APPLICATION_JSON_UTF8)
              .content(TestUtil.convertObjectToJsonBytes(managedUserVM)))
              .andExpect(status().isBadRequest());
  
          // Validate the User in the database
          List<User> userList = userRepository.findAll();
          assertThat(userList).hasSize(databaseSizeBeforeCreate);
      }
  
      @Test
      @Transactional
      public void createUserWithExistingLogin() throws Exception {
          // Initialize the database
          userRepository.saveAndFlush(user);
          userSearchRepository.save(user);
          int databaseSizeBeforeCreate = userRepository.findAll().size();
  
          Set<String> authorities = new HashSet<>();
          authorities.add("ROLE_USER");
          ManagedUserVM managedUserVM = new ManagedUserVM(
              null,
              DEFAULT_LOGIN, // this login should already be used
              DEFAULT_PASSWORD,
              DEFAULT_FIRSTNAME,
              DEFAULT_LASTNAME,
              "anothermail@localhost",
              true,
              DEFAULT_IMAGEURL,
              DEFAULT_LANGKEY,
              null,
              null,
              null,
              null,
              authorities);
  
          // Create the User
          restUserMockMvc.perform(post("/api/users")
              .contentType(TestUtil.APPLICATION_JSON_UTF8)
              .content(TestUtil.convertObjectToJsonBytes(managedUserVM)))
              .andExpect(status().isBadRequest());
  
          // Validate the User in the database
          List<User> userList = userRepository.findAll();
          assertThat(userList).hasSize(databaseSizeBeforeCreate);
      }
  
      @Test
      @Transactional
      public void createUserWithExistingEmail() throws Exception {
          // Initialize the database
          userRepository.saveAndFlush(user);
          userSearchRepository.save(user);
          int databaseSizeBeforeCreate = userRepository.findAll().size();
  
          Set<String> authorities = new HashSet<>();
          authorities.add("ROLE_USER");
          ManagedUserVM managedUserVM = new ManagedUserVM(
              null,
              "anotherlogin",
              DEFAULT_PASSWORD,
              DEFAULT_FIRSTNAME,
              DEFAULT_LASTNAME,
              DEFAULT_EMAIL, // this email should already be used
              true,
              DEFAULT_IMAGEURL,
              DEFAULT_LANGKEY,
              null,
              null,
              null,
              null,
              authorities);
  
          // Create the User
          restUserMockMvc.perform(post("/api/users")
              .contentType(TestUtil.APPLICATION_JSON_UTF8)
              .content(TestUtil.convertObjectToJsonBytes(managedUserVM)))
              .andExpect(status().isBadRequest());
  
          // Validate the User in the database
          List<User> userList = userRepository.findAll();
          assertThat(userList).hasSize(databaseSizeBeforeCreate);
      }
  
      @Test
      @Transactional
      public void getAllUsers() throws Exception {
          // Initialize the database
          userRepository.saveAndFlush(user);
          userSearchRepository.save(user);
  
          // Get all the users
          restUserMockMvc.perform(get("/api/users?sort=id,desc")
              .accept(MediaType.APPLICATION_JSON))
              .andExpect(status().isOk())
              .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
              .andExpect(jsonPath("$.[*].login").value(hasItem(DEFAULT_LOGIN)))
              .andExpect(jsonPath("$.[*].firstName").value(hasItem(DEFAULT_FIRSTNAME)))
              .andExpect(jsonPath("$.[*].lastName").value(hasItem(DEFAULT_LASTNAME)))
              .andExpect(jsonPath("$.[*].email").value(hasItem(DEFAULT_EMAIL)))
              .andExpect(jsonPath("$.[*].imageUrl").value(hasItem(DEFAULT_IMAGEURL)))
              .andExpect(jsonPath("$.[*].langKey").value(hasItem(DEFAULT_LANGKEY)));
      }
  
      @Test
      @Transactional
      public void getUser() throws Exception {
          // Initialize the database
          userRepository.saveAndFlush(user);
          userSearchRepository.save(user);
  
          // Get the user
          restUserMockMvc.perform(get("/api/users/{login}", user.getLogin()))
              .andExpect(status().isOk())
              .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
              .andExpect(jsonPath("$.login").value(user.getLogin()))
              .andExpect(jsonPath("$.firstName").value(DEFAULT_FIRSTNAME))
              .andExpect(jsonPath("$.lastName").value(DEFAULT_LASTNAME))
              .andExpect(jsonPath("$.email").value(DEFAULT_EMAIL))
              .andExpect(jsonPath("$.imageUrl").value(DEFAULT_IMAGEURL))
              .andExpect(jsonPath("$.langKey").value(DEFAULT_LANGKEY));
      }
  
      @Test
      @Transactional
      public void getNonExistingUser() throws Exception {
          restUserMockMvc.perform(get("/api/users/unknown"))
              .andExpect(status().isNotFound());
      }
  
      @Test
      @Transactional
      public void updateUser() throws Exception {
          // Initialize the database
          userRepository.saveAndFlush(user);
          userSearchRepository.save(user);
          int databaseSizeBeforeUpdate = userRepository.findAll().size();
  
          // Update the user
          User updatedUser = userRepository.findOne(user.getId());
  
          Set<String> authorities = new HashSet<>();
          authorities.add("ROLE_USER");
          ManagedUserVM managedUserVM = new ManagedUserVM(
              updatedUser.getId(),
              updatedUser.getLogin(),
              UPDATED_PASSWORD,
              UPDATED_FIRSTNAME,
              UPDATED_LASTNAME,
              UPDATED_EMAIL,
              updatedUser.getActivated(),
              UPDATED_IMAGEURL,
              UPDATED_LANGKEY,
              updatedUser.getCreatedBy(),
              updatedUser.getCreatedDate(),
              updatedUser.getLastModifiedBy(),
              updatedUser.getLastModifiedDate(),
              authorities);
  
          restUserMockMvc.perform(put("/api/users")
              .contentType(TestUtil.APPLICATION_JSON_UTF8)
              .content(TestUtil.convertObjectToJsonBytes(managedUserVM)))
              .andExpect(status().isOk());
  
          // Validate the User in the database
          List<User> userList = userRepository.findAll();
          assertThat(userList).hasSize(databaseSizeBeforeUpdate);
          User testUser = userList.get(userList.size() - 1);
          assertThat(testUser.getFirstName()).isEqualTo(UPDATED_FIRSTNAME);
          assertThat(testUser.getLastName()).isEqualTo(UPDATED_LASTNAME);
          assertThat(testUser.getEmail()).isEqualTo(UPDATED_EMAIL);
          assertThat(testUser.getImageUrl()).isEqualTo(UPDATED_IMAGEURL);
          assertThat(testUser.getLangKey()).isEqualTo(UPDATED_LANGKEY);
      }
  
      @Test
      @Transactional
      public void updateUserLogin() throws Exception {
          // Initialize the database
          userRepository.saveAndFlush(user);
          userSearchRepository.save(user);
          int databaseSizeBeforeUpdate = userRepository.findAll().size();
  
          // Update the user
          User updatedUser = userRepository.findOne(user.getId());
  
          Set<String> authorities = new HashSet<>();
          authorities.add("ROLE_USER");
          ManagedUserVM managedUserVM = new ManagedUserVM(
              updatedUser.getId(),
              UPDATED_LOGIN,
              UPDATED_PASSWORD,
              UPDATED_FIRSTNAME,
              UPDATED_LASTNAME,
              UPDATED_EMAIL,
              updatedUser.getActivated(),
              UPDATED_IMAGEURL,
              UPDATED_LANGKEY,
              updatedUser.getCreatedBy(),
              updatedUser.getCreatedDate(),
              updatedUser.getLastModifiedBy(),
              updatedUser.getLastModifiedDate(),
              authorities);
  
          restUserMockMvc.perform(put("/api/users")
              .contentType(TestUtil.APPLICATION_JSON_UTF8)
              .content(TestUtil.convertObjectToJsonBytes(managedUserVM)))
              .andExpect(status().isOk());
  
          // Validate the User in the database
          List<User> userList = userRepository.findAll();
          assertThat(userList).hasSize(databaseSizeBeforeUpdate);
  