EasyMock (3.2)을 사용하고 있습니다. Spring Security를 기반으로하는 보안 시스템의 일부에 대한 테스트를 작성하려고합니다. 나는 Authentication
을 모의 해 빈 권한리스트를 리턴하도록하고 싶다. 와일드 카드로 제네릭 메서드의 동작을 모의 사용하는 방법
Collection<? extends GrantedAuthority> getAuthorities();
그래서 내가 테스트 쓰기 : 다음과 같이 그 메소드 선언은
Authentication authentication = createMock(Authentication.class);
Collection<? extends GrantedAuthority> authorities = Collections.emptyList();
expect(authentication.getAuthorities()).andReturn(authorities);
을하지만 컴파일러는 andReturn
전화에 세 번째 줄에 대해 불평 :
The method andReturn(Collection<capture#1-of ? extends GrantedAuthority>) in the type IExpectationSetters<Collection<capture#1-of ? extends GrantedAuthority>> is not applicable for the arguments (Collection<capture#2-of ? extends GrantedAuthority>
무엇 내가 틀렸어?
UPDATE :
나는 authorities
의 선언 변경하는 경우 :
Collection<GrantedAuthority> authorities = Collections.emptyList();
, 여전히 컴파일되지 않습니다,하지만 오류가 조금 다릅니다
The method andReturn(Collection<capture#1-of ? extends GrantedAuthority>) in the type IExpectationSetters<Collection<capture#1-of ? extends GrantedAuthority>> is not applicable for the arguments (Collection<GrantedAuthority>)
나는 GrantedAuthority
은 두 선언에서 모두 동일합니다 (org.springframework.security.core.GrantedAuthority
).
와일드 카드 일반이 필요합니까, 아니면 그냥'Collection'로 갈 수 있습니까? –
GriffeyDog
getAuthorities() getter의 실제 반환 유형은 무엇입니까? – Joe
반환 형식의 메서드에서 상한의 와일드 카드를 사용하는 것은 대개 잘못된 생각입니다. 메소드가 무한 일반 타입을 반환하도록하십시오. – Seelenvirtuose