Search in sources :

Example 1 with CurrentThreadExecutor

use of dagger.extension.example.scheduler.CurrentThreadExecutor in project dagger-test-example by aschattney.

the class TestTodayWeatherViewModel method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    permissionSubject = PublishSubject.create();
    locationSubject = PublishSubject.create();
    pageChanged = PublishSubject.create();
    doReturn(permissionSubject).when(pm).onPermissionGranted();
    doReturn(locationSubject).when(locationService).onNewLocation();
    doReturn(true).when(locationService).isGpsProviderEnabled();
    doReturn(Observable.empty()).when(weatherService).getCurrentWeather(anyDouble(), anyDouble());
    final Scheduler androidScheduler = Schedulers.from(new CurrentThreadExecutor());
    vm = new TodayWeatherViewModel(navigation, pageChanged, pm, locationService, weatherService, weatherParser, androidScheduler);
    vm.state = new WeatherViewModel.WeatherViewModelState();
}
Also used : Scheduler(io.reactivex.Scheduler) CurrentThreadExecutor(dagger.extension.example.scheduler.CurrentThreadExecutor) Before(org.junit.Before)

Example 2 with CurrentThreadExecutor

use of dagger.extension.example.scheduler.CurrentThreadExecutor in project dagger-test-example by aschattney.

the class TestSearchService method setUp.

@Before
public void setUp() throws Exception {
    item = fakeResponse(Responses.JSON.SEARCH);
    doReturn(Observable.just(item)).when(weatherApi).searchWeather(anyString());
    searchService = new SearchService(weatherApi, Schedulers.from(new CurrentThreadExecutor()));
}
Also used : CurrentThreadExecutor(dagger.extension.example.scheduler.CurrentThreadExecutor) Before(org.junit.Before)

Example 3 with CurrentThreadExecutor

use of dagger.extension.example.scheduler.CurrentThreadExecutor in project dagger-test-example by aschattney.

the class TestTomorrowWeatherViewModel method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    permissionSubject = PublishSubject.create();
    locationSubject = PublishSubject.create();
    pageChanged = PublishSubject.create();
    doReturn(permissionSubject).when(pm).onPermissionGranted();
    doReturn(locationSubject).when(locationService).onNewLocation();
    doReturn(true).when(locationService).isGpsProviderEnabled();
    doReturn(Observable.empty()).when(weatherService).getTomorrowWeather(anyDouble(), anyDouble());
    final Scheduler androidScheduler = Schedulers.from(new CurrentThreadExecutor());
    vm = new TomorrowWeatherViewModel(navigation, pageChanged, pm, locationService, weatherService, weatherParser, androidScheduler);
    vm.state = new WeatherViewModel.WeatherViewModelState();
}
Also used : Scheduler(io.reactivex.Scheduler) CurrentThreadExecutor(dagger.extension.example.scheduler.CurrentThreadExecutor) Before(org.junit.Before)

Example 4 with CurrentThreadExecutor

use of dagger.extension.example.scheduler.CurrentThreadExecutor 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

CurrentThreadExecutor (dagger.extension.example.scheduler.CurrentThreadExecutor)4 Before (org.junit.Before)3 Scheduler (io.reactivex.Scheduler)2 RequestManager (com.bumptech.glide.RequestManager)1 TestDaggerComponentSingleton (dagger.extension.example.di.TestDaggerComponentSingleton)1 TestWeatherApplication (dagger.extension.example.di.TestWeatherApplication)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