forked from aofeng/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserService.java
More file actions
54 lines (42 loc) · 1.2 KB
/
UserService.java
File metadata and controls
54 lines (42 loc) · 1.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
package cn.aofeng.demo.mockito;
/**
* 用户服务。
*
* @author <a href="mailto:aofengblog@163.com">聂勇</a>
*/
public class UserService {
/** 成人年龄分界线 */
private final static int ADULT_AGE = 18;
private UserDao _userDao;
private CommodityDao _commodityDao;
public boolean isAdult(long userId) {
User user = _userDao.queryById(userId);
if (null == user || user.getAge() < ADULT_AGE) {
return false;
}
return true;
}
public boolean buy(long userId, String commodityId) {
if (! isAdult(userId)) {
return false;
}
Commodity commodity = _commodityDao.queryById(commodityId);
if (null == commodity) {
return false;
}
// 省略余下的处理逻辑
return true;
}
public UserDao getUserDao() {
return _userDao;
}
public void setUserDao(UserDao userDao) {
this._userDao = userDao;
}
public CommodityDao getCommodityDao() {
return _commodityDao;
}
public void setCommodityDao(CommodityDao commodityDao) {
this._commodityDao = commodityDao;
}
}