Skip to content

Commit

Permalink
Added a test to verify that a chooser is opened for exporting the pro…
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
penguin359 committed Jan 29, 2022
1 parent 2041ba3 commit 583918f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down
51 changes: 51 additions & 0 deletions androidTest/java/org/aprsdroid/app/ProfileTests.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
16 changes: 11 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
}

0 comments on commit 583918f

Please sign in to comment.