// Path: src/main/java/com/jeanchampemont/notedown/NoteDownApplication.java
// @Configuration
// @ComponentScan
// @EnableAutoConfiguration
// @EnableScheduling
// public class NoteDownApplication {
// 
//     public static void main(String[] args) {
//         SpringApplication.run(NoteDownApplication.class, args);
//     }
// 
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/security/AuthenticationService.java
// @Service
// public class AuthenticationService {
//     private UserRepository userRepository;
// 
//     private AuthenticationManager authenticationManager;
// 
//     @Autowired
//     public AuthenticationService(UserRepository userRepository, AuthenticationManager authenticationManager) {
//         this.userRepository = userRepository;
//         this.authenticationManager = authenticationManager;
//     }
// 
//     public User getCurrentUser() {
//         String email = SecurityContextHolder.getContext().getAuthentication().getName();
//         return userRepository.findByEmailIgnoreCase(email);
//     }
// 
//     public boolean isAuthenticated() {
//         return (SecurityContextHolder.getContext().getAuthentication() != null);
//     }
// 
//     public void newAuthentication(String email, String password) {
//         Authentication request = new UsernamePasswordAuthenticationToken(email, password);
//         Authentication result = authenticationManager.authenticate(request);
//         SecurityContextHolder.getContext().setAuthentication(result);
//     }
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/user/persistence/User.java
// @Entity
// @Table(name = "user_account")
// public class User {
//     @Id
//     @GeneratedValue(strategy = GenerationType.TABLE)
//     private long id;
// 
//     @Column(name = "email", unique = true, length = 64)
//     private String email;
// 
//     @Column(name = "password", length = 60)
//     private String password;
// 
//     @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
//     private Set<Note> notes = new HashSet<>();
// 
//     @Column(name = "locale", length = 2)
//     private String locale;
// 
//     @Column(name = "display_name", length = 64)
//     private String displayName;
// 
//     public long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public void setEmail(String email) {
//         this.email = email;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public Set<Note> getNotes() {
//         return notes;
//     }
// 
//     public void setNotes(Set<Note> notes) {
//         this.notes = notes;
//     }
// 
//     public String getLocale() {
//         return locale;
//     }
// 
//     public void setLocale(String locale) {
//         this.locale = locale;
//     }
// 
//     public String getDisplayName() {
//         return displayName;
//     }
// 
//     public void setDisplayName(String displayName) {
//         this.displayName = displayName;
//     }
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/user/persistence/repository/UserRepository.java
// public interface UserRepository extends CrudRepository<User, Long> {
//     User findByEmailIgnoreCase(String email);
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/utils/exception/OperationNotAllowedException.java
// public class OperationNotAllowedException extends RuntimeException {
// 
// }


import java.util.Optional;
import static org.junit.Assert.*;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
import com.jeanchampemont.notedown.NoteDownApplication;
import com.jeanchampemont.notedown.security.AuthenticationService;
import com.jeanchampemont.notedown.user.persistence.User;
import com.jeanchampemont.notedown.user.persistence.repository.UserRepository;
import com.jeanchampemont.notedown.utils.exception.OperationNotAllowedException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

        Optional<User> result = sut.getUserByEmail(email);

        verify(repoMock).findByEmailIgnoreCase(email);

        assertFalse(result.isPresent());
    }

    @Test
    public void testUpdate() {
        String locale = "fr";
        String email = "titi@toto.fr";

        User user = new User();
        user.setId(12);
        user.setEmail(email);
        user.setLocale(locale);

        when(repoMock.findByEmailIgnoreCase(email)).thenReturn(user);
        when(authenticationServiceMock.getCurrentUser()).thenReturn(user);
        when(repoMock.save(user)).thenReturn(user);

        User result = sut.update(user);

        verify(repoMock).findByEmailIgnoreCase(email);
        verify(repoMock).save(user);
        verify(authenticationServiceMock).getCurrentUser();
        assertEquals(locale, user.getLocale());
    }

