package uk.co.tekkies.readings.test.contentLocationActivity;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;

import junit.framework.Assert;

import org.hamcrest.Matcher;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.File;

import uk.co.tekkies.readings.R;
import uk.co.tekkies.readings.activity.ContentLocationActivity;

import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.intent.Intents.intending;
import static android.support.test.espresso.intent.matcher.IntentMatchers.toPackage;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

@RunWith(AndroidJUnit4.class)
public class ContentLocationActivityTest{




    @Rule
    public IntentsTestRule<ContentLocationActivity> mActivityRule = new IntentsTestRule<ContentLocationActivity>(
            ContentLocationActivity.class) {
        @Override
        protected void beforeActivityLaunched() {
            super.beforeActivityLaunched();

            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getInstrumentation().getTargetContext());
            preferences.edit().clear().commit();

        }
    };

    @Before
    public void setup() {



        Intent resultData = new Intent();
        Uri uri = Uri.fromFile(new File("/storage/emulated/0/readings-samples"));
        resultData.setData(uri);
        Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
        intending(toPackage("com.estrongs.android.pop")).respondWith(result);
    }

    @Test
    public void testContentIsFound() {
        onView(withId(R.id.button_browse)).perform(click());

        onView(withText("Found: /storage/emulated/0/readings-samples/KjvScourby2")).check(matches(isDisplayed()));
    }



}

@@ -217,16 +217,47 @@
 et.Uri;%0A
+import android.os.Environment;%0A
 import a
@@ -1465,16 +1465,129 @@
 yTest%7B%0A%0A
+    protected final File SAMPLE_FOLDER = new File(Environment.getExternalStorageDirectory(), %22readings-samples%22);
 %0A%0A%0A    @
@@ -2040,25 +2040,24 @@
 ).commit();%0A
-%0A
         %7D%0A  
@@ -2100,19 +2100,16 @@
 tup() %7B%0A
-%0A%0A%0A
         
@@ -2177,56 +2177,21 @@
 ile(
-new File(%22/storage/emulated/0/readings-samples%22)
+SAMPLE_FOLDER
 );%0A 
@@ -2562,53 +2562,24 @@
 ext(
-%22
+get
 Found
-: /storage/emulated/0/readings-samples/
+Messge(%22
 KjvS
@@ -2588,16 +2588,17 @@
 urby2%22))
+)
 .check(m
@@ -2628,12 +2628,223 @@
 %0A    %7D%0A%0A
+    private String getFoundMessge(String version) %7B%0A        File folder = new File(SAMPLE_FOLDER, version);%0A        String message = String.format(%22Found: %251s%22, folder.toString());%0A        return message;%0A    %7D%0A
 %0A%0A%7D%0A

Stop using hard coded paths