2010-11-26 2 views
1

바인딩 및 주석에 관한 질문이 있습니다.AbstractModule을 구현하는 클래스에서 주석 객체를 테스트하는 방법

public class MailFacadeImpl implements MailFacade { 

    private final PersonDao personDao; 

    @Inject 
    public MailFacadeImpl(@Mail PersonDao personDao) { 
    super(); 
    this.personDao = personDao; 
    } 

PersonDao는 사용자 정의 주석 주석이 :

나는 다음과 같은 클래스가 있습니다. AbstractModule을 구현하는 클래스 내부에서이 주석을 테스트 할 수 있기를 원합니다.

if(PersonDAO is annotated with(Mail.class)){ 
bind(new TypeLiteral<SecurityRulesFactory<Person>>(){}).toProvider(FactoryProvider.newFactory(
    new TypeLiteral<SecurityRulesFactory<Person>>(){}, new TypeLiteral<MailSecurityRulesCrdb>(){})); 
} 

당신이 그것을 가능하다고 생각하십니까 :

bind(new TypeLiteral<SecurityRulesFactory<Person>>(){}).toProvider(FactoryProvider.newFactory(
    new TypeLiteral<SecurityRulesFactory<Person>>(){}, new TypeLiteral<MailSecurityRulesCrdb>(){})); 

I과 유사한 뭔가를해야만하고 싶은 : 여기

코드의 조각인가?

도움을 주신 분들 :-) 멋진 금요일 되세요!

+0

이 파일을 찾았습니다 : PersonDao.class.isAnnotationPresent (Mail.class). 어쩌면 작동 할 수도 있습니다. 내가 시험해 볼게. – AbstractMan

답변

0

모듈이이 테스트를 수행하는 이유가 명확하지 않습니다. PersonDao 클래스 자체가 Mail로 주석되지 않기 때문에,

bind(PersonDao.class).annotatedWith(Mail.class).to(EmailAwarePersonDao.class); 

참고하여 PersonDao.class.isAnnotationPresent(Mail.class) 여기에 도움이되지 않습니다 : 대신, 모듈 가져 오거나 Mail 주석이 주입 지점에 대한 PersonDao의 인스턴스를 생성하는 방법을 지정할 수 있습니다 ; MailFacadeImpl 생성자에 대한 매개 변수에는 해당 주석이 있습니다. 테스트 할 수있는 방법이 있지만, Guice 모듈에서 테스트하려고하는 경우, 아마 뭔가 잘못하고있을 것입니다.

관련 문제