// Path: spat-services/src/test/java/com/pcalouche/spat/AbstractControllerTest.java
// @ExtendWith(SpringExtension.class)
// @Import({
//         SpatProperties.class,
//         SecurityUtils.class,
//         SecurityConfig.class
// })
// public abstract class AbstractControllerTest {
//     @Autowired
//     protected ObjectMapper objectMapper;
//     @Autowired
//     protected MockMvc mockMvc;
//     @Autowired
//     protected SecurityUtils securityUtils;
//     @Autowired
//     protected SpatProperties spatProperties;
//     @MockBean
//     protected LoggerInterceptor loggerInterceptor;
//     @MockBean
//     protected UserRepository userRepository;
//     private String validUserToken;
//     private String validAdminToken;
// 
//     protected String getValidUserToken() {
//         if (validUserToken == null) {
//             JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeUser", new HashSet<>());
//             validUserToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
//         }
//         return validUserToken;
//     }
// 
//     protected String getValidAdminToken() {
//         if (validAdminToken == null) {
//             Set<SimpleGrantedAuthority> authorities = Stream.of(new SimpleGrantedAuthority("Admin")).collect(Collectors.toSet());
//             JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeAdmin", authorities);
//             validAdminToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
//         }
//         return validAdminToken;
//     }
// 
//     @BeforeEach
//     public void setup() {
//         // Mock the logger interceptor
//         given(loggerInterceptor.preHandle(any(), any(), any())).willReturn(true);
//     }
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/api/EndpointMessages.java
// public class EndpointMessages {
//     public static final String CURRENT_USER_NOT_FOUND = "Unable to retrieve the current user.";
//     public static final String NO_USER_FOUND = "No user found for id: %d.";
//     public static final String USER_ALREADY_EXISTS = "A user already exists with username: %s.";
//     public static final String NO_TEAM_FOUND = "No team found for id: %d.";
//     public static final String TEAM_ALREADY_EXISTS = "A team already exists with name: %s.";
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/api/Endpoints.java
// public class Endpoints {
//     public static final String AUTH = "/auth";
//     public static final String TOKEN = "/token";
//     public static final String REFRESH_TOKEN = "/refresh-token";
//     public static final String USERS = "/users";
//     public static final String TEAMS = "/teams";
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
//     @EqualsAndHashCode.Exclude
//     private Integer id;
//     private String name;
// 
//     public static TeamDto map(Team team) {
//         return TeamDto.builder()
//                 .id(team.getId())
//                 .name(team.getName())
//                 .build();
//     }
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
//     @NotEmpty
//     private String name;
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/service/TeamService.java
// public interface TeamService {
//     Optional<TeamDto> findById(Integer id);
// 
//     Optional<TeamDto> findByName(String name);
// 
//     List<TeamDto> findAll();
// 
//     TeamDto create(TeamEditRequest teamEditRequest);
// 
//     Optional<TeamDto> update(int id, TeamEditRequest teamEditRequest);
// 
//     void delete(Integer id);
// }


import com.pcalouche.spat.AbstractControllerTest;
import com.pcalouche.spat.api.EndpointMessages;
import com.pcalouche.spat.api.Endpoints;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.service.TeamService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.hamcrest.Matchers.is;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
package com.pcalouche.spat.api.controller;




@WebMvcTest(TeamController.class)
public class TeamControllerTest extends AbstractControllerTest {
    @MockBean
    private TeamService teamService;
    private TeamDto testTeamDto1;
    private TeamDto testTeamDto2;

    @BeforeEach
    public void before() {
        testTeamDto1 = TeamDto.builder()
                .id(1)
                .name("Team1")
                .build();
        testTeamDto2 = TeamDto.builder()
                .id(2)
                .name("Team2")
                .build();
    }

