### Question:
AuthenticationUtils { public static boolean hasRole(Authentication authentication, String role) { Collection<? extends GrantedAuthority> grantedAuthorities = authentication.getAuthorities(); if (grantedAuthorities == null || role == null || role.isEmpty()) { return false; } for (GrantedAuthority auth : grantedAuthorities) { if (role.equalsIgnoreCase(auth.getAuthority())) { return true; } } return false; }  static boolean hasRole(Authentication authentication, String role); static boolean isAdmin(Authentication authentication); static final String ROLE_ADMIN; }### Answer:
@Test public void testHasRole() { List<GrantedAuthority> grantedAuthoritiesList = new ArrayList<GrantedAuthority>(); grantedAuthoritiesList.add(new SimpleGrantedAuthority(VALID_ROLE)); EasyMock.<Collection<? extends GrantedAuthority>>expect(authentication.getAuthorities()).andReturn(grantedAuthoritiesList).anyTimes(); replay(authentication); assertThat(AuthenticationUtils.hasRole(authentication, VALID_ROLE), is(true)); assertThat(AuthenticationUtils.hasRole(authentication, INVALID_ROLE), is(false)); assertThat(AuthenticationUtils.hasRole(authentication, null), is(false)); assertThat(AuthenticationUtils.hasRole(authentication, ""), is(false)); }