use of dagger.extension.example.di.TestWeatherApplication in project dagger-test-example by aschattney.
the class TestGraphComposition method testComponent.
@Test
public void testComponent() {
final TestWeatherApplication app = new TestWeatherApplication();
if (true) {
final TestDaggerComponentSingleton component = (TestDaggerComponentSingleton) TestDaggerComponentSingleton.builder(app).context(app).create(app);
final RequestManager requestManager = component.getRequestManager().get();
final String apiKey = component.getApiParamKey().get();
assertEquals(this.requestManager, requestManager);
assertEquals(this.apiKey, apiKey);
return;
}
app.componentSingleton().withRequestManager(() -> mock(RequestManager.class)).withWeatherApi(() -> mock(WeatherApi.class)).withRxSchedulerMain(() -> Schedulers.from(new CurrentThreadExecutor()));
TestDaggerComponentSingleton singleton = (TestDaggerComponentSingleton) TestDaggerComponentSingleton.builder(app).context(mock(Context.class)).seedInstance(app).build();
final TodayWeatherViewModel vm = mock(TodayWeatherViewModel.class);
app.todayWeatherFragmentSubcomponent().withTodayWeatherViewModel(() -> vm);
final TestDaggerComponentSingleton.TestMainActivitySubcomponentImpl mainActivitySubcomponent = singleton.getMainActivitySubcomponent(mock(MainActivity.class));
final TodayWeatherViewModel viewModel = mainActivitySubcomponent.getTodayWeatherFragmentSubcomponent(mock(TodayWeatherFragment.class)).getTodayWeatherViewModel().get();
assertEquals(vm, viewModel);
}
Aggregations