Haven is for people who need a way to protect their personal spaces and possessions without compromising their own privacy, through an Android app and on-device sensors
Add tests for the progress dialog
Arka Prava Basu38f975a8fa68
diff --git a/build.gradle b/build.gradleindex 6fc5ea7..a9824d6 100644--- a/build.gradle+++ b/build.gradle@@ -94,6 +94,9 @@ android {ndk {abiFilters "armeabi", "armeabi-v7a", "x86"}++ testInstrumentationRunner "android.test.InstrumentationTestRunner"+ testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'}@@ -150,4 +153,8 @@ dependencies {kapt "android.arch.persistence.room:compiler:1.1.1"implementation "android.arch.lifecycle:runtime:1.1.1"implementation "android.arch.lifecycle:extensions:1.1.1"++ testImplementation "junit:junit:4.12"+ androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.2"+ androidTestImplementation "com.android.support.test.espresso:espresso-intents:3.0.2"}diff --git a/src/androidTest/java/org/havenapp/main/ListActivityTest.kt b/src/androidTest/java/org/havenapp/main/ListActivityTest.ktnew file mode 100644index 0000000..2be225d--- /dev/null+++ b/src/androidTest/java/org/havenapp/main/ListActivityTest.kt@@ -0,0 +1,58 @@+package org.havenapp.main++import android.content.Intent+import android.support.test.annotation.UiThreadTest+import android.support.test.espresso.Espresso+import android.support.test.espresso.assertion.ViewAssertions.doesNotExist+import android.support.test.espresso.assertion.ViewAssertions.matches+import android.support.test.espresso.matcher.ViewMatchers.isDisplayed+import android.support.test.espresso.matcher.ViewMatchers.withText+import android.support.v4.content.LocalBroadcastManager+import android.test.ActivityInstrumentationTestCase2+import junit.framework.Assert+import org.havenapp.main.database.DB_INIT_END+import org.havenapp.main.database.DB_INIT_START+import org.havenapp.main.database.DB_INIT_STATUS++/**+ * Created by Arka Prava Basu <[email protected]> on 20/10/18.+ */+class ListActivityTest : ActivityInstrumentationTestCase2<ListActivity>(ListActivity::class.java) {+ private var listActivity: ListActivity? = null++ override fun setUp() {+ super.setUp()+ listActivity = activity+ }++ fun testCheckActivityNotNull() {+ Assert.assertNotNull(listActivity)+ }++ /**+ * Test that we show a progress dialog while database init/migration is in process.+ * Test that we remove that on db init/migration success+ */+ @UiThreadTest+ fun testCheckProgressBarShownOnBroadcast() {+ Assert.assertNotNull(listActivity)++ var dbIntent = Intent()+ dbIntent.putExtra(DB_INIT_STATUS, DB_INIT_START)+ dbIntent.action = DB_INIT_STATUS+ LocalBroadcastManager.getInstance(activity).sendBroadcast(dbIntent)++ Espresso.onView(withText(R.string.please_wait)).check(matches(isDisplayed()))+ Espresso.onView(withText(R.string.migrating_data)).check(matches(isDisplayed()))++ Thread.sleep(5000) // keeping a waiting time to check the view++ dbIntent = Intent()+ dbIntent.putExtra(DB_INIT_STATUS, DB_INIT_END)+ dbIntent.action = DB_INIT_STATUS+ LocalBroadcastManager.getInstance(activity).sendBroadcast(dbIntent)++ Espresso.onView(withText(R.string.please_wait)).check(doesNotExist())+ Espresso.onView(withText(R.string.migrating_data)).check(doesNotExist())+ }+}diff --git a/src/main/java/org/havenapp/main/ListActivity.java b/src/main/java/org/havenapp/main/ListActivity.javaindex 215d14f..1b02d05 100644--- a/src/main/java/org/havenapp/main/ListActivity.java+++ b/src/main/java/org/havenapp/main/ListActivity.java@@ -113,6 +113,8 @@ public class ListActivity extends AppCompatActivity {progressDialog = new ProgressDialog(ListActivity.this);progressDialog.setTitle(getString(R.string.please_wait));progressDialog.setMessage(getString(R.string.migrating_data));+ progressDialog.setCancelable(false);+ progressDialog.setCanceledOnTouchOutside(false);progressDialog.show();} else if (intent.getIntExtra(DB_INIT_STATUS, 0) == DB_INIT_END) {if (progressDialog != null)