99import org .junit .jupiter .api .BeforeEach ;
1010import org .junit .jupiter .api .Test ;
1111import org .junit .jupiter .api .extension .ExtendWith ;
12+ import org .junit .platform .runner .JUnitPlatform ;
13+ import org .junit .runner .RunWith ;
1214import org .mockito .Mock ;
1315import org .mockito .Mockito ;
1416import org .mockito .invocation .InvocationOnMock ;
2325import com .baeldung .junit5 .mockito .service .UserService ;
2426
2527@ ExtendWith (MockitoExtension .class )
28+ @ RunWith (JUnitPlatform .class )
2629public class UserServiceUnitTest {
2730
2831 UserService userService ;
32+ SettingRepository settingRepository ;
2933 @ Mock UserRepository userRepository ;
3034 @ Mock MailClient mailClient ;
3135
@@ -37,10 +41,11 @@ void init(@Mock SettingRepository settingRepository) {
3741 lenient ().when (settingRepository .getUserMinAge ()).thenReturn (10 );
3842 when (settingRepository .getUserNameMinLength ()).thenReturn (4 );
3943 lenient ().when (userRepository .isUsernameAlreadyExists (any (String .class ))).thenReturn (false );
44+ this .settingRepository = settingRepository ;
4045 }
4146
4247 @ Test
43- void givenValidUser_whenSaveUser_thenSucceed () {
48+ void givenValidUser_whenSaveUser_thenSucceed (@ Mock MailClient mailClient ) {
4449 // Given
4550 user = new User ("Jerry" , 12 );
4651 when (userRepository .insert (any (User .class ))).then (new Answer <User >() {
@@ -53,7 +58,9 @@ public User answer(InvocationOnMock invocation) throws Throwable {
5358 return user ;
5459 }
5560 });
56-
61+
62+ userService = new DefaultUserService (userRepository , settingRepository , mailClient );
63+
5764 // When
5865 User insertedUser = userService .register (user );
5966
0 commit comments