package fr.miage.paris10.projetm1.helpu;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.widget.Toast;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

/**
 * Created by dameimou on 07/03/2017.
 */

@RunWith(AndroidJUnit4.class)
public class LoginActivityTest {
    @Rule
    public ActivityTestRule<LoginActivity> loginActivityRule  = new ActivityTestRule<>(LoginActivity.class);


    @Test
    public void testGoodLogIn() {
        onView(withId(R.id.input_email))
                .perform(typeText("33012900@u-paris10.fr"), closeSoftKeyboard());
        Thread.sleep(1000);
        onView(withId(R.id.input_password)).perform(typeText("azerty"), closeSoftKeyboard());
        Thread.sleep(500);
        onView(withId(R.id.btn_login)).perform(click());
    }
   @Test
    public void testFalseLogIn() {
       LoginActivity activity = loginActivityRule.getActivity();
        onView(withId(R.id.input_email))
                .perform(typeText("a@u-paris10.fr"), closeSoftKeyboard());
        Thread.sleep(1000);
        onView(withId(R.id.input_password)).perform(typeText("azerty"), closeSoftKeyboard());
        Thread.sleep(500);
        onView(withId(R.id.btn_login)).perform(click());
               onView(withText("Login failed")).
                       inRoot(withDecorView(not(is(activity.getWindow().getDecorView())))).
                       check(matches(isDisplayed()));
    }
}

@@ -1784,24 +1784,53 @@
 tGoodLogIn()
+  throws InterruptedException
  %7B%0A        o
@@ -2196,16 +2196,44 @@
 eLogIn()
+ throws InterruptedException
  %7B%0A     

Update LoginActivityTest.java