<commit_before>package com.jos.dem.vetlog.unit

import spock.lang.Specification

import com.jos.dem.vetlog.service.UserService
import com.jos.dem.vetlog.service.impl.UserServiceImpl
import com.jos.dem.vetlog.repository.UserRepository
import com.jos.dem.vetlog.binder.UserBinder
import com.jos.dem.vetlog.model.User
import com.jos.dem.vetlog.model.Role
import com.jos.dem.vetlog.command.Command
import com.jos.dem.vetlog.command.UserCommand

class UserServiceSpec extends Specification {

  UserService userService = new UserServiceImpl()

  UserRepository userRepository = Mock(UserRepository)
  UserBinder userBinder = new UserBinder()

  def setup(){
    userService.userRepository = userRepository
    userService.userBinder = userBinder
  }

  void "should find an user by username"(){
    given:"An username"
      String username = 'username'
    when:"We find by username"
      userService.getByUsername(username)
    then:"We expect repository delegation"
    1 * userRepository.findByUsername(username)
  }

  void "should find an user by email"(){
    given:"An email"
      String email = 'email'
    when:"We find by email"
      userService.getByEmail(email)
    then:"We expect repository delegation"
    1 * userRepository.findByEmail(email)
  }

  void "should save an user"(){
    given:"A command"
      Command command = new UserCommand(username:'josdem',password:'password', passwordConfirmation:'password', name:'josdem',lastname:'lastname',email:'<EMAIL>')
    when:"We save an user"
      User user = userService.save(command)
    then:"We expect repository delegation"
    1 * userRepository.save(_ as User)
    user.username == 'josdem'
    user.password.size() == 60
    user.firstName == 'josdem'
    user.lastName == 'lastname'
    user.email == '<EMAIL>'
    user.role == Role.USER
  }

}<commit_msg>#14 Fixing user service test<commit_after>package com.jos.dem.vetlog.unit

import spock.lang.Specification

import com.jos.dem.vetlog.service.UserService
import com.jos.dem.vetlog.service.RecoveryService
import com.jos.dem.vetlog.service.impl.UserServiceImpl
import com.jos.dem.vetlog.repository.UserRepository
import com.jos.dem.vetlog.binder.UserBinder
import com.jos.dem.vetlog.model.User
import com.jos.dem.vetlog.model.Role
import com.jos.dem.vetlog.command.Command
import com.jos.dem.vetlog.command.UserCommand

class UserServiceSpec extends Specification {

  UserService userService = new UserServiceImpl()

  UserRepository userRepository = Mock(UserRepository)
  RecoveryService recoveryService = Mock(RecoveryService)
  UserBinder userBinder = new UserBinder()

  def setup(){
    userService.userRepository = userRepository
    userService.userBinder = userBinder
    userService.recoveryService = recoveryService
  }

  void "should find an user by username"(){
    given:"An username"
      String username = 'username'
    when:"We find by username"
      userService.getByUsername(username)
    then:"We expect repository delegation"
    1 * userRepository.findByUsername(username)
  }

  void "should find an user by email"(){
    given:"An email"
      String email = 'email'
    when:"We find by email"
      userService.getByEmail(email)
    then:"We expect repository delegation"
    1 * userRepository.findByEmail(email)
  }

  void "should save an user"(){
    given:"A command"
      Command command = new UserCommand(username:'josdem',password:'password', passwordConfirmation:'password', name:'josdem',lastname:'lastname',email:'<EMAIL>')
    when:"We save an user"
      User user = userService.save(command)
    then:"We expect repository delegation"
    1 * userRepository.save(_ as User)
    1 * recoveryService.sendConfirmationAccountToken('<EMAIL>')
    user.username == 'josdem'
    user.password.size() == 60
    user.firstName == 'josdem'
    user.lastName == 'lastname'
    user.email == '<EMAIL>'
    user.role == Role.USER
  }

}
{'fraction_non_alphanumeric': 0.10854503464203233, 'fraction_numerical': 0.0033358994098024123, 'mean_word_length': 4.156084656084656, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1889009', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1147, 'n_words': 267}