forked from tbruyelle/RxPermissions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Public access to Permission constructors (tbruyelle#138)
- Loading branch information
Showing
3 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
sample/src/test/java/com/tbruyelle/rxpermissions/sample/RxPermissionsSampleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.tbruyelle.rxpermissions.sample; | ||
|
||
|
||
import android.Manifest; | ||
import android.annotation.TargetApi; | ||
import android.app.Activity; | ||
import android.os.Build; | ||
|
||
import com.tbruyelle.rxpermissions2.Permission; | ||
import com.tbruyelle.rxpermissions2.RxPermissions; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import io.reactivex.Observable; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Sample tests for {@link RxPermissions}. | ||
*/ | ||
public class RxPermissionsSampleTest { | ||
|
||
@Mock | ||
private Activity activity; | ||
@Mock | ||
private RxPermissions rxPermissions; | ||
|
||
@Before | ||
public void setUp() { | ||
MockitoAnnotations.initMocks(this); | ||
} | ||
|
||
@Test | ||
@TargetApi(Build.VERSION_CODES.M) | ||
public void test_permission_denied_dont_ask_again() throws Exception { | ||
// mocks | ||
final String permissionString = Manifest.permission.READ_PHONE_STATE; | ||
final boolean granted = false; | ||
final boolean shouldShowRequestPermissionRationale = false; | ||
final Permission permission = new Permission(permissionString, granted, shouldShowRequestPermissionRationale); | ||
when(rxPermissions.requestEach(permissionString)).thenReturn(Observable.just(permission)); | ||
// test | ||
rxPermissions.requestEach(permissionString).test().assertNoErrors().assertValue(permission); | ||
} | ||
|
||
} |