Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported fake for private method #714

Open
ondrejlerch opened this issue Aug 5, 2021 · 2 comments
Open

Unsupported fake for private method #714

ondrejlerch opened this issue Aug 5, 2021 · 2 comments

Comments

@ondrejlerch
Copy link

From JMockit 1.47 it is not possible to mock private methods, such attempt leads to "Unsupported fake for private method" exception,

We find private method mocking useful in a situation when we call third party libraries out of our control.

E.g. We are using spring-ws and want to check what kind of soap request was actually sent. With JMockit <= 1.46 we have used:

new MockUp<WebServiceTemplate>() {
    @Mock
    private void sendRequest(Invocation invocation, WebServiceConnection connection, WebServiceMessage request) throws IOException {
        // some assert here
        invocation.proceed(connection, request);
    }
};

Obviously WebServiceTemplate code is out of our control:
https://github.com/spring-projects/spring-ws/blob/main/spring-ws-core/src/main/java/org/springframework/ws/client/core/WebServiceTemplate.java#L626

JMockit was a great mocking tool for such corner cases and it allowed us to mock anything, including private methods of third party libraries.

We have been happily using JMockit for a long time on many projects and now we are stuck with 1.46 since we don't want to investigate how to replace all our private method mocks with some protected or public counterparts which is not straightforward, desirable or even possible.

Therefore we suggest to put private method mocking back. Or at least disable it by default and enable it somehow via JMockit API if you find it dangerous.

PS: We have noticed that JMockit was not released since 2019. We would be happy if this project continues since we find it great.

Many thanks ✌

@AlexFTrapp
Copy link

I too would like to have tha abbility back to mock private methods. In my case these private methods are mocked in order to reduce complexity of test cases.
For example the method under test calls some private method and this private method provides access to cached items and has a fallback if an item is not in cache (load from db). In any case I want to mock the private method to return items with special field values matching the test set. Using the cache or accessing the DB is NOT of concern when testing the method under test.

@AskSantoshYadav
Copy link

AskSantoshYadav commented Jul 4, 2023

It would be great if ability to mock private class and methods brought back. In my case all java classes and methods are private.

Therefore we request to put private class/ method mocking back. If there there is any alternative please share, or Like ondrejlerch mentioned at least disable it by default and enable it somehow via JMockit API if you find it dangerous.

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants