### Question:
AuthenticationJsonWebToken implements Authentication, JwtAuthentication { @Override public Collection<? extends GrantedAuthority> getAuthorities() { List<SimpleGrantedAuthority> scopes = getScopeAuthorities(); List<SimpleGrantedAuthority> permissions = getPermissionAuthorities(); List<GrantedAuthority> authorities = new ArrayList<>(); authorities.addAll(scopes); authorities.addAll(permissions); return authorities; } AuthenticationJsonWebToken(String token, JWTVerifier verifier); @Override String getToken(); @Override String getKeyId(); @Override Authentication verify(JWTVerifier verifier); @Override Collection<? extends GrantedAuthority> getAuthorities(); @Override Object getCredentials(); @Override Object getDetails(); @Override Object getPrincipal(); @Override boolean isAuthenticated(); @Override void setAuthenticated(boolean isAuthenticated); @Override String getName();  }### Answer:
@Test public void shouldGetEmptyAuthoritiesOnMissingScopeClaim() throws Exception { String token = JWT.create() .sign(hmacAlgorithm); AuthenticationJsonWebToken auth = new AuthenticationJsonWebToken(token, verifier); assertThat(auth, is(notNullValue())); assertThat(auth.getAuthorities(), is(notNullValue())); assertThat(auth.getAuthorities(), is(IsEmptyCollection.empty())); }
@Test public void shouldGetEmptyAuthoritiesOnEmptyScopeClaim() throws Exception { String token = JWT.create() .withClaim("scope", " ") .sign(hmacAlgorithm); AuthenticationJsonWebToken auth = new AuthenticationJsonWebToken(token, verifier); assertThat(auth, is(notNullValue())); assertThat(auth.getAuthorities(), is(notNullValue())); assertThat(auth.getAuthorities(), is(IsEmptyCollection.empty())); }
@Test public void shouldGetScopeAsAuthorities() throws Exception { String token = JWT.create() .withClaim("scope", "auth0 auth10") .sign(hmacAlgorithm); AuthenticationJsonWebToken auth = new AuthenticationJsonWebToken(token, verifier); assertThat(auth, is(notNullValue())); Collection<? extends GrantedAuthority> authorities = auth.getAuthorities(); assertThat(authorities, is(notNullValue())); assertThat(authorities, is(IsCollectionWithSize.hasSize(4))); assertThat(authorities, containsInAnyOrder( hasProperty("authority", is("auth0")), hasProperty("authority", is("auth10")), hasProperty("authority", is("SCOPE_auth0")), hasProperty("authority", is("SCOPE_auth10")) )); }
@Test public void shouldGetEmptyAuthoritiesOnEmptyPermissionsClaim() throws Exception { String token = JWT.create() .withArrayClaim("permissions", new String[]{}) .sign(hmacAlgorithm); AuthenticationJsonWebToken auth = new AuthenticationJsonWebToken(token, verifier); assertThat(auth, is(notNullValue())); assertThat(auth.getAuthorities(), is(notNullValue())); assertThat(auth.getAuthorities(), is(IsEmptyCollection.empty())); }
@Test public void shouldGetPermissionsAsAuthorities() throws Exception { String[] permissionsClaim = {"read:permission", "write:permission"}; String token = JWT.create() .withArrayClaim("permissions", permissionsClaim) .sign(hmacAlgorithm); AuthenticationJsonWebToken auth = new AuthenticationJsonWebToken(token, verifier); assertThat(auth, is(notNullValue())); assertThat(auth.getAuthorities(), is(notNullValue())); assertThat(auth.getAuthorities(), is(IsCollectionWithSize.hasSize(2))); Collection<? extends GrantedAuthority> authorities = auth.getAuthorities(); assertThat(authorities, IsCollectionWithSize.hasSize(2)); assertThat(authorities, containsInAnyOrder( hasProperty("authority", is("PERMISSION_" + permissionsClaim[0])), hasProperty("authority", is("PERMISSION_" + permissionsClaim[1])) )); }