summaryrefslogtreecommitdiff
path: root/espresso/espresso-sample/src/androidTest
diff options
context:
space:
mode:
Diffstat (limited to 'espresso/espresso-sample/src/androidTest')
-rw-r--r--espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/ActionBarTest.java105
-rw-r--r--espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/AdapterViewTest.java142
-rw-r--r--espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/AdvancedSynchronizationTest.java91
-rw-r--r--espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/BasicTest.java100
-rw-r--r--espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/CustomFailureHandlerTest.java92
-rw-r--r--espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/DrawerActionsTest.java87
-rw-r--r--espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/LongListMatchers.java127
-rw-r--r--espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/LongListMatchersTest.java57
-rw-r--r--espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/MenuTest.java78
-rw-r--r--espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/MultipleWindowTest.java122
-rw-r--r--espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/ScrollToTest.java56
-rw-r--r--espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/SwipeTest.java96
12 files changed, 0 insertions, 1153 deletions
diff --git a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/ActionBarTest.java b/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/ActionBarTest.java
deleted file mode 100644
index 10485c9..0000000
--- a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/ActionBarTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.android.apps.common.testing.ui.testapp;
-
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.openContextualActionModeOverflowMenu;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
-import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
-
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-
-/**
- * Demonstrates Espresso with action bar and contextual action mode.
- * {@link openActionBarOverflowOrOptionsMenu()} opens the overflow menu from an action bar.
- * {@link openContextualActionModeOverflowMenu()} opens the overflow menu from an contextual action
- * mode.
- */
-@LargeTest
-public class ActionBarTest extends ActivityInstrumentationTestCase2<ActionBarTestActivity> {
- @SuppressWarnings("deprecation")
- public ActionBarTest() {
- // This constructor was deprecated - but we want to support lower API levels.
- super("com.google.android.apps.common.testing.ui.testapp", ActionBarTestActivity.class);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- // Espresso will not launch our activity for us, we must launch it via getActivity().
- getActivity();
- }
-
- @SuppressWarnings("unchecked")
- public void testClickActionBarItem() {
- onView(withId(R.id.hide_contextual_action_bar))
- .perform(click());
-
- onView(withId(R.id.action_save))
- .perform(click());
-
- onView(withId(R.id.text_action_bar_result))
- .check(matches(withText("Save")));
- }
-
- @SuppressWarnings("unchecked")
- public void testClickActionModeItem() {
- onView(withId(R.id.show_contextual_action_bar))
- .perform(click());
-
- onView((withId(R.id.action_lock)))
- .perform(click());
-
- onView(withId(R.id.text_action_bar_result))
- .check(matches(withText("Lock")));
- }
-
-
- @SuppressWarnings("unchecked")
- public void testActionBarOverflow() {
- onView(withId(R.id.hide_contextual_action_bar))
- .perform(click());
-
- // Open the overflow menu from action bar
- openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
-
- onView(withText("World"))
- .perform(click());
-
- onView(withId(R.id.text_action_bar_result))
- .check(matches(withText("World")));
- }
-
- @SuppressWarnings("unchecked")
- public void testActionModeOverflow() {
- onView(withId(R.id.show_contextual_action_bar))
- .perform(click());
-
- // Open the overflow menu from contextual action mode.
- openContextualActionModeOverflowMenu();
-
- onView(withText("Key"))
- .perform(click());
-
- onView(withId(R.id.text_action_bar_result))
- .check(matches(withText("Key")));
- }
-}
diff --git a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/AdapterViewTest.java b/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/AdapterViewTest.java
deleted file mode 100644
index fd531ec..0000000
--- a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/AdapterViewTest.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.android.apps.common.testing.ui.testapp;
-
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onData;
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
-import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
-import static com.google.android.apps.common.testing.ui.testapp.LongListMatchers.isFooter;
-import static com.google.android.apps.common.testing.ui.testapp.LongListMatchers.withItemContent;
-import static com.google.android.apps.common.testing.ui.testapp.LongListMatchers.withItemSize;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.view.View;
-import android.widget.Adapter;
-import android.widget.AdapterView;
-
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-import org.hamcrest.TypeSafeMatcher;
-
-/**
- * Demonstrates the usage of
- * {@link com.google.android.apps.common.testing.ui.espresso.Espresso#onData(org.hamcrest.Matcher)}
- * to match data within list views.
- */
-@LargeTest
-public class AdapterViewTest extends ActivityInstrumentationTestCase2<LongListActivity> {
-
- @SuppressWarnings("deprecation")
- public AdapterViewTest() {
- // This constructor was deprecated - but we want to support lower API levels.
- super("com.google.android.apps.common.testing.ui.testapp", LongListActivity.class);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- getActivity();
- }
-
- public void testClickOnItem50() {
- // The text view "item: 50" may not exist if we haven't scrolled to it.
- // By using onData api we tell Espresso to look into the Adapter for an item matching
- // the matcher we provide it. Espresso will then bring that item into the view hierarchy
- // and we can click on it.
-
- onData(withItemContent("item: 50"))
- .perform(click());
-
- onView(withId(R.id.selection_row_value))
- .check(matches(withText("50")));
- }
-
- public void testClickOnSpecificChildOfRow60() {
- onData(withItemContent("item: 60"))
- .onChildView(withId(R.id.item_size)) // resource id of second column from xml layout
- .perform(click());
-
- onView(withId(R.id.selection_row_value))
- .check(matches(withText("60")));
-
- onView(withId(R.id.selection_column_value))
- .check(matches(withText("2")));
- }
-
- public void testClickOnFirstAndFifthItemOfLength8() {
- onData(is(withItemSize(8)))
- .atPosition(0)
- .perform(click());
-
- onView(withId(R.id.selection_row_value))
- .check(matches(withText("10")));
-
- onData(is(withItemSize(8)))
- .atPosition(4)
- .perform(click());
-
- onView(withId(R.id.selection_row_value))
- .check(matches(withText("14")));
- }
-
- @SuppressWarnings("unchecked")
- public void testClickFooter() {
- onData(isFooter())
- .perform(click());
-
- onView(withId(R.id.selection_row_value))
- .check(matches(withText("100")));
- }
-
- @SuppressWarnings("unchecked")
- public void testDataItemNotInAdapter(){
- onView(withId(R.id.list))
- .check(matches(not(withAdaptedData(withItemContent("item: 168")))));
- }
-
- private static Matcher<View> withAdaptedData(final Matcher<Object> dataMatcher) {
- return new TypeSafeMatcher<View>() {
-
- @Override
- public void describeTo(Description description) {
- description.appendText("with class name: ");
- dataMatcher.describeTo(description);
- }
-
- @Override
- public boolean matchesSafely(View view) {
- if (!(view instanceof AdapterView)) {
- return false;
- }
- @SuppressWarnings("rawtypes")
- Adapter adapter = ((AdapterView) view).getAdapter();
- for (int i = 0; i < adapter.getCount(); i++) {
- if (dataMatcher.matches(adapter.getItem(i))) {
- return true;
- }
- }
- return false;
- }
- };
- }
-}
diff --git a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/AdvancedSynchronizationTest.java b/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/AdvancedSynchronizationTest.java
deleted file mode 100644
index d19fb69..0000000
--- a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/AdvancedSynchronizationTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.android.apps.common.testing.ui.testapp;
-
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.registerIdlingResources;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
-import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.android.apps.common.testing.ui.espresso.contrib.CountingIdlingResource;
-import com.google.android.apps.common.testing.ui.testapp.SyncActivity.HelloWorldServer;
-
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-
-/**
- * Example for {@link CountingIdlingResource}. Demonstrates how to wait on a delayed response from
- * request before continuing with a test.
- */
-@LargeTest
-public class AdvancedSynchronizationTest extends ActivityInstrumentationTestCase2<SyncActivity> {
-
- private class DecoratedHelloWorldServer implements HelloWorldServer {
- private final HelloWorldServer realHelloWorldServer;
- private final CountingIdlingResource helloWorldServerIdlingResource;
-
- private DecoratedHelloWorldServer(HelloWorldServer realHelloWorldServer,
- CountingIdlingResource helloWorldServerIdlingResource) {
- this.realHelloWorldServer = checkNotNull(realHelloWorldServer);
- this.helloWorldServerIdlingResource = checkNotNull(helloWorldServerIdlingResource);
- }
-
- @Override
- public String getHelloWorld() {
- // Use CountingIdlingResource to track in-flight calls to getHelloWorld (a simulation of a
- // network call). Whenever the count goes to zero, Espresso will be notified that this
- // resource is idle and the test will be able to proceed.
- helloWorldServerIdlingResource.increment();
- try {
- return realHelloWorldServer.getHelloWorld();
- } finally {
- helloWorldServerIdlingResource.decrement();
- }
- }
- }
-
- @SuppressWarnings("deprecation")
- public AdvancedSynchronizationTest() {
- // This constructor was deprecated - but we want to support lower API levels.
- super("com.google.android.apps.common.testing.ui.testapp", SyncActivity.class);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- SyncActivity activity = getActivity();
- HelloWorldServer realServer = activity.getHelloWorldServer();
- // Here, we use CountingIdlingResource - a common convenience class - to track the idle state of
- // the server. You could also do this yourself, by implementing the IdlingResource interface.
- CountingIdlingResource countingResource = new CountingIdlingResource("HelloWorldServerCalls");
- activity.setHelloWorldServer(new DecoratedHelloWorldServer(realServer, countingResource));
- registerIdlingResources(countingResource);
- }
-
- public void testCountingIdlingResource() {
- // Request the "hello world!" text by clicking on the request button.
- onView(withId(R.id.request_button)).perform(click());
-
- // Espresso waits for the resource to go idle and then continues.
-
- // The check if the text is visible can pass now.
- onView(withId(R.id.status_text)).check(matches(withText(R.string.hello_world)));
- }
-}
diff --git a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/BasicTest.java b/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/BasicTest.java
deleted file mode 100644
index ba2b282..0000000
--- a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/BasicTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.android.apps.common.testing.ui.testapp;
-
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onData;
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.pressBack;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.typeText;
-import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-
-/**
- * Highlights basic
- * {@link com.google.android.apps.common.testing.ui.espresso.Espresso#onView(org.hamcrest.Matcher)}
- * functionality.
- */
-@LargeTest
-public class BasicTest extends ActivityInstrumentationTestCase2<SimpleActivity> {
-
- @SuppressWarnings("deprecation")
- public BasicTest() {
- // This constructor was deprecated - but we want to support lower API levels.
- super("com.google.android.apps.common.testing.ui.testapp", SimpleActivity.class);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- // Espresso will not launch our activity for us, we must launch it via getActivity().
- getActivity();
- }
-
- public void testSimpleClickAndCheckText() {
- onView(withId(R.id.button_simple))
- .perform(click());
-
- onView(withId(R.id.text_simple))
- .check(matches(withText("Hello Espresso!")));
- }
-
- public void testTypingAndPressBack() {
- onView(withId(R.id.sendtext_simple))
- .perform(typeText("Have a cup of Espresso."));
-
- onView(withId(R.id.send_simple))
- .perform(click());
-
- // Clicking launches a new activity that shows the text entered above. You don't need to do
- // anything special to handle the activity transitions. Espresso takes care of waiting for the
- // new activity to be resumed and its view hierarchy to be laid out.
- onView(withId(R.id.display_data))
- .check(matches(withText(("Have a cup of Espresso."))));
-
- // Going back to the previous activity - lets make sure our text was perserved.
- pressBack();
-
- onView(withId(R.id.sendtext_simple))
- .check(matches(withText(containsString("Espresso"))));
- }
-
- @SuppressWarnings("unchecked")
- public void testClickOnSpinnerItemAmericano(){
- // Open the spinner.
- onView(withId(R.id.spinner_simple))
- .perform(click());
- // Spinner creates a List View with its contents - this can be very long and the element not
- // contributed to the ViewHierarchy - by using onData we force our desired element into the
- // view hierarchy.
- onData(allOf(is(instanceOf(String.class)), is("Americano")))
- .perform(click());
-
- onView(withId(R.id.spinnertext_simple))
- .check(matches(withText(containsString("Americano"))));
- }
-}
-
-
diff --git a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/CustomFailureHandlerTest.java b/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/CustomFailureHandlerTest.java
deleted file mode 100644
index 14a3baf..0000000
--- a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/CustomFailureHandlerTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.android.apps.common.testing.ui.testapp;
-
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.setFailureHandler;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
-
-import com.google.android.apps.common.testing.ui.espresso.FailureHandler;
-import com.google.android.apps.common.testing.ui.espresso.NoMatchingViewException;
-import com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler;
-
-import android.content.Context;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.util.Log;
-import android.view.View;
-
-import org.hamcrest.Matcher;
-
-/**
- * A sample of how to set a non-default {@link FailureHandler}.
- */
-@LargeTest
-public class CustomFailureHandlerTest extends ActivityInstrumentationTestCase2<MainActivity> {
-
- private static final String TAG = "CustomFailureHandlerTest";
-
- @SuppressWarnings("deprecation")
- public CustomFailureHandlerTest() {
- // This constructor was deprecated - but we want to support lower API levels.
- super("com.google.android.apps.common.testing.ui.testapp", MainActivity.class);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- getActivity();
- setFailureHandler(new CustomFailureHandler(getInstrumentation().getTargetContext()));
- }
-
- public void testWithCustomFailureHandler() {
- try {
- onView(withText("does not exist")).perform(click());
- } catch (MySpecialException expected) {
- Log.e(TAG, "Special exception is special and expected: ", expected);
- }
- }
-
- /**
- * A {@link FailureHandler} that re-throws {@link NoMatchingViewException} as
- * {@link MySpecialException}. All other functionality is delegated to
- * {@link DefaultFailureHandler}.
- */
- private static class CustomFailureHandler implements FailureHandler {
- private final FailureHandler delegate;
-
- public CustomFailureHandler(Context targetContext) {
- delegate = new DefaultFailureHandler(targetContext);
- }
-
- @Override
- public void handle(Throwable error, Matcher<View> viewMatcher) {
- try {
- delegate.handle(error, viewMatcher);
- } catch (NoMatchingViewException e) {
- throw new MySpecialException(e);
- }
- }
- }
-
- private static class MySpecialException extends RuntimeException {
- MySpecialException(Throwable cause) {
- super(cause);
- }
- }
-}
diff --git a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/DrawerActionsTest.java b/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/DrawerActionsTest.java
deleted file mode 100644
index b7c1337..0000000
--- a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/DrawerActionsTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.android.apps.common.testing.ui.testapp;
-
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onData;
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
-import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
-import static com.google.android.apps.common.testing.ui.espresso.contrib.DrawerActions.closeDrawer;
-import static com.google.android.apps.common.testing.ui.espresso.contrib.DrawerActions.openDrawer;
-import static com.google.android.apps.common.testing.ui.espresso.contrib.DrawerMatchers.isClosed;
-import static com.google.android.apps.common.testing.ui.espresso.contrib.DrawerMatchers.isOpen;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-
-import com.google.android.apps.common.testing.ui.espresso.contrib.DrawerActions;
-
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-
-/**
- * Demonstrates use of {@link DrawerActions}.
- */
-@LargeTest
-public class DrawerActionsTest extends ActivityInstrumentationTestCase2<DrawerActivity> {
-
- public DrawerActionsTest() {
- super(DrawerActivity.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- getActivity();
- }
-
- public void testOpenAndCloseDrawer() {
- // Drawer should not be open to start.
- onView(withId(R.id.drawer_layout)).check(matches(isClosed()));
-
- openDrawer(R.id.drawer_layout);
-
- // The drawer should now be open.
- onView(withId(R.id.drawer_layout)).check(matches(isOpen()));
-
- closeDrawer(R.id.drawer_layout);
-
- // Drawer should be closed again.
- onView(withId(R.id.drawer_layout)).check(matches(isClosed()));
- }
-
- @SuppressWarnings("unchecked")
- public void testDrawerOpenAndClick() {
- openDrawer(R.id.drawer_layout);
-
- onView(withId(R.id.drawer_layout)).check(matches(isOpen()));
-
- // Click an item in the drawer. We use onData because the drawer is backed by a ListView, and
- // the item may not necessarily be visible in the view hierarchy.
- int rowIndex = 2;
- String rowContents = DrawerActivity.DRAWER_CONTENTS[rowIndex];
- onData(allOf(is(instanceOf(String.class)), is(rowContents))).perform(click());
-
- // clicking the item should close the drawer.
- onView(withId(R.id.drawer_layout)).check(matches(isClosed()));
-
- // The text view will now display "You picked: Pickle"
- onView(withId(R.id.drawer_text_view)).check(matches(withText("You picked: " + rowContents)));
- }
-}
diff --git a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/LongListMatchers.java b/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/LongListMatchers.java
deleted file mode 100644
index 1518697..0000000
--- a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/LongListMatchers.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.android.apps.common.testing.ui.testapp;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.hasEntry;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-
-import com.google.android.apps.common.testing.ui.espresso.matcher.BoundedMatcher;
-
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-
-import java.util.Map;
-
-/**
- * Static utility methods to create {@link Matcher} instances that can be applied to the data
- * objects created by {@link com.google.android.apps.common.testing.ui.testapp.LongListActivity}.
- * <p>
- * These matchers are used by the
- * {@link com.google.android.apps.common.testing.ui.espresso.Espresso#onData(Matcher)} API and are
- * applied against the data exposed by @{link android.widget.ListView#getAdapter()}.
- * </p>
- * <p>
- * In LongListActivity's case - each row is a Map containing 2 key value pairs. The key "STR" is
- * mapped to a String which will be rendered into a TextView with the R.id.item_content. The other
- * key "LEN" is an Integer which is the length of the string "STR" refers to. This length is
- * rendered into a TextView with the id R.id.item_size.
- * </p>
- */
-public final class LongListMatchers {
-
- private LongListMatchers() { }
-
-
- /**
- * Creates a matcher against the text stored in R.id.item_content. This text is roughly
- * "item: $row_number".
- */
- public static Matcher<Object> withItemContent(String expectedText) {
- // use preconditions to fail fast when a test is creating an invalid matcher.
- checkNotNull(expectedText);
- return withItemContent(equalTo(expectedText));
- }
-
- /**
- * Creates a matcher against the text stored in R.id.item_content. This text is roughly
- * "item: $row_number".
- */
- @SuppressWarnings("rawtypes")
- public static Matcher<Object> withItemContent(final Matcher<String> itemTextMatcher) {
- // use preconditions to fail fast when a test is creating an invalid matcher.
- checkNotNull(itemTextMatcher);
- return new BoundedMatcher<Object, Map>(Map.class) {
- @Override
- public boolean matchesSafely(Map map) {
- return hasEntry(equalTo("STR"), itemTextMatcher).matches(map);
- }
-
- @Override
- public void describeTo(Description description) {
- description.appendText("with item content: ");
- itemTextMatcher.describeTo(description);
- }
- };
- }
-
- /**
- * Creates a matcher against the text stored in R.id.item_size. This text is the size of the text
- * printed in R.id.item_content.
- */
- public static Matcher<Object> withItemSize(int itemSize) {
- // use preconditions to fail fast when a test is creating an invalid matcher.
- checkArgument(itemSize > -1);
- return withItemSize(equalTo(itemSize));
- }
-
- /**
- * Creates a matcher against the text stored in R.id.item_size. This text is the size of the text
- * printed in R.id.item_content.
- */
- @SuppressWarnings("rawtypes")
- public static Matcher<Object> withItemSize(final Matcher<Integer> itemSizeMatcher) {
- // use preconditions to fail fast when a test is creating an invalid matcher.
- checkNotNull(itemSizeMatcher);
- return new BoundedMatcher<Object, Map>(Map.class) {
- @Override
- public boolean matchesSafely(Map map) {
- return hasEntry(equalTo("LEN"), itemSizeMatcher).matches(map);
- }
-
- @Override
- public void describeTo(Description description) {
- description.appendText("with item size: ");
- itemSizeMatcher.describeTo(description);
- }
- };
- }
-
- /**
- * Creates a matcher against the footer of this list view.
- */
- @SuppressWarnings("unchecked")
- public static Matcher<Object> isFooter() {
- // This depends on LongListActivity.FOOTER being passed as data in the addFooterView method.
- return allOf(is(instanceOf(String.class)), is(LongListActivity.FOOTER));
- }
-
-}
diff --git a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/LongListMatchersTest.java b/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/LongListMatchersTest.java
deleted file mode 100644
index 3b80757..0000000
--- a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/LongListMatchersTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.android.apps.common.testing.ui.testapp;
-
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.assertThat;
-import static com.google.android.apps.common.testing.ui.testapp.LongListMatchers.withItemContent;
-import static com.google.android.apps.common.testing.ui.testapp.LongListMatchers.withItemSize;
-import static org.hamcrest.Matchers.anyOf;
-import static org.hamcrest.Matchers.endsWith;
-import static org.hamcrest.Matchers.equalTo;
-
-import android.content.Intent;
-import android.test.ActivityUnitTestCase;
-
-/**
- * UnitTests for LongListMatchers matcher factory.
- */
-public final class LongListMatchersTest extends ActivityUnitTestCase<LongListActivity> {
-
- public LongListMatchersTest() {
- super(LongListActivity.class);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- startActivity(new Intent(getInstrumentation().getTargetContext(), LongListActivity.class),
- null, null);
- }
-
- public void testWithContent() {
- assertThat(getActivity().makeItem(54), withItemContent("item: 54"));
- assertThat(getActivity().makeItem(54), withItemContent(endsWith("54")));
- assertFalse(withItemContent("hello world").matches(getActivity().makeItem(54)));
- }
-
- @SuppressWarnings("unchecked")
- public void testWithItemSize() {
- assertThat(getActivity().makeItem(54), withItemSize(8));
- assertThat(getActivity().makeItem(54), withItemSize(anyOf(equalTo(8), equalTo(7))));
- assertFalse(withItemSize(7).matches(getActivity().makeItem(54)));
- }
-}
diff --git a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/MenuTest.java b/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/MenuTest.java
deleted file mode 100644
index 9ea8898..0000000
--- a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/MenuTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.android.apps.common.testing.ui.testapp;
-
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.longClick;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.pressMenuKey;
-import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.doesNotExist;
-import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isRoot;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
-
-import android.os.Build;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-
-/**
- * Ensures view root ordering works properly.
- */
-@LargeTest
-public class MenuTest extends ActivityInstrumentationTestCase2<MenuActivity> {
- @SuppressWarnings("deprecation")
- public MenuTest() {
- // This constructor was deprecated - but we want to support lower API levels.
- super("com.google.android.apps.common.testing.ui.testapp", MenuActivity.class);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- getActivity();
- }
-
- public void testPopupMenu() {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
- // popup menus are post honeycomb.
- return;
- }
- onView(withText(R.string.popup_item_1_text)).check(doesNotExist());
- onView(withId(R.id.popup_button)).perform(click());
- onView(withText(R.string.popup_item_1_text)).check(matches(isDisplayed())).perform(click());
-
- onView(withId(R.id.text_menu_result)).check(matches(withText(R.string.popup_item_1_text)));
- }
-
- public void testContextMenu() {
- onView(withText(R.string.context_item_2_text)).check(doesNotExist());
- onView(withId(R.id.text_context_menu)).perform(longClick());
- onView(withText(R.string.context_item_2_text)).check(matches(isDisplayed())).perform(click());
-
- onView(withId(R.id.text_menu_result)).check(matches(withText(R.string.context_item_2_text)));
- }
-
- public void testOptionMenu() {
- onView(withText(R.string.options_item_3_text)).check(doesNotExist());
- onView(isRoot()).perform(pressMenuKey());
- onView(withText(R.string.options_item_3_text)).check(matches(isDisplayed())).perform(click());
-
- onView(withId(R.id.text_menu_result)).check(matches(withText(R.string.options_item_3_text)));
- }
-}
diff --git a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/MultipleWindowTest.java b/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/MultipleWindowTest.java
deleted file mode 100644
index 23c3ea3..0000000
--- a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/MultipleWindowTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.android.apps.common.testing.ui.testapp;
-
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onData;
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.clearText;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.scrollTo;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.typeText;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.typeTextIntoFocusedView;
-import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.RootMatchers.withDecorView;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-
-import android.os.Build;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-
-/**
- * Demonstrates dealing with multiple windows.
- *
- * Espresso provides the ability to switch the default window matcher used in both onView and onData
- * interactions.
- *
- * @see com.google.android.apps.common.testing.ui.espresso.Espresso#onView
- * @see com.google.android.apps.common.testing.ui.espresso.Espresso#onData
- */
-@LargeTest
-public class MultipleWindowTest extends ActivityInstrumentationTestCase2<SendActivity> {
-
- @SuppressWarnings("deprecation")
- public MultipleWindowTest() {
- // This constructor was deprecated - but we want to support lower API levels.
- super("com.google.android.apps.common.testing.ui.testapp", SendActivity.class);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- // Espresso will not launch our activity for us, we must launch it via getActivity().
- getActivity();
- }
-
- public void testInteractionsWithAutoCompletePopup() {
- if (Build.VERSION.SDK_INT < 10) {
- // Froyo's AutoCompleteTextBox is broken - do not bother testing with it.
- return;
- }
- // Android's Window system allows multiple view hierarchies to layer on top of each other.
- //
- // A real world analogy would be an overhead projector with multiple transparencies placed
- // on top of each other. Each Window is a transparency, and what is drawn on top of this
- // transparency is the view hierarchy.
- //
- // By default Espresso uses a heuristic to guess which Window you intend to interact with.
- // This heuristic is normally 'good enough' however if you want to interact with a Window
- // that it does not select then you'll have to swap in your own root window matcher.
-
-
- // Initially we only have 1 window, but by typing into the auto complete text view another
- // window will be layered on top of the screen. Espresso ignore's this layer because it is
- // not connected to the keyboard/ime.
- onView(withId(R.id.auto_complete_text_view))
- .perform(scrollTo())
- .perform(typeText("So"));
-
- // As you can see, we continue typing oblivious to the new window on the screen.
- // At the moment there should be 2 completions (South China Sea and Southern Ocean)
- // Lets narrow that down to 1 completion.
- onView(withId(R.id.auto_complete_text_view))
- .perform(typeTextIntoFocusedView("uth "));
-
- // Now we may want to explicitly tap on a completion. We must override Espresso's
- // default window selection heuristic with our own.
- onView(withText("South China Sea"))
- .inRoot(withDecorView(not(is(getActivity().getWindow().getDecorView()))))
- .perform(click());
-
- // And by clicking on the auto complete term, the text should be filled in.
- onView(withId(R.id.auto_complete_text_view))
- .check(matches(withText("South China Sea")));
-
-
- // NB: The autocompletion box is implemented with a ListView, so the preferred way
- // to interact with it is onData(). We can use inRoot here too!
- onView(withId(R.id.auto_complete_text_view))
- .perform(clearText())
- .perform(typeText("S"));
-
- // Which is useful because some of the completions may not be part of the View Hierarchy
- // unless you scroll around the list.
- onData(allOf(instanceOf(String.class), is("Baltic Sea")))
- .inRoot(withDecorView(not(is(getActivity().getWindow().getDecorView()))))
- .perform(click());
-
- onView(withId(R.id.auto_complete_text_view))
- .check(matches(withText("Baltic Sea")));
- }
-
-}
-
-
diff --git a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/ScrollToTest.java b/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/ScrollToTest.java
deleted file mode 100644
index 6cf7836..0000000
--- a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/ScrollToTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.android.apps.common.testing.ui.testapp;
-
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.scrollTo;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
-import static org.hamcrest.Matchers.is;
-
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-
-
-/**
- * Demonstrates the usage of
- * {@link com.google.android.apps.common.testing.ui.espresso.action.ViewActions#scrollTo()}.
- */
-@LargeTest
-public class ScrollToTest extends ActivityInstrumentationTestCase2<ScrollActivity> {
-
- @SuppressWarnings("deprecation")
- public ScrollToTest() {
- // This constructor was deprecated - but we want to support lower API levels.
- super("com.google.android.apps.common.testing.ui.testapp", ScrollActivity.class);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- // Espresso will not launch our activity for us, we must launch it via getActivity().
- getActivity();
- }
-
- // You can pass more than one action to perform. This is useful if you are performing two actions
- // back-to-back on the same view.
- // Note - scrollTo is a no-op if the view is already displayed on the screen.
- public void testScrollToInScrollView() {
- onView(withId(is(R.id.bottom_left)))
- .perform(scrollTo(), click());
- }
-}
diff --git a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/SwipeTest.java b/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/SwipeTest.java
deleted file mode 100644
index 46704ec..0000000
--- a/espresso/espresso-sample/src/androidTest/java/com/google/android/apps/common/testing/ui/testapp/SwipeTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.android.apps.common.testing.ui.testapp;
-
-import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.swipeLeft;
-import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.swipeRight;
-import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
-import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
-
-import com.google.android.apps.common.testing.ui.espresso.action.ViewActions;
-
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
-
-/**
- * Demonstrates use of {@link ViewActions#swipeLeft()} and {@link ViewActions#swipeRight()}.
- */
-@LargeTest
-public class SwipeTest extends ActivityInstrumentationTestCase2<ViewPagerActivity> {
-
- @SuppressWarnings("deprecation")
- public SwipeTest() {
- // This constructor was deprecated - but we want to support lower API levels.
- super("com.google.android.apps.common.testing.ui.testapp", ViewPagerActivity.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- getActivity();
- }
-
- public void testSwipingThroughViews() {
- // Should be on position 0 to start with.
- onView(withText("Position #0")).check(matches(isDisplayed()));
-
- // Swipe left once.
- onView(withId(R.id.pager_layout)).perform(swipeLeft());
-
- // Now position 1 should be visible.
- onView(withText("Position #1")).check(matches(isDisplayed()));
-
- // Swipe left again.
- onView(withId(R.id.pager_layout)).perform(swipeLeft());
-
- // Now position 2 should be visible.
- onView(withText("Position #2")).check(matches(isDisplayed()));
-
- // Swipe left again.
- onView(withId(R.id.pager_layout)).perform(swipeLeft());
-
- // Position 2 should still be visible as this is the last view in the pager.
- onView(withText("Position #2")).check(matches(isDisplayed()));
- }
-
- public void testSwipingBackAndForward() {
- // Should be on position 0 to start with.
- onView(withText("Position #0")).check(matches(isDisplayed()));
-
- // Swipe left once.
- onView(withId(R.id.pager_layout)).perform(swipeLeft());
-
- // Now position 1 should be visible.
- onView(withText("Position #1")).check(matches(isDisplayed()));
-
- // Swipe back to the right.
- onView(withId(R.id.pager_layout)).perform(swipeRight());
-
- // Now position 0 should be visible again.
- onView(withText("Position #0")).check(matches(isDisplayed()));
-
- // Swipe right again.
- onView(withId(R.id.pager_layout)).perform(swipeRight());
-
- // Position 0 should still be visible as this is the first view in the pager.
- onView(withText("Position #0")).check(matches(isDisplayed()));
- }
-
-}