Search in sources :

Example 1 with TestDaggerComponentSingleton

use of dagger.extension.example.di.TestDaggerComponentSingleton 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);
}
Also used : TodayWeatherViewModel(dagger.extension.example.view.weather.TodayWeatherViewModel) RequestManager(com.bumptech.glide.RequestManager) TodayWeatherFragment(dagger.extension.example.view.weather.TodayWeatherFragment) TestDaggerComponentSingleton(dagger.extension.example.di.TestDaggerComponentSingleton) MainActivity(dagger.extension.example.view.main.MainActivity) CurrentThreadExecutor(dagger.extension.example.scheduler.CurrentThreadExecutor) TestWeatherApplication(dagger.extension.example.di.TestWeatherApplication) Test(org.junit.Test)

Aggregations

RequestManager (com.bumptech.glide.RequestManager)1 TestDaggerComponentSingleton (dagger.extension.example.di.TestDaggerComponentSingleton)1 TestWeatherApplication (dagger.extension.example.di.TestWeatherApplication)1 CurrentThreadExecutor (dagger.extension.example.scheduler.CurrentThreadExecutor)1 MainActivity (dagger.extension.example.view.main.MainActivity)1 TodayWeatherFragment (dagger.extension.example.view.weather.TodayWeatherFragment)1 TodayWeatherViewModel (dagger.extension.example.view.weather.TodayWeatherViewModel)1 Test (org.junit.Test)1