This repository was archived by the owner on Dec 27, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +32
-44
lines changed
src/test/java/com/cf/cfteam Expand file tree Collapse file tree 7 files changed +32
-44
lines changed Original file line number Diff line number Diff line change 33import com .cf .cfteam .services .codeforces .GroupService ;
44import com .cf .cfteam .transfer .payloads .codeforces .GroupPayload ;
55import com .cf .cfteam .transfer .responses .codeforces .GroupResponse ;
6- import org .junit .jupiter .api .BeforeEach ;
6+ import org .junit .jupiter .api .BeforeAll ;
77import org .junit .jupiter .api .Test ;
8+ import org .junit .jupiter .api .extension .ExtendWith ;
89import org .mockito .InjectMocks ;
910import org .mockito .Mock ;
10- import org .mockito .MockitoAnnotations ;
11+ import org .mockito .junit . jupiter . MockitoExtension ;
1112import org .springframework .test .context .ActiveProfiles ;
1213
1314import java .util .List ;
1819
1920
2021@ ActiveProfiles ("test" )
22+ @ ExtendWith (MockitoExtension .class )
2123class GroupControllerTest {
2224
2325 @ InjectMocks
@@ -26,19 +28,11 @@ class GroupControllerTest {
2628 @ Mock
2729 private GroupService groupService ;
2830
29- private GroupPayload groupPayload ;
30- private GroupResponse groupResponse ;
31-
32- @ BeforeEach
33- void setUp () {
34- MockitoAnnotations .openMocks (this );
35-
36- // group = Group.builder()
37- // .name("Test Group")
38- // .description("Test description")
39- // .user(null)
40- // .build();
31+ private static GroupPayload groupPayload ;
32+ private static GroupResponse groupResponse ;
4133
34+ @ BeforeAll
35+ static void setUp () {
4236 groupPayload = GroupPayload .builder ()
4337 .name ("Test Group" )
4438 .description ("Test description" )
Original file line number Diff line number Diff line change 11package com .cf .cfteam .controllers .codeforces ;
22
3+ import com .cf .cfteam .services .codeforces .TeamService ;
4+ import org .junit .jupiter .api .extension .ExtendWith ;
35import org .mockito .InjectMocks ;
6+ import org .mockito .Mock ;
7+ import org .mockito .junit .jupiter .MockitoExtension ;
48import org .springframework .test .context .ActiveProfiles ;
59
6- import static org .junit .jupiter .api .Assertions .*;
710
811@ ActiveProfiles ("test" )
12+ @ ExtendWith (MockitoExtension .class )
913class TeamControllerTest {
1014
1115 @ InjectMocks
1216 private TeamController teamController ;
1317
18+ @ Mock
19+ private TeamService teamService ;
20+
21+
1422
1523
1624}
Original file line number Diff line number Diff line change 88import com .cf .cfteam .transfer .responses .security .JwtAuthenticationResponse ;
99import org .junit .jupiter .api .BeforeEach ;
1010import org .junit .jupiter .api .Test ;
11+ import org .junit .jupiter .api .extension .ExtendWith ;
1112import org .mockito .InjectMocks ;
1213import org .mockito .Mock ;
1314import org .mockito .MockitoAnnotations ;
15+ import org .mockito .junit .jupiter .MockitoExtension ;
1416import org .springframework .test .context .ActiveProfiles ;
1517import org .springframework .security .core .Authentication ;
1618
1921import static org .mockito .Mockito .when ;
2022
2123@ ActiveProfiles ("test" )
24+ @ ExtendWith (MockitoExtension .class )
2225class UserControllerTest {
2326
2427 @ InjectMocks
@@ -30,11 +33,6 @@ class UserControllerTest {
3033 @ Mock
3134 private Authentication authentication ;
3235
33- @ BeforeEach
34- void setUp () {
35- MockitoAnnotations .openMocks (this );
36- }
37-
3836 @ Test
3937 void testRegister_success () {
4038 RegistrationPayload registrationPayload = getRegistrationPayload ();
Original file line number Diff line number Diff line change 1212import com .cf .cfteam .utils .codeforces .mappers .GroupMapper ;
1313import org .junit .jupiter .api .BeforeEach ;
1414import org .junit .jupiter .api .Test ;
15+ import org .junit .jupiter .api .extension .ExtendWith ;
1516import org .mockito .InjectMocks ;
1617import org .mockito .Mock ;
1718import org .mockito .MockitoAnnotations ;
19+ import org .mockito .junit .jupiter .MockitoExtension ;
1820import org .springframework .test .context .ActiveProfiles ;
1921
2022import java .util .List ;
2729import static org .mockito .Mockito .*;
2830
2931@ ActiveProfiles ("test" )
32+ @ ExtendWith (MockitoExtension .class )
3033class GroupServiceTest {
3134
3235 @ InjectMocks
@@ -48,7 +51,6 @@ class GroupServiceTest {
4851
4952 @ BeforeEach
5053 void setUp () {
51- MockitoAnnotations .openMocks (this );
5254
5355 user = User .builder ()
5456 .name ("User name" )
@@ -164,8 +166,6 @@ void updateGroup_ShouldThrowGroupNotFoundException_WhenGroupDoesNotExist() {
164166
165167 @ Test
166168 void deleteGroup_ShouldDeleteGroup_WhenGroupExists () {
167- when (groupRepository .findById (1L )).thenReturn (Optional .of (group ));
168-
169169 groupService .deleteGroup (1L );
170170
171171 verify (groupRepository , times (1 )).deleteById (1L );
Original file line number Diff line number Diff line change 1212import com .cf .cfteam .transfer .payloads .security .ChangePasswordPayload ;
1313import com .cf .cfteam .transfer .payloads .security .RegistrationPayload ;
1414import com .cf .cfteam .transfer .responses .security .JwtAuthenticationResponse ;
15- import org .junit .jupiter .api .BeforeEach ;
1615import org .junit .jupiter .api .Test ;
16+ import org .junit .jupiter .api .extension .ExtendWith ;
1717import org .mockito .InjectMocks ;
1818import org .mockito .Mock ;
19- import org .mockito .MockitoAnnotations ;
19+ import org .mockito .junit . jupiter . MockitoExtension ;
2020import org .springframework .security .authentication .AuthenticationManager ;
2121import org .springframework .security .core .Authentication ;
2222import org .springframework .security .crypto .password .PasswordEncoder ;
2929import static org .mockito .Mockito .*;
3030
3131@ ActiveProfiles ("test" )
32+ @ ExtendWith (MockitoExtension .class )
3233class AuthenticationServiceTest {
3334
3435 @ InjectMocks
@@ -55,11 +56,6 @@ class AuthenticationServiceTest {
5556 @ Mock
5657 private UserDetails userDetails ;
5758
58- @ BeforeEach
59- void setUp () {
60- MockitoAnnotations .openMocks (this );
61- }
62-
6359 @ Test
6460 void register_shouldThrowException_WhenUserAlreadyRegistered () {
6561 String login = "testLogin" ;
Original file line number Diff line number Diff line change 22
33import com .cf .cfteam .models .entities .security .User ;
44import com .cf .cfteam .repositories .jpa .security .UserRepository ;
5- import org .junit .jupiter .api .BeforeEach ;
65import org .junit .jupiter .api .Test ;
6+ import org .junit .jupiter .api .extension .ExtendWith ;
77import org .mockito .InjectMocks ;
88import org .mockito .Mock ;
9- import org .mockito .MockitoAnnotations ;
9+ import org .mockito .junit . jupiter . MockitoExtension ;
1010import org .springframework .security .core .userdetails .UserDetails ;
1111import org .springframework .security .core .userdetails .UsernameNotFoundException ;
1212import org .springframework .test .context .ActiveProfiles ;
1818import static org .mockito .Mockito .when ;
1919
2020@ ActiveProfiles ("test" )
21+ @ ExtendWith (MockitoExtension .class )
2122class MyUserDetailsServiceTest {
2223
2324 @ Mock
@@ -26,11 +27,6 @@ class MyUserDetailsServiceTest {
2627 @ InjectMocks
2728 private MyUserDetailsService userDetailsService ;
2829
29- @ BeforeEach
30- void setUp () {
31- MockitoAnnotations .openMocks (this );
32- }
33-
3430 @ Test
3531 void loadUserByUsername_shouldLoadUserByUsername_WhenUserExists () {
3632 String login = "testLogin" ;
Original file line number Diff line number Diff line change 44import com .cf .cfteam .exceptions .security .TokenNotFoundException ;
55import com .cf .cfteam .models .entities .security .Token ;
66import com .cf .cfteam .repositories .jpa .security .TokenRepository ;
7- import org .junit .jupiter .api .BeforeEach ;
87import org .junit .jupiter .api .Test ;
8+ import org .junit .jupiter .api .extension .ExtendWith ;
99import org .mockito .InjectMocks ;
1010import org .mockito .Mock ;
11- import org .mockito .MockitoAnnotations ;
11+ import org .mockito .junit . jupiter . MockitoExtension ;
1212import org .springframework .test .context .ActiveProfiles ;
1313
1414import java .util .Optional ;
1818import static org .mockito .Mockito .*;
1919
2020@ ActiveProfiles ("test" )
21+ @ ExtendWith (MockitoExtension .class )
2122class TokenServiceTest {
2223
2324 @ InjectMocks
@@ -26,11 +27,6 @@ class TokenServiceTest {
2627 @ Mock
2728 private TokenRepository tokenRepository ;
2829
29- @ BeforeEach
30- void setUp () {
31- MockitoAnnotations .openMocks (this );
32- }
33-
3430 @ Test
3531 void isTokenRevoked_shouldReturnTrue_whenTokenIsRevoked () {
3632 String tokenValue = "valid-token" ;
You can’t perform that action at this time.
0 commit comments