-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/TeamSevenWeb/Virtual-Wallet…
… into fix-tests-for-transactions
- Loading branch information
Showing
2 changed files
with
33 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import com.telerikacademy.web.virtualwallet.models.*; | ||
import com.telerikacademy.web.virtualwallet.models.wallets.Wallet; | ||
import com.telerikacademy.web.virtualwallet.utils.UserRole; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.HashSet; | ||
|
@@ -10,8 +11,6 @@ public class Helpers { | |
|
||
public static User createMockUser() { | ||
var mockUser = new User(); | ||
Role role = new Role(); | ||
role.setRoleType("admin"); | ||
mockUser.setId(1); | ||
mockUser.setUsername("MockUsername"); | ||
mockUser.setPassword("MockPassword"); | ||
|
@@ -20,7 +19,7 @@ public static User createMockUser() { | |
mockUser.setEmail("[email protected]"); | ||
mockUser.setPhoneNumber("123456789123"); | ||
mockUser.setUserRoles(new HashSet<>()); | ||
mockUser.getUserRoles().add(role); | ||
mockUser.getUserRoles().add(createMockAdminRole()); | ||
mockUser.setUserCards(new HashSet<>()); | ||
mockUser.setWallets(new HashSet<>()); | ||
mockUser.getWallets().add(new Wallet()); | ||
|
@@ -58,6 +57,13 @@ public static Card createMockCard() { | |
return mockCard; | ||
} | ||
|
||
public static Role createMockAdminRole(){ | ||
var mockRole = new Role(); | ||
mockRole.setRoleId(1); | ||
mockRole.setRoleType("admin"); | ||
return mockRole; | ||
} | ||
|
||
public static ProfilePhoto createMockProfilePhoto() { | ||
var profilePhoto = new ProfilePhoto(); | ||
profilePhoto.setUser(createMockUser()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
package com.telerikacademy.web.virtualwallet.services; | ||
|
||
import com.cloudinary.Cloudinary; | ||
import com.cloudinary.Uploader; | ||
import com.cloudinary.utils.ObjectUtils; | ||
import com.telerikacademy.web.virtualwallet.Helpers; | ||
import com.telerikacademy.web.virtualwallet.config.CloudinaryConfig; | ||
import com.telerikacademy.web.virtualwallet.exceptions.EntityDuplicateException; | ||
import com.telerikacademy.web.virtualwallet.exceptions.EntityNotFoundException; | ||
import com.telerikacademy.web.virtualwallet.filters.UserFilterOptions; | ||
import com.telerikacademy.web.virtualwallet.models.Role; | ||
import com.telerikacademy.web.virtualwallet.models.User; | ||
import com.telerikacademy.web.virtualwallet.models.wallets.Wallet; | ||
import com.telerikacademy.web.virtualwallet.repositories.contracts.ProfilePhotoRepository; | ||
import com.telerikacademy.web.virtualwallet.repositories.contracts.UserRepository; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -15,6 +21,8 @@ | |
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.*; | ||
|
||
import static com.telerikacademy.web.virtualwallet.Helpers.createMockUser; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
|
@@ -29,16 +37,25 @@ public class UserServiceImplTests { | |
@Mock | ||
UserRepository mockUserRepository; | ||
|
||
@Mock | ||
private Cloudinary cloudinary; | ||
|
||
@Mock | ||
private Uploader uploader; | ||
|
||
@Mock | ||
private ProfilePhotoRepository profilePhotoRepository; | ||
|
||
@Test | ||
void getAll_Should_CallRepository(){ | ||
//Arrange, Act | ||
Mockito.when(mockUserRepository.getAllUsersFiltered(new UserFilterOptions())).thenReturn(null); | ||
User user = createMockUser(); | ||
mockUserService.getAll(new UserFilterOptions() | ||
,user); | ||
User testUser = createMockUser(); | ||
UserFilterOptions userFilterOptions = new UserFilterOptions("testUsername","[email protected]","1234567890"); | ||
Mockito.when(mockUserRepository.getAllUsersFiltered(userFilterOptions)).thenReturn(new ArrayList<>()); | ||
mockUserService.getAll(userFilterOptions,testUser); | ||
|
||
//Assert | ||
Mockito.verify(mockUserRepository,Mockito.times(1)).getAllUsersFiltered(new UserFilterOptions()); | ||
Mockito.verify(mockUserRepository,Mockito.times(1)).getAllUsersFiltered(userFilterOptions); | ||
} | ||
|
||
@Test | ||
|
@@ -131,7 +148,7 @@ void create_Should_CallRepository_When_UserWithSameUsernameOrEmailDoesNotExist() | |
User user = createMockUser(); | ||
Mockito.when(mockUserRepository.getByField("username",user.getUsername())).thenThrow(EntityNotFoundException.class); | ||
Mockito.when(mockUserRepository.getByField("email",user.getEmail())).thenThrow(EntityNotFoundException.class); | ||
|
||
Mockito.when(cloudinary.uploader()).thenReturn(uploader); | ||
//Act | ||
mockUserService.create(user); | ||
|
||
|
@@ -147,7 +164,7 @@ void create_Should_CallWalletService_When_UserWithSameUsernameOrEmailDoesNotExis | |
User user = createMockUser(); | ||
Mockito.when(mockUserRepository.getByField("username",user.getUsername())).thenThrow(EntityNotFoundException.class); | ||
Mockito.when(mockUserRepository.getByField("email",user.getEmail())).thenThrow(EntityNotFoundException.class); | ||
|
||
Mockito.when(cloudinary.uploader()).thenReturn(uploader); | ||
//Act | ||
mockUserService.create(user); | ||
|
||
|