-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnnotationMain.java
52 lines (42 loc) · 1.51 KB
/
AnnotationMain.java
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
package com.example.annotation;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
public class AnnotationMain implements CommandLineRunner {
private static final Logger log = LoggerFactory.getLogger(AnnotationMain.class);
@Autowired
private UserMapper userMapper;
@Override
public void run(String... args) throws Exception {
Long uid = save();
find(uid);
update(uid);
delete(uid);
}
private Long save() {
User user = new User();
user.setName("user");
user.setGender(Gender.MAN);
Assertions.assertEquals(1, userMapper.save(user));
log.info("save: uid: {}", user.getId());
Assertions.assertNotNull(user.getId());
return user.getId();
}
private void find(Long uid) {
User user = userMapper.find(uid);
log.info("find: {}", user);
Assertions.assertNotNull(user);
Assertions.assertEquals("user", user.getName());
Assertions.assertEquals(Gender.MAN, user.getGender());
}
private void update(Long uid) {
Assertions.assertEquals(1, userMapper.update(uid, "user2"));
Assertions.assertEquals("user2", userMapper.find(uid).getName());
}
private void delete(Long uid) {
Assertions.assertEquals(1, userMapper.delete(uid));
Assertions.assertNull(userMapper.find(uid));
}
}