Search in sources :

Example 6 with PermissionResult

use of dagger.extension.example.service.PermissionResult in project dagger-test-example by aschattney.

the class TestTodayWeatherViewModel method grantingPermissionsShouldTriggerReloadOfWeatherDataIfGpsIsEnabled.

@Test
public void grantingPermissionsShouldTriggerReloadOfWeatherDataIfGpsIsEnabled() {
    final Location location = mockLocation(mock(Location.class), 1.0, 1.0);
    when(locationService.lastLocation()).thenReturn(location);
    when(pm.isPermissionGranted(PERM_COARSE_LOCATION)).thenReturn(false);
    when(pm.isPermissionGranted(PERM_FINE_LOCATION)).thenReturn(false);
    vm.onViewAttached();
    when(pm.isPermissionGranted(PERM_COARSE_LOCATION)).thenReturn(true);
    permissionSubject.onNext(new PermissionResult(TodayWeatherViewModel.REQUEST_CODE_PERM_ACCESS_FINE_LOCATION, new String[] { PERM_FINE_LOCATION }, new int[] { PackageManager.PERMISSION_GRANTED }));
    verifyZeroInteractions(weatherService);
    permissionSubject.onNext(new PermissionResult(TodayWeatherViewModel.REQUEST_CODE_PERM_ACCESS_COARSE_LOCATION, new String[] { PERM_COARSE_LOCATION }, new int[] { PackageManager.PERMISSION_GRANTED }));
    verify(weatherService).getCurrentWeather(1.0, 1.0);
}
Also used : PermissionResult(dagger.extension.example.service.PermissionResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Location(android.location.Location) Test(org.junit.Test)

Aggregations

PermissionResult (dagger.extension.example.service.PermissionResult)6 Test (org.junit.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Location (android.location.Location)2