11package com .cf .cfteam .controllers .codeforces ;
22
33import com .cf .cfteam .services .codeforces .TeamService ;
4+ import com .cf .cfteam .transfer .payloads .codeforces .TeamPayload ;
5+ import com .cf .cfteam .transfer .responses .codeforces .TeamResponse ;
6+ import org .junit .jupiter .api .BeforeAll ;
7+ import org .junit .jupiter .api .Test ;
48import org .junit .jupiter .api .extension .ExtendWith ;
59import org .mockito .InjectMocks ;
610import org .mockito .Mock ;
711import org .mockito .junit .jupiter .MockitoExtension ;
812import org .springframework .test .context .ActiveProfiles ;
913
14+ import java .util .List ;
15+
16+ import static org .assertj .core .api .Assertions .assertThat ;
17+ import static org .junit .jupiter .api .Assertions .assertAll ;
18+ import static org .mockito .Mockito .*;
19+
1020
1121@ ActiveProfiles ("test" )
1222@ ExtendWith (MockitoExtension .class )
@@ -18,7 +28,85 @@ class TeamControllerTest {
1828 @ Mock
1929 private TeamService teamService ;
2030
31+ private static TeamPayload teamPayload ;
32+ private static TeamResponse teamResponse ;
33+
34+ @ BeforeAll
35+ static void setUp () {
36+ teamPayload = TeamPayload .builder ()
37+ .name ("team name" )
38+ .description ("team description" )
39+ .build ();
40+
41+ teamResponse = TeamResponse .builder ()
42+ .id (1L )
43+ .name ("team name" )
44+ .description ("team description" )
45+ .players (List .of ())
46+ .teamRating (0. )
47+ .build ();
48+ }
49+
50+ @ Test
51+ void shouldReturnAllTeamsByGroup () {
52+ when (teamService .getAllTeamsByGroup (1L )).thenReturn (List .of (teamResponse ));
53+
54+ var teams = teamController .getAllTeamsByGroup (1L , null ).getBody ();
55+
56+ verify (teamService , times (1 )).getAllTeamsByGroup (1L );
57+
58+ assertThat (teams )
59+ .isNotNull ()
60+ .hasSize (1 )
61+ .contains (teamResponse );
62+ }
63+
64+ @ Test
65+ void shouldReturnTeamById () {
66+ when (teamService .getTeamById (1L )).thenReturn (teamResponse );
67+
68+ var result = teamController .getTeamById (1L , null ).getBody ();
69+
70+ verify (teamService , times (1 )).getTeamById (1L );
71+ assertThat (result ).isEqualTo (teamResponse );
72+ }
73+
74+ @ Test
75+ void shouldAddTeamToGroup () {
76+ when (teamService .addTeamToGroup (1L , teamPayload )).thenReturn (teamResponse );
77+
78+ var result = teamController .addTeamToGroup (1L , teamPayload , null ).getBody ();
79+
80+ verify (teamService , times (1 )).addTeamToGroup (1L , teamPayload );
81+
82+ assertThat (result ).isEqualTo (teamResponse );
83+ }
84+
85+ @ Test
86+ void shouldUpdateTeam () {
87+ when (teamService .updateTeam (1L , teamPayload )).thenReturn (teamResponse );
88+
89+ var result = teamController .updateTeam (1L , teamPayload , null ).getBody ();
90+
91+ verify (teamService , times (1 )).updateTeam (1L , teamPayload );
92+ assertAll (
93+ () -> assertThat (result ).isNotNull (),
94+ () -> assertThat (result .name ()).isEqualTo (teamResponse .name ()),
95+ () -> assertThat (result .description ()).isEqualTo (teamResponse .description ())
96+ );
97+ }
98+
99+ @ Test
100+ void shouldDeleteGroup () {
101+ teamController .deleteTeam (1L , null );
21102
103+ verify (teamService , times (1 )).deleteTeam (1L );
104+ }
22105
106+ @ Test
107+ void shouldDeleteAllGroupsByUser () {
108+ teamController .deleteAllTeamsByGroup (1L , null );
23109
110+ verify (teamService , times (1 )).deleteAllTeamsByGroup (1L );
111+ }
24112}
0 commit comments