1

I have a Sigleton class but how to use PoserMock to mock a private method in java?

Is there any sample?

public final class ApimSDKImpl implements ApimSDK {
    /**
     * init sdk
     */
    private ApimSDKImpl() {}

    /**
     * set Singelton
     */
    public static ApimSDKImpl getInstance() {
        if (instance == null) {
            synchronized (ApimSDKImpl.class) {
                if (instance == null) {
                    instance = new ApimSDKImpl();
                }
            }
        }
        return instance;
    }

    /**
     * setSystemConfig
     */
    private String setSystemConfig() {
        return "test";
    }
}

how can I use PowerMock to Mock setSystemConfig function? thanks

Alan Ting
  • 11
  • 1
  • 1
    Check this out [Mocking of Private Methods Using PowerMock](https://www.baeldung.com/powermock-private-method) – abdev Mar 12 '19 at 04:07
  • And you can find a good example [here](https://automationrhapsody.com/mock-private-method-call-powermock/). – abdev Mar 12 '19 at 04:16

0 Answers0