google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.45k stars 2.02k forks source link

Make generated component implementation non-final #318

Closed artem-zinnatullin closed 8 years ago

artem-zinnatullin commented 8 years ago

At the moment, Dagger generates final class DaggerSomeComponent implements SomeComponent.

Basically, I just want to Mockito.spy(component) to be able to override its behavior like inject() and getSomething() in integration tests, but the fact that class is final makes me sad (not a fan of PowerMock).

Can we please make impl classes non-final?

tbroyer commented 8 years ago

Can't you mock the component and use AdditionalAnswers.delegatesTo()?
See http://site.mockito.org/mockito/docs/current/org/mockito/Mockito.html#27

artem-zinnatullin commented 8 years ago

I'll try and report, looks promising (did same thing manually), thanks for suggestion!

On Tue, 16 Feb 2016, 20:04 Thomas Broyer notifications@github.com wrote:

Can't you mock the component and use AdditionalAnswers.delegateTo()?

See http://site.mockito.org/mockito/docs/current/org/mockito/Mockito.html#delegating_call_to_real_instance

— Reply to this email directly or view it on GitHub https://github.com/google/dagger/issues/318#issuecomment-184956362.

@artem_zin

artem-zinnatullin commented 8 years ago

@tbroyer works like a charm, thanks a lot!

ronshapiro commented 8 years ago

You also probably want to consider just creating a new component/module set if you're going to be overriding behavior so that you make sure the graph is properly composed. Just mocking the component's getSomething() method doesn't actually replace the binding elsewhere in the graph.

artem-zinnatullin commented 8 years ago

Sure sure, I understand possible problems and apply it carefully.