### Question:
DefaultPermissionChecker implements PermissionChecker { @Override public boolean isPermitted(final String permission, final String accessToken) { Assert.hasText(permission, "Null or empty text was passed as an argument for parameter 'permission'."); Assert.hasText(accessToken, "Null or empty text was passed as an argument for parameter 'accessToken'."); return Try.ofSupplier(() -> resourceServerTokenServices.loadAuthentication(accessToken) ) .filter(authentication -> isPermitted(authentication, permission)) .isSuccess(); } DefaultPermissionChecker(final ResourceServerTokenServices resourceServerTokenServices); @Override boolean isPermitted(final String permission, final String accessToken);  }### Answer:
@Test public void isPermittedWithInvalidArguments() { assertThatThrownBy(() -> permissionChecker.isPermitted(null, uuid())).isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> permissionChecker.isPermitted("", uuid())).isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> permissionChecker.isPermitted(uuid(), null)).isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> permissionChecker.isPermitted(uuid(), "")).isInstanceOf(IllegalArgumentException.class); }
@Test public void isPermittedTrue() { final String permission = uuid(); final String token = uuid(); expect(oAuth2Authentication.getAuthorities()).andReturn(Collections.singleton(new SimpleGrantedAuthority(permission))); expect(resourceServerTokenServices.loadAuthentication(token)).andReturn(oAuth2Authentication); replayAll(); assertThat(permissionChecker.isPermitted(permission, token)).isTrue(); verifyAll(); }
@Test public void isPermittedFalse() { final String permission = uuid(); final String token = uuid(); expect(oAuth2Authentication.getAuthorities()).andReturn(Collections.singleton(new SimpleGrantedAuthority(uuid()))); expect(resourceServerTokenServices.loadAuthentication(token)).andReturn(oAuth2Authentication); replayAll(); assertThat(permissionChecker.isPermitted(permission, token)).isFalse(); verifyAll(); }