I am almost certain that there is no way to test my @AfterInject methods. Take a look at the generated init_ method:
private void init_(Bundle savedInstanceState) {
OnViewChangedNotifier.registerOnViewChangedListener(this);
imageController = ImageController_.getInstance_(getActivity());
myAfterInjectActivity();
}
I can't mock before onCreate() because the dependency will be overwritten. I can't mock after because the method I'm testing already ran. I can't mock out ImageController_.getInstance_() either, because the generated ImageController_ is final.
Ideally, I'd like to be able to use a dependency injection strategy, something like a module where I can setup:
// This would be the default. Existing users wouldn't need to create a module
binder.bind(ImageController.class).toGeneratedClass();
// In my testing method I could bind it to something else:
ImageController mock = mock(ImageController.class);
when(mock.downloadGiantVideoAndReturnUri).thenReturn("fake uri");
binder.bind(ImageController.class).to(mock);
Also useful would be binder.bindOnce, so I could do this individually in each method. If we did this kind of setup robotium users could do the following:
MyActivity activity = Robolectric.buildActivity(MyActivity_.class)
.create()
.get();
To implement this, we would need to replace generated code like this:
imageController = ImageController_.getInstance_(getActivity());
with
imageController = binder.getInstance(ImageController_.class, getActivity());
Any thoughts would be lovely. I'm still mulling over this, but hopefully I'm going in the right direction.
Additional thoughts: EBean injections should be handled the same way, so we can test EBeans that rely on other EBeans.
I am almost certain that there is no way to test my
@AfterInjectmethods. Take a look at the generatedinit_method:I can't mock before
onCreate()because the dependency will be overwritten. I can't mock after because the method I'm testing already ran. I can't mock outImageController_.getInstance_()either, because the generatedImageController_isfinal.Ideally, I'd like to be able to use a dependency injection strategy, something like a module where I can setup:
Also useful would be
binder.bindOnce, so I could do this individually in each method. If we did this kind of setup robotium users could do the following:To implement this, we would need to replace generated code like this:
with
Any thoughts would be lovely. I'm still mulling over this, but hopefully I'm going in the right direction.
Additional thoughts:
EBeaninjections should be handled the same way, so we can testEBeans that rely on otherEBeans.