I'm testing my spring controller and trying to do the following
Controller
Authentication authentication = SecurityContextHolder.getContext()
.getAuthentication();
String role = String.valueOf(authentication.getAuthorities());
if(role.contains("user")) {
...
}
Test
@Test
public void testLoginUser() throws Exception {
User user = new User();
user.setLogin("user");
user.setRoleid(1L);
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(user,user));
when(String.valueOf(Collection.class)).thenReturn("user");
But I get
org.mockito.exceptions.misusing.MissingMethodInvocationException
I need my if
block to be true
and execute.
Is there any way it can be done?