// Path: src/main/java/com/jeanchampemont/notedown/NoteDownApplication.java
// @Configuration
// @ComponentScan
// @EnableAutoConfiguration
// @EnableScheduling
// public class NoteDownApplication {
// 
//     public static void main(String[] args) {
//         SpringApplication.run(NoteDownApplication.class, args);
//     }
// 
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/security/AuthenticationService.java
// @Service
// public class AuthenticationService {
//     private UserRepository userRepository;
// 
//     private AuthenticationManager authenticationManager;
// 
//     @Autowired
//     public AuthenticationService(UserRepository userRepository, AuthenticationManager authenticationManager) {
//         this.userRepository = userRepository;
//         this.authenticationManager = authenticationManager;
//     }
// 
//     public User getCurrentUser() {
//         String email = SecurityContextHolder.getContext().getAuthentication().getName();
//         return userRepository.findByEmailIgnoreCase(email);
//     }
// 
//     public boolean isAuthenticated() {
//         return (SecurityContextHolder.getContext().getAuthentication() != null);
//     }
// 
//     public void newAuthentication(String email, String password) {
//         Authentication request = new UsernamePasswordAuthenticationToken(email, password);
//         Authentication result = authenticationManager.authenticate(request);
//         SecurityContextHolder.getContext().setAuthentication(result);
//     }
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/user/persistence/User.java
// @Entity
// @Table(name = "user_account")
// public class User {
//     @Id
//     @GeneratedValue(strategy = GenerationType.TABLE)
//     private long id;
// 
//     @Column(name = "email", unique = true, length = 64)
//     private String email;
// 
//     @Column(name = "password", length = 60)
//     private String password;
// 
//     @OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
//     private Set<Note> notes = new HashSet<>();
// 
//     @Column(name = "locale", length = 2)
//     private String locale;
// 
//     @Column(name = "display_name", length = 64)
//     private String displayName;
// 
//     public long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public void setEmail(String email) {
//         this.email = email;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public Set<Note> getNotes() {
//         return notes;
//     }
// 
//     public void setNotes(Set<Note> notes) {
//         this.notes = notes;
//     }
// 
//     public String getLocale() {
//         return locale;
//     }
// 
//     public void setLocale(String locale) {
//         this.locale = locale;
//     }
// 
//     public String getDisplayName() {
//         return displayName;
//     }
// 
//     public void setDisplayName(String displayName) {
//         this.displayName = displayName;
//     }
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/user/persistence/repository/UserRepository.java
// public interface UserRepository extends CrudRepository<User, Long> {
//     User findByEmailIgnoreCase(String email);
// }
// 
// Path: src/main/java/com/jeanchampemont/notedown/utils/exception/OperationNotAllowedException.java
// public class OperationNotAllowedException extends RuntimeException {
// 
// }


// Path: src/test/java/com/jeanchampemont/notedown/user/UserServiceTest.java
import java.util.Optional;
import static org.junit.Assert.*;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
import com.jeanchampemont.notedown.NoteDownApplication;
import com.jeanchampemont.notedown.security.AuthenticationService;
import com.jeanchampemont.notedown.user.persistence.User;
import com.jeanchampemont.notedown.user.persistence.repository.UserRepository;
import com.jeanchampemont.notedown.utils.exception.OperationNotAllowedException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


        Optional<User> result = sut.getUserByEmail(email);

        verify(repoMock).findByEmailIgnoreCase(email);

        assertFalse(result.isPresent());
    }

    @Test
    public void testUpdate() {
        String locale = "fr";
        String email = "titi@toto.fr";

        User user = new User();
        user.setId(12);
        user.setEmail(email);
        user.setLocale(locale);

        when(repoMock.findByEmailIgnoreCase(email)).thenReturn(user);
        when(authenticationServiceMock.getCurrentUser()).thenReturn(user);
        when(repoMock.save(user)).thenReturn(user);

        User result = sut.update(user);

        verify(repoMock).findByEmailIgnoreCase(email);
        verify(repoMock).save(user);
        verify(authenticationServiceMock).getCurrentUser();
        assertEquals(locale, user.getLocale());
    }

    @Test(expected = OperationNotAllowedException.class)