Repository navigation
Expand file tree
/
Copy pathUserTest.java
More file actions
70 lines (58 loc) · 2.2 KB
/
Copy pathUserTest.java
File metadata and controls
70 lines (58 loc) · 2.2 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
package codesquad.domain;
import codesquad.UnAuthorizedException;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.*;
public class UserTest {
public static final User JAVAJIGI = new User(1L, "javajigi", "password", "name");
public static final User SANJIGI = new User(2L, "sanjigi", "password", "name");
public static User newUser(Long id) {
return new User(id, "userId", "pass", "name");
}
public static User newUser(String userId) {
return newUser(userId, "password");
}
public static User newUser(String userId, String password) {
return new User(1L, userId, password, "name");
}
@Test
public void update_owner() throws Exception {
User origin = newUser("sanjigi");
User loginUser = origin;
User target = new User("sanjigi", "password", "name2");
origin.update(loginUser, target);
assertThat(origin.getName(), is(target.getName()));
}
@Test(expected = UnAuthorizedException.class)
public void update_not_owner() throws Exception {
User origin = newUser("sanjigi");
User loginUser = newUser("javajigi");
User target = new User("sanjigi", "password", "name2");
origin.update(loginUser, target);
}
@Test
public void update_match_password() {
User origin = newUser("sanjigi");
User target = new User("sanjigi", "password", "name2");
origin.update(origin, target);
assertThat(origin.getName(), is(target.getName()));
}
@Test
public void update_mismatch_password() {
User origin = newUser("sanjigi", "password");
User target = new User("sanjigi", "password2", "name2");
origin.update(origin, target);
assertThat(origin.getName(), is(not(target.getName())));
}
@Test
public void match_password() throws Exception {
User user = newUser("sanjigi");
assertTrue(user.matchPassword(user.getPassword()));
}
@Test
public void mismatch_password() throws Exception {
User user = newUser("sanjigi");
assertFalse(user.matchPassword(user.getPassword() + "2"));
}
}