title: jUnit testing KeycloakAuthenticationToken
body: <p>I'm trying to cover my code <code>coverage</code> with <code>jUnit</code>, but I'm having problems because of  <code>KeycloakPrincipal</code>.
  The method which I want to test and cover is isRoleAdmin(), which calls another method.</p>
  <pre><code>public Boolean isRoleAdmin() {
      Map&lt;String, Access&gt; resources = getAccessToken().getResourceAccess();
      Access access = resources.get(projectName);
      if(access == null) return false;
      return access.getRoles().contains(admin) || access.getRoles().contains(superadmin);
  }
  
  public AccessToken getAccessToken() {
      KeycloakAuthenticationToken token = (KeycloakAuthenticationToken) request.getUserPrincipal();        
      KeycloakPrincipal principal = (KeycloakPrincipal) token.getPrincipal();
      KeycloakSecurityContext session = principal.getKeycloakSecurityContext();
      return session.getToken();
  }   
  </code></pre>
  <p>My test :</p>
  <pre><code>@Test
  void getContactListTest() {
  
      KeycloakAccount keycloakAccount = new KeycloakAccount() {
          
          @Override
          public Set&lt;String&gt; getRoles() {
              return null;
          }
          
          @Override
          public Principal getPrincipal() {
              return new Principal() {
                  
                  @Override
                  public String getName() {
                      return &quot;Name&quot;;
                  }
              };
          }
      };
      given((KeycloakAuthenticationToken) request.getUserPrincipal()).willReturn(new KeycloakAuthenticationToken(keycloakAccount, false) {            
      });
      assertNotNull(contactService.isRoleAdmin());
  </code></pre>
  <p>I have the problem when getAccessToken() is called, in token.getPrincipal(), where I can't mock it and it gives me an error:</p>
  <pre><code>   java.lang.ClassCastException: class com.editran.contacts.test.controller.ContactControllerTest$1$1 cannot be cast to class org.keycloak.KeycloakPrincipal (com.editran.contacts.test.controller.ContactControllerTest$1$1 and org.keycloak.KeycloakPrincipal are in unnamed module of loader 'app')
  </code></pre>
  <p>How can I end coverage for this method? Is there any way to avoid this error?</p>