Jersey 2将依赖注入单元测试

时间:2016-04-11 08:53:54

标签: java unit-testing dependency-injection jersey jersey-2.0

我有一个像这样的控制器

@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和AccountService
ResourceConfig config = new ResourceConfig()
               .packages("controller", "exception")
               .register(new MyDIBinder());

MyDIBinder包含所有绑定(例如

AccountDaoImpl accountDaoImpl = new AccountDaoImpl();
bind(accountDaoImpl).to(AccountDao.class);

现在我想为这个控制器编写一个单元测试,是否可以将整个AccountController实例及其所有传递依赖项注入测试?

这样的东西
    @Inject
    AccountController accountController;

0 个答案:

没有答案