我有一个像这样的控制器
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class AccountController implements CRUDController<Long, Account> {
private AccountDao accountDao;
private AccountService accountService;
@Inject
public AccountController(AccountDao accountDao, AccountService accountService) {
this.accountDao = accountDao;
this.accountService = accountService;
}
...
我正在使用
注入AccountDao和AccountServiceResourceConfig config = new ResourceConfig()
.packages("controller", "exception")
.register(new MyDIBinder());
MyDIBinder包含所有绑定(例如
AccountDaoImpl accountDaoImpl = new AccountDaoImpl();
bind(accountDaoImpl).to(AccountDao.class);
)
现在我想为这个控制器编写一个单元测试,是否可以将整个AccountController实例及其所有传递依赖项注入测试?
像
这样的东西 @Inject
AccountController accountController;