DaggerMock icon indicating copy to clipboard operation
DaggerMock copied to clipboard

How would one work with subcomponents?

Open marius-bardan opened this issue 6 years ago • 1 comments

Let's say I have an AppComponent, which has a subcomponent UserComponent, which in turn has a ProfileComponent, each with sub/modules:

@AppScope
@Component(modules={AppModule.class, NetworkModule.class})
interface AppComponent {
  UserComponent userComponent(...);
}

@UserScope
@Subcomponent(modules={UserDataModule.class})
interface UserComponent {
  ProfileComponent profileComponent(...);
}

@UserProfileScope
@Subcomponent(modules={SomeProfileModule.class})
interface ProfileComponent {
  // other subcomponents here
  void inject(UserProfileActivity activity);
}

What I'd like is to have an integration test, from the UserProfileActivity onwards. From the examples I'm seeing, they only show how to deal with 1 component or top-level component.

How would I get a reference in this case, to the ProfileComponent, since creating a Rule for it will not cut it, since it has to be created like: appComponent.userComponent(...).profileComponent(...)?

Thinking it has something to do with addComponentDependency, but unsure how it should work when I have a module (e.g. UserDataModule) with an activity reference in the middle.

marius-bardan avatar Apr 25 '18 08:04 marius-bardan

Hi, I have some questions to understand better your problem:

  • what test are you trying to write? An Espresso test that launch the UserProfileActivity?
  • which objects do you wan to to replace with some mocks in the test? Which component are defined in?
  • do you get an error if you don't use addComponentDependency in a test?

fabioCollini avatar Apr 28 '18 14:04 fabioCollini