I'm using EasyMock (3.2). I want to write a test for part of my security system based on Spring Security. I want to mock the Authentication
so that it returns empty list of authorities. Its method declaration is as follows:
Collection<? extends GrantedAuthority> getAuthorities();
So I write a test:
Authentication authentication = createMock(Authentication.class);
Collection<? extends GrantedAuthority> authorities = Collections.emptyList();
expect(authentication.getAuthorities()).andReturn(authorities);
But the compiler is complaining about the third line on andReturn
call:
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>
What am I doing wrong?
UPDATE:
When I change the declaration of authorities
to:
Collection<GrantedAuthority> authorities = Collections.emptyList();
as suggested, it still does not compile, but the error is a bit different:
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>)
I ensured that the GrantedAuthority
is actually the same in both declarations - org.springframework.security.core.GrantedAuthority
.