@RunWith(RaiisIocTestRunner.class)
@IocBean
public class UserTest extends Assert {
@Inject("refer:$ioc")
protected Ioc ioc;
@Test
public void test_service_ok() {
UserService userService = ioc.get(UserService.class);
User user = userService.fetch(1);
assertNotNull(user);
}
}
Service 里面的方法:
@Override
public User fetch(int id) {
if (dao() == null) {
System.out.println(1);
}
User user = dao().fetch(getEntityClass(), Cnd.where("id", "=", id));
if (!Lang.isEmpty(user)) {
dao().fetchLinks(user, "roles");
}
return user;
}