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 7593523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:11:28+00:00 2026-05-30T21:11:28+00:00

PowerMock provides the method expectPrivate to mock out private methods, however it appears only

  • 0

PowerMock provides the method expectPrivate to mock out private methods, however it appears only in EasyMock api and not the Mockito API.

So, is there an equivalent for PowerMockito? I’m guessing not because I haven’t found it and because of this wiki entry. but that doesn’t actually prevent PowerMockito from working around it. So, I’m asking this mostly for confirmation and since I think this will be of value for others.

  • 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-05-30T21:11:29+00:00Added an answer on May 30, 2026 at 9:11 pm

    PowerMockito provides ways to mock private methods as well, from the API:

    <T> WithOrWithoutExpectedArguments<T> when(Object instance, Method method) 
    Expect calls to private methods.
    
    
    verifyPrivate(Object object, org.mockito.verification.VerificationMode verificationMode) 
          Verify a private method invocation with a given verification mode.
    

    There are a bunch of other signatures of the type described above.

    An example:

    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.powermock.api.mockito.PowerMockito;
    import org.powermock.core.classloader.annotations.PrepareForTest;
    import org.powermock.modules.junit4.PowerMockRunner;
    
    import static org.mockito.Matchers.eq;
    
    @RunWith(PowerMockRunner.class)
    @PrepareForTest(Foo.class)
    public class SimpleTest {
    
        @Test
        public void testHello() throws Exception {
            Foo foo = PowerMockito.spy(new Foo());
            foo.sayHello();
            PowerMockito.verifyPrivate(foo).invoke("hello", eq("User"));
        }
    }
    
    class Foo {
        public void sayHello() {
            System.out.println(hello("User"));
        }
    
        private String hello(String user) {
            return "Hello " + user;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JUnit with Mockito. PowerMock can mock static methods but it doesn't seem
I am trying to mock out a private method that is making a JNDI
I am trying to mock a class using Mockito and also using PowerMock. This
I am not being able to run Powermock through maven. I'm the PowerMock Mockito
I use powermock to mock Logger.getInstance() method. This causes a problem as junit seems
I use PowerMock to mock static methods. I need to verify order of static
I found this example where they used PowerMock and EasyMock to stub/mock the Menu
PowerMock throws org.powermock.reflect.exceptions.MethodNotFoundException: No methods matching the name(s) methodInsideFoo were found in the class
As i did some research i have found out that PowerMock is able to
I have class with all the methods static and final. How do I mock

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.