Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7822567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:57:19+00:00 2026-06-02T07:57:19+00:00

For unit testing purposes I want to provide a mock for a javax.security.auth.kerberos.KerberosTicket instance.

  • 0

For unit testing purposes I want to provide a mock for a javax.security.auth.kerberos.KerberosTicket instance. I tried using Mockito and PowerMockito but both failed with a similar message:

org.mockito.exceptions.misusing.MissingMethodInvocationException: 
when() requires an argument which has to be 'a method call on a mock'.
For example:
    when(mock.getArticles()).thenReturn(articles);

Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
   Those methods *cannot* be stubbed/verified.
2. inside when() you don't call method on mock but on some other object.

Adding @RunWith and @PrepareForTest annotations results in following LinkageException:

java.lang.LinkageError:
  loader constraint violation: 
  when resolving method "sun.security.jgss.krb5.Krb5Util.getTicketFromSubjectAndTgs(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/security/AccessControlContext;)Ljavax/security/auth/kerberos/KerberosTicket;"
  the class loader (instance of org/powermock/core/classloader/MockClassLoader) of the current class, 
  org/epo/security/spnego/impl/KerberosUtilsTest, and the class loader (instance of <bootloader>) 
  for resolved class, sun/security/jgss/krb5/Krb5Util, have different Class objects 
  for the type javax/security/auth/kerberos/KerberosTicket used in the signature

My test class looks like this:

@RunWith(PowerMockRunner.class)

@PrepareForTest({KerberosTicket.class})
public class KerberosUtilsTest {

@Test
public void testGetTicketFromSubjectAndTgs() throws LoginException, KrbException, IOException {
    PowerMockito.mockStatic(Krb5Util.class);
    KerberosTicket kerberosTicketMock = PowerMockito.mock(KerberosTicket.class);

    AccessControlContext controlContext = AccessController.getContext();

    // Causes the LinkageError to be thrown
    when(Krb5Util.getTicketFromSubjectAndTgs(-1, "test", "test", "test", controlContext)).thenReturn(
                kerberosTicketMock);

    KerberosTicket actual = new KerberosUtils().getTicketFromSubjectAndTgs(-1, "test", "test", "test",
                controlContext);

    assertEquals(kerberosTicketMock, actual);
}

Searching internet revealed that the LinkageError can be fixed by changing the annotation as such:

@PowerMockIgnore({"sun.security.jgss.krb5.Krb5Util", "javax.security.auth.kerberos.KerberosTicket"})
@PrepareForTest({KerberosUtils.class})
@RunWith(PowerMockRunner.class)

Running this gets me back to square one:

org.mockito.exceptions.misusing.MissingMethodInvocationException: 
when() requires an argument which has to be 'a method call on a mock'.
For example:
    when(mock.getArticles()).thenReturn(articles);

Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
   Those methods *cannot* be stubbed/verified.
2. inside when() you don't call method on mock but on some other object.

Does someone have a solution for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:57:20+00:00Added an answer on June 2, 2026 at 7:57 am

    Most of the methods of KerberosTicket are final, but PowerMockito should be able to mock them.

    Don’t forget to annotate your test class as required by PowerMockito to mock final methods

    @RunWith(PowerMockRunner.class)
    @PrepareForTest(KerberosTicket.class)
    

    and use PowerMockito instead of Mockito inside a test

    KerberosTicket mock = PowerMockito.mock(KerberosTicket.class);
    PowerMockit.when(mock.getAuthTime().thenReturn(...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For unit testing purposes I'm trying to write a mock object of a class
For unit testing a Scala project, I am writing my own simple javax.sql.DataSource class
I'm new with unit testing in visual studio and I want to load a
I use Eclipse + Maven and - for unit testing purposes - the web
I am doing a TDD project using EF. I want to unit test the
I'm trying to setup temporary tables for unit-testing purposes. So far I managed to
My first programming job introduced me to unit testing and the concept of mock
For unit testing purposes: Im searching for testing framework like NUnit that can validate
For learning purposes, I dived into the field of unit testing. I've read through
I am trying to inegerate Google Toolbox for mac for unit testing purposes on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.