From 583918fc3aa56b8fed88f93a276de18908bc834c Mon Sep 17 00:00:00 2001 From: "Loren M. Lang" Date: Fri, 28 Jan 2022 02:23:16 -0800 Subject: [PATCH] Added a test to verify that a chooser is opened for exporting the profile --- .../app/ExampleInstrumentedTest.java | 8 +-- .../java/org/aprsdroid/app/ProfileTests.java | 51 +++++++++++++++++++ build.gradle | 16 ++++-- 3 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 androidTest/java/org/aprsdroid/app/ProfileTests.java diff --git a/androidTest/java/org/aprsdroid/app/ExampleInstrumentedTest.java b/androidTest/java/org/aprsdroid/app/ExampleInstrumentedTest.java index 85369e0c..e0e19075 100644 --- a/androidTest/java/org/aprsdroid/app/ExampleInstrumentedTest.java +++ b/androidTest/java/org/aprsdroid/app/ExampleInstrumentedTest.java @@ -1,15 +1,15 @@ package org.aprsdroid.app; +import static org.junit.Assert.assertEquals; + import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; - /** * Instrumented test, which will execute on an Android device. * diff --git a/androidTest/java/org/aprsdroid/app/ProfileTests.java b/androidTest/java/org/aprsdroid/app/ProfileTests.java new file mode 100644 index 00000000..ce316a5f --- /dev/null +++ b/androidTest/java/org/aprsdroid/app/ProfileTests.java @@ -0,0 +1,51 @@ +package org.aprsdroid.app; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction; +import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.allOf; + +import android.app.Instrumentation; +import android.content.Intent; +import android.util.Log; + +import androidx.test.core.app.ActivityScenario; +import androidx.test.espresso.intent.Intents; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class ProfileTests { + @Before public void setUp() { + Intents.init(); + } + + @After public void tearDown() { + Intents.release(); + } + + @Test + public void testThatExportProfileOpensTheChooser() { + ActivityScenario scenario = ActivityScenario.launch(PrefsAct.class); + Assert.assertEquals(1, Intents.getIntents().size()); + Intents.intending(hasAction(Intent.ACTION_CHOOSER)).respondWith(new Instrumentation.ActivityResult(0, null)); + Assert.assertEquals(1, Intents.getIntents().size()); + openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getInstrumentation().getTargetContext()); + onView(withText(R.string.profile_export)) + .perform(click()); + Intents.intended(hasAction(Intent.ACTION_MAIN)); // Validate the activity launch + Intents.intended(allOf(hasAction(Intent.ACTION_CHOOSER))); + Assert.assertEquals(2, Intents.getIntents().size()); + Log.d("DDD", Intents.getIntents().get(0).toString()); + Log.d("DDD", Intents.getIntents().get(1).toString()); + Intents.assertNoUnverifiedIntents(); + } +} diff --git a/build.gradle b/build.gradle index 7f7d6daa..269159d8 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.1' + classpath 'com.android.tools.build:gradle:3.5.4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -90,7 +90,7 @@ android { resValue "string", "google_maps_key", mapsApiKey() - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } useLibrary 'org.apache.http.legacy' compileOptions { @@ -167,7 +167,13 @@ dependencies { implementation 'com.squareup.okio:okio:2.1.0' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - testImplementation 'junit:junit:4.12' + + testImplementation 'junit:junit:4.13.1' + testImplementation 'org.hamcrest:hamcrest-core:1.3' + testImplementation 'org.hamcrest:hamcrest-library:1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0' + androidTestImplementation 'androidx.test:runner:1.4.0' + androidTestImplementation 'androidx.test:rules:1.4.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' }