diff --git a/library/src/androidTest/java/me/drakeet/toast/ExampleInstrumentedTest.java b/library/src/androidTest/java/me/drakeet/toast/ExampleInstrumentedTest.java
deleted file mode 100644
index 9f11fd8..0000000
--- a/library/src/androidTest/java/me/drakeet/toast/ExampleInstrumentedTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package me.drakeet.toast;
-
-import android.content.Context;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import static org.junit.Assert.*;
-
-/**
- * Instrumented test, which will execute on an Android device.
- *
- * @see Testing documentation
- */
-@RunWith(AndroidJUnit4.class)
-public class ExampleInstrumentedTest {
- @Test
- public void useAppContext() throws Exception {
- // Context of the app under test.
- Context appContext = InstrumentationRegistry.getTargetContext();
-
- assertEquals("me.drakeet.toast.test", appContext.getPackageName());
- }
-}
diff --git a/sample/src/androidTest/java/me/drakeet/toast/ExampleInstrumentedTest.java b/sample/src/androidTest/java/me/drakeet/toast/ExampleInstrumentedTest.java
deleted file mode 100644
index 81e340b..0000000
--- a/sample/src/androidTest/java/me/drakeet/toast/ExampleInstrumentedTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package me.drakeet.toast;
-
-import android.content.Context;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import static org.junit.Assert.*;
-
-/**
- * Instrumented test, which will execute on an Android device.
- *
- * @see Testing documentation
- */
-@RunWith(AndroidJUnit4.class)
-public class ExampleInstrumentedTest {
- @Test
- public void useAppContext() throws Exception {
- // Context of the app under test.
- Context appContext = InstrumentationRegistry.getTargetContext();
-
- assertEquals("me.drakeet.toastcompat", appContext.getPackageName());
- }
-}
diff --git a/sample/src/androidTest/java/me/drakeet/toast/sample/MainActivityTest.java b/sample/src/androidTest/java/me/drakeet/toast/sample/MainActivityTest.java
new file mode 100644
index 0000000..0d631ec
--- /dev/null
+++ b/sample/src/androidTest/java/me/drakeet/toast/sample/MainActivityTest.java
@@ -0,0 +1,32 @@
+package me.drakeet.toast.sample;
+
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
+import android.test.suitebuilder.annotation.LargeTest;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static android.support.test.espresso.Espresso.onView;
+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;
+
+@LargeTest
+@RunWith(AndroidJUnit4.class)
+public class MainActivityTest {
+
+ @Rule
+ public ActivityTestRule rule = new ActivityTestRule<>(MainActivity.class);
+
+
+ @Test
+ public void shouldShowToastWithHello() {
+ onView(withText("hello"))
+ .inRoot(withDecorView(not(is(rule.getActivity().getWindow().getDecorView()))))
+ .check(matches(isDisplayed()));
+ }
+}
diff --git a/sample/src/main/java/me/drakeet/toast/sample/MainActivity.java b/sample/src/main/java/me/drakeet/toast/sample/MainActivity.java
index 290a890..a28acd7 100644
--- a/sample/src/main/java/me/drakeet/toast/sample/MainActivity.java
+++ b/sample/src/main/java/me/drakeet/toast/sample/MainActivity.java
@@ -1,10 +1,8 @@
package me.drakeet.toast.sample;
import android.os.Bundle;
-import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
-import android.widget.TextView;
import android.widget.Toast;
import me.drakeet.support.toast.ToastCompat;
@@ -16,17 +14,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
ToastCompat.makeText(this, "hello", Toast.LENGTH_SHORT)
.setBadTokenListener(toast -> {
- Log.e("failed toast", text(toast));
+ Log.e("failed toast", "hello");
}).show();
}
-
-
- private @NonNull String text(@NonNull Toast toast) {
- TextView textView = toast.getView().findViewById(com.android.internal.R.id.message);
- if (textView != null) {
- return textView.getText().toString();
- } else {
- return toast.toString();
- }
- }
}