【发布时间】:2014-11-10 23:14:42
【问题描述】:
您好,我定义了以下限定符类型..
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.FIELD })
public @interface SortAndFilterType {
/**
* The value for the sort and filter.
*
* @return the sort and filter type value.
*/
String value();
}
还有两个实现。
@SortAndFilterType("Users")
public class UserSortAndFilterProviderImpl implements SortAndFilterProvider<Field, User> {}
@SortAndFilterType("ReportsList")
public class ReportListSortAndFilterProviderImpl implements SortAndFilterProvider<Field, ReportList> {}
我从客户端注入 ..
@Inject
@SortAndFilterType("Users")
private SortAndFilterProvider mSortAndFilterProvider;
一切都在运行时运行良好..
但是当我运行单元测试时问题就来了..
我收到以下异常..
org.jboss.weld.exceptions.DeploymentException: WELD-001408: 带有限定符 @SortAndFilterType 的类型 SortAndFilterProvider 的依赖关系不满足 在注入点 [BackedAnnotatedField] @Inject @SortAndFilterType private com.collabnet.ctf.saturn.client.apps.users.ChangeUsersStatus.mSortAndFilterProvider
我从这样的单元测试中调用它..它使用@RunWith(CdiRunner.class) 运行
@Produces
@SortAndFilterType("Users")
@Mock
private SortAndFilterProvider mSortAndFilterProvider;
这里出了什么问题?
【问题讨论】:
-
你能分享更多的测试代码吗?
标签: unit-testing mockito cdi jboss-weld cdi-unit