Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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());
}
}