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

Repeat: Java generation: allow non-final generation for classes #16793

Open
carojkov opened this issue May 8, 2024 · 5 comments
Open

Repeat: Java generation: allow non-final generation for classes #16793

carojkov opened this issue May 8, 2024 · 5 comments
Labels
untriaged auto added to all issues by default when created.

Comments

@carojkov
Copy link

carojkov commented May 8, 2024

re: #11162

Allow mocking stubs - don't make them final

I'd love to be able to mock stubs

    private HelloServiceGrpc.HelloServiceBlockingStub stub;

    public void hello(String message) {
        stub.hello(message); <-- I should be able to make a unit test that verifies stub.hello() is called and with the right value.
    }

@MarinaShaposhnikova
@artnaseef

@carojkov carojkov added the untriaged auto added to all issues by default when created. label May 8, 2024
@artnaseef
Copy link

I agree - it would be excellent to be able to mock. The only response I've gotten in the past from google devs (not protobuf, though) as to why the classes are marked final is because they wanted to ensure users of their libraries don't use inheritance on those classes.

That response feels like using a Nuke to remove the tree stump in the back yard to me. However, even that can be solved - using interfaces. Wasn't finding any common ground / interest in working on the matter, so I gave up.

@artnaseef
Copy link

As mentioned on #11162 follow-up, this request may belong on a gRPC project instead of this one. Sorry that I don't know the right project to link here myself.

Is this the plugin invloved? https://github.com/xolstice/protobuf-maven-plugin

Looking at the plugin briefly, I did not find references to the grpc/protobuf code generators themselves.

Hope this helps.

@carojkov
Copy link
Author

carojkov commented May 9, 2024

Yep, I think I posted to the wrong project. I'll make sure to re-post to the right one.

However, I think the design issue is systemic - unit tests should be able to mock generated classes. Even Any, Empty etc should be mockable but user classes should be mockable without question.

@artnaseef
Copy link

I agree that generated model objects should be inheritable (and, hence, not final), although I can see protobuf folks wanting to be clear that subclasses aren't supported in the marshalling/unmarshalling (aka seralizing/deserializing). At least adding a "I know what I am doing - I swear" option to the generator that drops the final keyword would be nice to have.

@carojkov if you @ me on any new threads, I'll try to help/contribute.

@carojkov
Copy link
Author

carojkov commented May 9, 2024

Thanks, I am sure adding voices makes a differenced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged auto added to all issues by default when created.
Projects
None yet
Development

No branches or pull requests

2 participants