package hdm.mi.sthbackend; import hdm.mi.sthbackend.controller.TournamentController; import hdm.mi.sthbackend.dto.MatchDTO; import hdm.mi.sthbackend.exeptions.MatchIdNotFoundException; import hdm.mi.sthbackend.mapper.ModelToDTOMapper; import hdm.mi.sthbackend.model.Match; import hdm.mi.sthbackend.repository.IMatchRepository; import hdm.mi.sthbackend.repository.IPlayerRepository; import hdm.mi.sthbackend.repository.ITeamRepository; import hdm.mi.sthbackend.repository.ITournamentRepository; import hdm.mi.sthbackend.service.TournamentService; import hdm.mi.sthbackend.types.TeamMatchScore; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnitRunner; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; import org.springframework.beans.factory.annotation.Autowired; import java.util.HashMap; import java.util.Optional; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import static org.hamcrest.Matchers.is; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @AutoConfigureMockMvc @RunWith(MockitoJUnitRunner.class) @SpringBootTest public class t1 { @Mock private IMatchRepository matchRepository; @Mock private ITeamRepository teamRepository; @Mock private IPlayerRepository playerRepository; @Mock private ITournamentRepository tournamentRepository; @Mock private ModelToDTOMapper mapper; @InjectMocks private TournamentController tournamentController; @Autowired private MockMvc mockMvc; @Test public void assignTeamToMatch() throws Exception { UUID matchId = UUID.randomUUID(); MatchDTO testMatch = new MatchDTO(); testMatch.setTeamScores(new HashMap<>()); testMatch.setComment("Sample comment"); // Erstelle ein gültiges Match-Objekt für die Mock-Antwort Match mockMatch = new Match(matchId, new HashMap<>(), UUID.randomUUID(), "Some comment", UUID.randomUUID()); when(matchRepository.findById(matchId)).thenReturn(Optional.of(mockMatch)); when(mapper.mapToMatchDTO(any())).thenReturn(testMatch); verify(matchRepository, times(1)).findById(matchId); verify(matchRepository, times(1)).save(any()); verify(mapper, times(1)).mapToMatchDTO(any()); } }