-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathUserServiceTest.java
More file actions
72 lines (61 loc) · 2.84 KB
/
UserServiceTest.java
File metadata and controls
72 lines (61 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.epam.izh.rd.online;
import com.epam.izh.rd.online.entity.User;
import com.epam.izh.rd.online.exception.SimplePasswordException;
import com.epam.izh.rd.online.exception.UserAlreadyRegisteredException;
import com.epam.izh.rd.online.repository.IUserRepository;
import com.epam.izh.rd.online.repository.UserRepository;
import com.epam.izh.rd.online.service.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static com.epam.izh.rd.online.Providers.getUserWithNumberPassword;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class UserServiceTest {
private IUserRepository userRepository;
private IUserService userService;
private Assert assertion = new Assert();
@BeforeEach
private void setup() {
userRepository = new UserRepository();
userService = new UserService(userRepository);
}
@ParameterizedTest
@DisplayName("Тест метода IUserService.register(User user) кейс 1")
@MethodSource("com.epam.izh.rd.online.Providers#testRegisterCase1")
void testRegisterCase1(User user) {
assertThrows(IllegalArgumentException.class,
() -> userService.register(user),
"Ошибка в заполнении полей"
);
}
@Test
@DisplayName("Тест метода IUserService.register(User user) кейс 2")
void testRegisterCase2() {
User user = Providers.getUser();
try {
userService.register(user);
} catch (UserAlreadyRegisteredException | SimplePasswordException e) {
e.printStackTrace();
}
assertion.assertThrowsWithClassName("UserAlreadyRegisteredException", () -> userService.register(user),
"Пользователь с логином " + user.getLogin() + " уже зарегистрирован");
}
@Test
@DisplayName("Тест метода IUserService.register(User user) кейс 3")
void testRegisterCase3() {
User user = getUserWithNumberPassword();
assertion.assertThrowsWithClassName("SimplePasswordException", () -> userService.register(user),
"Пароль не соответствует требованиям безопасности"
);
}
@ParameterizedTest
@MethodSource("com.epam.izh.rd.online.Providers#testDelete")
@DisplayName("Тест метода IUserService.delete(String login)")
void testDelete(User user) {
CurrentUserManager.setCurrentLoggedInUser(user);
assertion.assertThrowsWithClassName("NotAccessException", () -> userService.delete("123"),
"Недостаточно прав для выполнения операции");
}
}