    @Test
    public void testFindAll() throws Exception {
        List<TeamDto> expectedTeamDtos = new ArrayList<>();
        expectedTeamDtos.add(testTeamDto1);
        expectedTeamDtos.add(testTeamDto2);

        given(teamService.findAll()).willReturn(expectedTeamDtos);

// Path: spat-services/src/test/java/com/pcalouche/spat/AbstractControllerTest.java
// @ExtendWith(SpringExtension.class)
// @Import({
//         SpatProperties.class,
//         SecurityUtils.class,
//         SecurityConfig.class
// })
// public abstract class AbstractControllerTest {
//     @Autowired
//     protected ObjectMapper objectMapper;
//     @Autowired
//     protected MockMvc mockMvc;
//     @Autowired
//     protected SecurityUtils securityUtils;
//     @Autowired
//     protected SpatProperties spatProperties;
//     @MockBean
//     protected LoggerInterceptor loggerInterceptor;
//     @MockBean
//     protected UserRepository userRepository;
//     private String validUserToken;
//     private String validAdminToken;
// 
//     protected String getValidUserToken() {
//         if (validUserToken == null) {
//             JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeUser", new HashSet<>());
//             validUserToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
//         }
//         return validUserToken;
//     }
// 
//     protected String getValidAdminToken() {
//         if (validAdminToken == null) {
//             Set<SimpleGrantedAuthority> authorities = Stream.of(new SimpleGrantedAuthority("Admin")).collect(Collectors.toSet());
//             JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeAdmin", authorities);
//             validAdminToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
//         }
//         return validAdminToken;
//     }
// 
//     @BeforeEach
//     public void setup() {
//         // Mock the logger interceptor
//         given(loggerInterceptor.preHandle(any(), any(), any())).willReturn(true);
//     }
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/api/EndpointMessages.java
// public class EndpointMessages {
//     public static final String CURRENT_USER_NOT_FOUND = "Unable to retrieve the current user.";
//     public static final String NO_USER_FOUND = "No user found for id: %d.";
//     public static final String USER_ALREADY_EXISTS = "A user already exists with username: %s.";
//     public static final String NO_TEAM_FOUND = "No team found for id: %d.";
//     public static final String TEAM_ALREADY_EXISTS = "A team already exists with name: %s.";
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/api/Endpoints.java
// public class Endpoints {
//     public static final String AUTH = "/auth";
//     public static final String TOKEN = "/token";
//     public static final String REFRESH_TOKEN = "/refresh-token";
//     public static final String USERS = "/users";
//     public static final String TEAMS = "/teams";
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
//     @EqualsAndHashCode.Exclude
//     private Integer id;
//     private String name;
// 
//     public static TeamDto map(Team team) {
//         return TeamDto.builder()
//                 .id(team.getId())
//                 .name(team.getName())
//                 .build();
//     }
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
//     @NotEmpty
//     private String name;
// }
// 
// Path: spat-services/src/main/java/com/pcalouche/spat/service/TeamService.java
// public interface TeamService {
//     Optional<TeamDto> findById(Integer id);
// 
//     Optional<TeamDto> findByName(String name);
// 
//     List<TeamDto> findAll();
// 
//     TeamDto create(TeamEditRequest teamEditRequest);
// 
//     Optional<TeamDto> update(int id, TeamEditRequest teamEditRequest);
// 
//     void delete(Integer id);
// }


// Path: spat-services/src/test/java/com/pcalouche/spat/api/controller/TeamControllerTest.java
import com.pcalouche.spat.AbstractControllerTest;
import com.pcalouche.spat.api.EndpointMessages;
import com.pcalouche.spat.api.Endpoints;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.service.TeamService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.hamcrest.Matchers.is;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

package com.pcalouche.spat.api.controller;




@WebMvcTest(TeamController.class)
public class TeamControllerTest extends AbstractControllerTest {
    @MockBean
    private TeamService teamService;
    private TeamDto testTeamDto1;
    private TeamDto testTeamDto2;

    @BeforeEach
    public void before() {
        testTeamDto1 = TeamDto.builder()
                .id(1)
                .name("Team1")
                .build();
        testTeamDto2 = TeamDto.builder()
                .id(2)
                .name("Team2")
                .build();
    }

    @Test
    public void testFindAll() throws Exception {
        List<TeamDto> expectedTeamDtos = new ArrayList<>();
        expectedTeamDtos.add(testTeamDto1);
        expectedTeamDtos.add(testTeamDto2);

        given(teamService.findAll()).willReturn(expectedTeamDtos);

        mockMvc.perform(MockMvcRequestBuilders.get(Endpoints.TEAMS)