1+ package com .cf .cfteam .utils .codeforces .mappers ;
2+
3+ import com .cf .cfteam .models .entities .codeforces .Group ;
4+ import com .cf .cfteam .models .entities .codeforces .Team ;
5+ import com .cf .cfteam .transfer .payloads .codeforces .TeamPayload ;
6+ import com .cf .cfteam .transfer .responses .codeforces .TeamResponse ;
7+ import org .junit .jupiter .api .Test ;
8+ import org .junit .jupiter .api .extension .ExtendWith ;
9+ import org .mockito .InjectMocks ;
10+ import org .mockito .junit .jupiter .MockitoExtension ;
11+ import org .springframework .test .context .ActiveProfiles ;
12+
13+ import java .util .List ;
14+
15+ import static org .assertj .core .api .Assertions .assertThat ;
16+ import static org .junit .jupiter .api .Assertions .assertAll ;
17+
18+ @ ActiveProfiles ("test" )
19+ @ ExtendWith (MockitoExtension .class )
20+ class TeamMapperTest {
21+
22+ @ InjectMocks
23+ private TeamMapper teamMapper ;
24+
25+ @ Test
26+ void shouldMapFromEntityToResponse () {
27+ Team team = Team .builder ()
28+ .name ("Team name" )
29+ .description (" Team description" )
30+ .id (1L )
31+ .players (null )
32+ .build ();
33+
34+ TeamResponse response = teamMapper .fromEntityToResponse (team );
35+
36+ assertAll (
37+ () -> assertThat (response ).isNotNull (),
38+ () -> assertThat (response .name ()).isEqualTo (team .getName ()),
39+ () -> assertThat (response .description ()).isEqualTo (team .getDescription ()),
40+ () -> assertThat (response .id ()).isEqualTo (team .getId ()),
41+ () -> assertThat (response .players ()).isEqualTo (List .of ()),
42+ () -> assertThat (response .teamRating ()).isEqualTo (0L )
43+ );
44+ }
45+
46+ @ Test
47+ void shouldMapFromPayloadToEntity () {
48+ TeamPayload payload = TeamPayload .builder ()
49+ .name ("team name" )
50+ .description ("team description" )
51+ .build ();
52+ Group group = Group .builder ()
53+ .name ("group name" )
54+ .description ("group descr" )
55+ .build ();
56+
57+ Team team = teamMapper .fromPayloadToEntity (payload , group );
58+
59+ assertAll (
60+ () -> assertThat (team ).isNotNull (),
61+ () -> assertThat (team .getGroup ()).isEqualTo (group ),
62+ () -> assertThat (team .getName ()).isEqualTo (payload .name ()),
63+ () -> assertThat (team .getDescription ()).isEqualTo (payload .description ())
64+ );
65+ }
66+
67+ @ Test
68+ void shouldUpdateEntityFromPayload () {
69+ Team team = Team .builder ()
70+ .name ("Team name" )
71+ .description (" Team description" )
72+ .id (1L )
73+ .players (null )
74+ .build ();
75+
76+ TeamPayload payload = TeamPayload .builder ()
77+ .name ("new team name" )
78+ .description ("new team description" )
79+ .build ();
80+
81+ Team updatedTeam = teamMapper .updateEntityFromPayload (team , payload );
82+
83+ assertAll (
84+ () -> assertThat (updatedTeam ).isNotNull (),
85+ () -> assertThat (updatedTeam .getName ()).isEqualTo (payload .name ()),
86+ () -> assertThat (updatedTeam .getDescription ()).isEqualTo (payload .description ())
87+ );
88+ }
89+ }
0 commit comments