Search in sources :

Example 1 with PermissionResult

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

the class TestTomorrowWeatherViewModel 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).getTomorrowWeather(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)

Example 2 with PermissionResult

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

the class UnitTestTodayWeatherPresenter method denieingPermissionsShouldNotTriggerReloadOfWeatherData.

@Test
public void denieingPermissionsShouldNotTriggerReloadOfWeatherData() {
    when(locationProvider.lastLocation()).thenReturn(createLocation(1.0, 1.0));
    when(pm.isPermissionGranted(PERM_COARSE_LOCATION)).thenReturn(false);
    when(pm.isPermissionGranted(PERM_FINE_LOCATION)).thenReturn(false);
    vm.onViewAttached();
    PermissionResult result = new PermissionResult(TodayWeatherViewModel.REQUEST_CODE_PERM_ACCESS_FINE_LOCATION, new String[] { PERM_COARSE_LOCATION }, new int[] { PackageManager.PERMISSION_DENIED });
    permissionSubject.onNext(result);
    verifyZeroInteractions(weatherService);
}
Also used : PermissionResult(dagger.extension.example.service.PermissionResult) Test(org.junit.Test)

Example 3 with PermissionResult

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

the class UnitTestTodayWeatherPresenter method grantingPermissionsShouldTriggerReloadOfWeatherData.

@Test
public void grantingPermissionsShouldTriggerReloadOfWeatherData() {
    when(locationProvider.lastLocation()).thenReturn(createLocation(1.0, 1.0));
    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);
    when(pm.isPermissionGranted(PERM_FINE_LOCATION)).thenReturn(true);
    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) Test(org.junit.Test)

Example 4 with PermissionResult

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

the class TestTomorrowWeatherViewModel method denieingPermissionsShouldNotTriggerReloadOfWeatherData.

@Test
public void denieingPermissionsShouldNotTriggerReloadOfWeatherData() {
    when(pm.isPermissionGranted(PERM_COARSE_LOCATION)).thenReturn(false);
    when(pm.isPermissionGranted(PERM_FINE_LOCATION)).thenReturn(false);
    vm.onViewAttached();
    PermissionResult result = new PermissionResult(TodayWeatherViewModel.REQUEST_CODE_PERM_ACCESS_FINE_LOCATION, new String[] { PERM_COARSE_LOCATION }, new int[] { PackageManager.PERMISSION_DENIED });
    permissionSubject.onNext(result);
    verifyZeroInteractions(weatherService);
}
Also used : PermissionResult(dagger.extension.example.service.PermissionResult) Test(org.junit.Test)

Example 5 with PermissionResult

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

the class TestTodayWeatherViewModel method denieingPermissionsShouldNotTriggerReloadOfWeatherData.

@Test
public void denieingPermissionsShouldNotTriggerReloadOfWeatherData() {
    when(pm.isPermissionGranted(PERM_COARSE_LOCATION)).thenReturn(false);
    when(pm.isPermissionGranted(PERM_FINE_LOCATION)).thenReturn(false);
    vm.onViewAttached();
    PermissionResult result = new PermissionResult(TodayWeatherViewModel.REQUEST_CODE_PERM_ACCESS_FINE_LOCATION, new String[] { PERM_COARSE_LOCATION }, new int[] { PackageManager.PERMISSION_DENIED });
    permissionSubject.onNext(result);
    verifyZeroInteractions(weatherService);
}
Also used : PermissionResult(dagger.extension.example.service.PermissionResult) 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