// Path: spat-services/src/main/java/com/pcalouche/spat/entity/User.java
// @Entity
// @Table(name = "users")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class User implements UserDetails {
//     @Id
//     @GeneratedValue(strategy = GenerationType.IDENTITY)
//     private Integer id;
//     @NotBlank
//     @Column(unique = true, nullable = false)
//     private String username;
//     @NotBlank
//     @Column(nullable = false)
//     private String password;
//     @Builder.Default
//     private boolean accountNonExpired = true;
//     @Builder.Default
//     private boolean accountNonLocked = true;
//     @Builder.Default
//     private boolean credentialsNonExpired = true;
//     @Builder.Default
//     private boolean enabled = true;
//     @ManyToMany(fetch = FetchType.EAGER)
//     @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
//     @Builder.Default
//     private Set<Role> roles = new HashSet<>();
//     @Transient
//     @Setter(AccessLevel.NONE)
//     private Set<SimpleGrantedAuthority> authorities;
// 
//     @Override
//     public Set<SimpleGrantedAuthority> getAuthorities() {
//         if (authorities == null) {
//             authorities = new HashSet<>();
//             if (roles != null) {
//                 for (Role role : roles) {
//                     authorities.add(new SimpleGrantedAuthority(role.getName()));
//                 }
//             }
//         }
//         return authorities;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) {
//             return true;
//         }
//         if (!(o instanceof User)) {
//             return false;
//         }
//         User castedObj = (User) o;
//         return Objects.equals(username, castedObj.getUsername());
//     }
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(username);
//     }
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/UserRepository.java
// @Repository
// public interface UserRepository extends JpaRepository<User, Integer> {
//     Optional<User> findByUsername(String username);
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/security/authentication/JwtAuthenticationToken.java
// public class JwtAuthenticationToken extends AbstractAuthenticationToken {
//     private final String subject;
//     private final String token;
// 
//     public JwtAuthenticationToken(String token) {
//         super(null);
//         this.token = token;
//         subject = null;
//         setAuthenticated(false);
//     }
// 
//     public JwtAuthenticationToken(String subject,
//                                   Collection<? extends GrantedAuthority> authorities) {
//         super(authorities);
//         this.subject = subject;
//         this.token = null;
//         setAuthenticated(true);
//     }
// 
//     @Override
//     public String getPrincipal() {
//         return subject;
//     }
// 
//     @Override
//     public String getCredentials() {
//         return token;
//     }
// }


import com.pcalouche.spat.entity.User;
import com.pcalouche.spat.repository.UserRepository;
import com.pcalouche.spat.security.authentication.JwtAuthenticationToken;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
package com.pcalouche.spat.security.provider;




@ExtendWith(SpringExtension.class)
public class LoginAuthenticationProviderTest {
    private LoginAuthenticationProvider loginAuthenticationProvider;
    @MockBean
    private UserRepository userRepository;

    @BeforeEach
    public void before() {
        Mockito.reset(userRepository);

// Path: spat-services/src/main/java/com/pcalouche/spat/entity/User.java
// @Entity
// @Table(name = "users")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class User implements UserDetails {
//     @Id
//     @GeneratedValue(strategy = GenerationType.IDENTITY)
//     private Integer id;
//     @NotBlank
//     @Column(unique = true, nullable = false)
//     private String username;
//     @NotBlank
//     @Column(nullable = false)
//     private String password;
//     @Builder.Default
//     private boolean accountNonExpired = true;
//     @Builder.Default
//     private boolean accountNonLocked = true;
//     @Builder.Default
//     private boolean credentialsNonExpired = true;
//     @Builder.Default
//     private boolean enabled = true;
//     @ManyToMany(fetch = FetchType.EAGER)
//     @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
//     @Builder.Default
//     private Set<Role> roles = new HashSet<>();
//     @Transient
//     @Setter(AccessLevel.NONE)
//     private Set<SimpleGrantedAuthority> authorities;
// 
//     @Override
//     public Set<SimpleGrantedAuthority> getAuthorities() {
//         if (authorities == null) {
//             authorities = new HashSet<>();
//             if (roles != null) {
//                 for (Role role : roles) {
//                     authorities.add(new SimpleGrantedAuthority(role.getName()));
//                 }
//             }
//         }
//         return authorities;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) {
//             return true;
//         }
//         if (!(o instanceof User)) {
//             return false;
//         }
//         User castedObj = (User) o;
//         return Objects.equals(username, castedObj.getUsername());
//     }
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(username);
//     }
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/UserRepository.java
// @Repository
// public interface UserRepository extends JpaRepository<User, Integer> {
//     Optional<User> findByUsername(String username);
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/security/authentication/JwtAuthenticationToken.java
// public class JwtAuthenticationToken extends AbstractAuthenticationToken {
//     private final String subject;
//     private final String token;
// 
//     public JwtAuthenticationToken(String token) {
//         super(null);
//         this.token = token;
//         subject = null;
//         setAuthenticated(false);
//     }
// 
//     public JwtAuthenticationToken(String subject,
//                                   Collection<? extends GrantedAuthority> authorities) {
//         super(authorities);
//         this.subject = subject;
//         this.token = null;
//         setAuthenticated(true);
//     }
// 
//     @Override
//     public String getPrincipal() {
//         return subject;
//     }
// 
//     @Override
//     public String getCredentials() {
//         return token;
//     }
// }


// Path: spat-services/src/test/java/com/pcalouche/spat/security/provider/LoginAuthenticationProviderTest.java
import com.pcalouche.spat.entity.User;
import com.pcalouche.spat.repository.UserRepository;
import com.pcalouche.spat.security.authentication.JwtAuthenticationToken;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;

package com.pcalouche.spat.security.provider;




@ExtendWith(SpringExtension.class)
public class LoginAuthenticationProviderTest {
    private LoginAuthenticationProvider loginAuthenticationProvider;
    @MockBean
    private UserRepository userRepository;

    @BeforeEach
    public void before() {
        Mockito.reset(userRepository);

        User activeUser = User.builder()