forked from Realhedin/topjava02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserServiceTest.java
More file actions
69 lines (56 loc) · 2.18 KB
/
UserServiceTest.java
File metadata and controls
69 lines (56 loc) · 2.18 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
package ru.javawebinar.topjava.service;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import ru.javawebinar.topjava.UserTestData.*;
import ru.javawebinar.topjava.model.BaseEntity;
import ru.javawebinar.topjava.model.Role;
import ru.javawebinar.topjava.model.User;
import ru.javawebinar.topjava.util.exception.NotFoundException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static ru.javawebinar.topjava.UserTestData.*;
abstract public class UserServiceTest extends DbTest {
@Test
public void testSave() throws Exception {
TestUser tu = new TestUser("New", "new@gmail.com", "newPass", Role.ROLE_USER);
User created = userService.save(tu.asUser());
tu.setId(created.getId());
MATCHER.assertListEquals(Arrays.asList(ADMIN, tu, USER), userService.getAll());
}
@Test(expected = DataAccessException.class)
public void testDuplicateMailSave() throws Exception {
userService.save(new TestUser("Duplicate", "user@yandex.ru", "newPass", Role.ROLE_USER).asUser());
}
@Test
public void testDelete() throws Exception {
userService.delete(BaseEntity.START_SEQ);
MATCHER.assertListEquals(Collections.singletonList(ADMIN), userService.getAll());
}
@Test(expected = NotFoundException.class)
public void testNotFoundDelete() throws Exception {
userService.delete(1);
}
@Test
public void testGet() throws Exception {
User user = userService.get(BaseEntity.START_SEQ);
MATCHER.assertEquals(USER, user);
}
@Test
public void testGetByEmail() throws Exception {
User user = userService.getByEmail("user@yandex.ru");
MATCHER.assertEquals(USER, user);
}
@Test
public void testGetAll() throws Exception {
List<User> all = userService.getAll();
MATCHER.assertListEquals(Arrays.asList(ADMIN, USER), all);
}
@Test
public void testUpdate() throws Exception {
TestUser updated = new TestUser(USER);
updated.setName("UpdatedName");
userService.update(updated.asUser());
MATCHER.assertEquals(updated, userService.get(BaseEntity.START_SEQ));
}
}