Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

[Updated] Fix unlinked android injector factories#211

Closed
nodejsjs wants to merge 6 commits intoJakeWharton:masterfrom
nodejsjs:rs/fix-unlinked-android-injector-factories
Closed

[Updated] Fix unlinked android injector factories#211
nodejsjs wants to merge 6 commits intoJakeWharton:masterfrom
nodejsjs:rs/fix-unlinked-android-injector-factories

Conversation

@nodejsjs
Copy link
Copy Markdown

@nodejsjs nodejsjs commented Nov 13, 2020

Updated PR for #196 #174
Credits to @crgarridos and @kokeroulis

  • Added tests
  • Formatted code using the googleJavaFormat task

Comment on lines +14 to +27
public class ExampleFragmentInjectionActivityTest {
@Test
public void activityFragmentInjection() {
try (ActivityScenario<ExampleFragmentInjectionActivity> scenario = launch(ExampleFragmentInjectionActivity.class)) {
scenario.moveToState(CREATED);
scenario.onActivity(activity -> {
ExampleFragment fragment = (ExampleFragment) activity.getFragmentManager().findFragmentByTag("ExampleFragment");
assertThat(fragment.string).isEqualTo("Hello!");
assertThat(fragment.aLong).isEqualTo(10L);
assertThat(fragment.anInt).isEqualTo(20);
});
}
}
}
Copy link
Copy Markdown
Author

@nodejsjs nodejsjs Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is failing when the task :integration-tests:android-has-interface:testReflectDebugUnitTest is run. But as a single test run from the IDE, it passes just fine. Any hints please on what might be going on here? @JakeWharton

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably because of moveToState. launch may have an optional parameter for initial state like Fragment, even if it doesn't, the default initial state may be RESUMED. I think you are going to DESTROYED with this code. Just an idea, not fully sure.

Also you may need to idle the looper, since Robolectric 4.4.

Copy link
Copy Markdown
Author

@nodejsjs nodejsjs Nov 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointers! I'm gonna investigate the Fragment/ActivityScenario apis more. I should add that it fails with the following error:

No injector factory bound for Class<com.example.ExampleFragment>
java.lang.IllegalArgumentException: No injector factory bound for Class<com.example.ExampleFragment>
	at dagger.android.DispatchingAndroidInjector.inject(DispatchingAndroidInjector.java:136)
	at dagger.android.support.AndroidSupportInjection.inject(AndroidSupportInjection.java:75)
	at dagger.android.support.AndroidSupportInjection.inject(AndroidSupportInjection.java:67)
	at com.example.ExampleFragment.onAttach(ExampleFragment.java:34)

@nodejsjs nodejsjs closed this Sep 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants