//Setup your test environment
//To avoid flakiness, we highly recommend that you turn off system animations on the virtual or physical device(s) used for testing.
//    Under 'Settings->Developer options' disable the following 3 settings and restart the device:



import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;

import com.dummies.silentmodetoggle.MainActivity;
import com.dummies.silentmodetoggle.R;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions
    .matches;
import static android.support.test.espresso.matcher.ViewMatchers
    .isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;

@LargeTest
public class SilentModeToggleEspressoTest 
    extends ActivityInstrumentationTestCase2<MainActivity> 
{

    public SilentModeToggleEspressoTest() {
        super(MainActivity.class);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        
        // Get the Activity under test, starting it if necessary.
        // This must be done before you can run any testcases
        // that use the activity.
        getActivity();
    }

    public void testPhoneIconIsDisplayed() {
        onView(withId(R.id.phone_icon)).check(matches(isDisplayed()));
    }
}

@@ -258,16 +258,112 @@
 ice:%0A%0A%0A%0A
+import android.app.Activity;%0Aimport android.content.Context;%0Aimport android.media.AudioManager;%0A
 import a
@@ -552,16 +552,71 @@
 oggle.R;
+%0Aimport com.dummies.silentmodetoggle.util.RingerHelper;
 %0A%0Aimport
@@ -670,16 +670,86 @@
 onView;%0A
+import static android.support.test.espresso.action.ViewActions.click;%0A
 import s
@@ -1095,16 +1095,52 @@
 vity%3E %0A%7B
+%0A    %0A    AudioManager audioManager;
 %0A%0A    pu
@@ -1482,142 +1482,1084 @@
     
-getActivity();%0A    %7D%0A%0A    public void testPhoneIconIsDisplayed() %7B%0A        onView(withId(R.id.phone_icon)).check(matches(isDisplayed()
+Activity activity = getActivity();%0A        %0A        // Retrieve an AudioManager from the activity%0A        audioManager = (AudioManager) %0A            activity.getSystemService(Context.AUDIO_SERVICE);%0A    %7D%0A%0A    public void testPhoneIconIsDisplayed() %7B%0A        // When the phone_icon view is available,%0A        // check that it is displayed.%0A        onView(withId(R.id.phone_icon)).check(matches(isDisplayed()));%0A    %7D%0A    %0A    public void testCanToggleIcon() %7B%0A        // When the phone_icon view is available,%0A        // click it until the phone is no longer silent%0A        while( RingerHelper.isPhoneSilent(audioManager) )%0A            onView(withId(R.id.phone_icon)).perform(click());%0A%0A        // Sanity check that we're not in silent mode%0A        assertTrue(!RingerHelper.isPhoneSilent(audioManager));%0A%0A        // When the phone_icon view is available,%0A        // click it one more time.%0A        onView(withId(R.id.phone_icon)).perform(click());%0A        %0A        // Then assert that the phone is now in silent mode.%0A        assertTrue(RingerHelper.isPhoneSilent(audioManager
 ));%0A

Add a testcase to click phone icon