This file contains hidden or 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
| var imagePath: File = File(getContext().getExternalFilesDir(null), "images") | |
| var newFile: File = File(imagePath, "default_image.jpg") | |
| var contentUri: Uri = getUriForFile(getContext(), "com.mydomain.authority", newFile) |
This file contains hidden or 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
| class EncryptedFileProvider : FileProvider() { | |
| private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob()) | |
| private var masterKeyAlias: String = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC) | |
| override fun openFile(uri: Uri, mode: String): ParcelFileDescriptor? { | |
| if (uri.path.isNullOrEmpty()) { | |
| return null |
This file contains hidden or 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
| @RunWith(AndroidJUnit4::class) | |
| class AdvancedExampleTest { | |
| lateinit var scenario: ActivityScenario<MainActivity> | |
| @Test | |
| fun launchMainActivityWithLongDisplayNameExtra() { | |
| val intent = Intent(ApplicationProvider.getApplicationContext(), MainActivity::class.java) | |
| .putExtra( | |
| INTENT_EXTRA_DISPLAY_NAME, |
This file contains hidden or 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
| val context: Context = getInstrumentation().targetContext | |
| fun getString(id: Int): String? { | |
| return context.resources.getString(id) | |
| } | |
| fun getCurrentActivity(): Activity? { | |
| var currentActivity: Activity? = null | |
| getInstrumentation().runOnMainSync { | |
| run { |
This file contains hidden or 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
| dependencies { | |
| androidTestImplementation 'androidx.test:core-ktx:1.2.0' | |
| androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.1' | |
| androidTestImplementation 'androidx.test:runner:1.2.0' | |
| androidTestImplementation 'androidx.test:rules:1.2.0' | |
| androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | |
| androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0' | |
| androidTestImplementation "com.google.truth:truth:0.44" | |
| } |
This file contains hidden or 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
| private const val USER_NAME = "test@gmail.com" | |
| private const val VALID_PASSWORD = "123456" | |
| private const val INVALID_PASSWORD = "12345" // Password must be >5 characters | |
| @RunWith(AndroidJUnit4::class) | |
| class BasicExampleTest { | |
| /** | |
| * Use [activityScenarioRule] to create and launch the activity under test before each test, | |
| * and close it after each test. This is a replacement for |
This file contains hidden or 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
| private const val USER_NAME = "test@gmail.com" | |
| private const val VALID_PASSWORD = "123456" | |
| @RunWith(AndroidJUnit4::class) | |
| class IntentsExampleTest { | |
| /** | |
| * Use [IntentsTestRule] to initialize Espresso-Intents before each test | |
| * and releases Espresso-Intents after each test run. | |
| */ |
This file contains hidden or 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
| dependencies { | |
| // AndroidJUnitRunner and JUnit Rules | |
| androidTestImplementation 'androidx.test:runner:1.1.0' | |
| androidTestImplementation 'androidx.test:rules:1.1.0' | |
| // Assertions | |
| androidTestImplementation 'androidx.test.ext:junit:1.0.0' | |
| androidTestImplementation 'androidx.test.ext:truth:1.0.0' | |
| androidTestImplementation 'com.google.truth:truth:0.42' |
This file contains hidden or 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
| fun SharedPreferences.copyTo(dest: SharedPreferences) { | |
| for (entry in all.entries) { | |
| val key = entry.key | |
| val value: Any? = entry.value | |
| dest.set(key, value) | |
| } | |
| } |
NewerOlder