forked from upstream-mirrors/OpenTracks
Cleanup unused utils
This commit is contained in:
committed by
mmarca.tech
parent
b679f00cc5
commit
def4f3a1b9
@@ -6,9 +6,9 @@ import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
|
||||
import static androidx.test.espresso.action.ViewActions.replaceText;
|
||||
import static androidx.test.espresso.action.ViewActions.scrollTo;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static androidx.test.espresso.matcher.RootMatchers.isPlatformPopup;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
@@ -16,7 +16,6 @@ import static de.dennisguse.opentracks.util.ActivityTestUtils.waitForResumedActi
|
||||
import static de.dennisguse.opentracks.util.EspressoUtils.performClick;
|
||||
import static de.dennisguse.opentracks.util.EspressoUtils.performClickOnAncestor;
|
||||
import static de.dennisguse.opentracks.util.EspressoUtils.performLongClick;
|
||||
import static de.dennisguse.opentracks.util.EspressoUtils.waitForView;
|
||||
import static de.dennisguse.opentracks.util.EspressoUtils.waitForResumedView;
|
||||
import static de.dennisguse.opentracks.util.TrackRecordingServiceTestUtils.waitForRecordingState;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
@@ -82,10 +81,8 @@ public class EspressoEditTrackRecordingTest {
|
||||
withContentDescription(androidx.appcompat.R.string.abc_action_menu_overflow_description),
|
||||
isDescendantOfA(withId(R.id.bottom_app_bar))))
|
||||
.perform(performClick());
|
||||
waitUntilDisplayedInCurrentRoot(withText(R.string.menu_edit));
|
||||
|
||||
// Click the item.
|
||||
onView(withText(R.string.menu_edit))
|
||||
.inRoot(isPlatformPopup())
|
||||
.perform(performClickOnAncestor());
|
||||
waitUntilDisplayed(withId(R.id.track_edit_name));
|
||||
|
||||
@@ -119,8 +116,4 @@ public class EspressoEditTrackRecordingTest {
|
||||
private void waitUntilDisplayed(Matcher<View> viewMatcher) {
|
||||
waitForResumedView(allOf(viewMatcher, isDisplayed()), UI_TIMEOUT);
|
||||
}
|
||||
|
||||
private void waitUntilDisplayedInCurrentRoot(Matcher<View> viewMatcher) {
|
||||
onView(isRoot()).perform(waitForView(allOf(viewMatcher, isDisplayed()), UI_TIMEOUT));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package de.dennisguse.opentracks.util;
|
||||
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.SystemClock;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.test.espresso.PerformException;
|
||||
@@ -30,46 +28,12 @@ import org.hamcrest.TypeSafeMatcher;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class EspressoUtils {
|
||||
|
||||
private static final long VIEW_POLLING_INTERVAL_MS = 50;
|
||||
|
||||
public static Matcher<View> childAtPosition(
|
||||
final Matcher<View> parentMatcher, final int position) {
|
||||
|
||||
return new TypeSafeMatcher<>() {
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("Child at position " + position + " in parent ");
|
||||
parentMatcher.describeTo(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesSafely(View view) {
|
||||
ViewParent parent = view.getParent();
|
||||
return parent instanceof ViewGroup && parentMatcher.matches(parent)
|
||||
&& view.equals(((ViewGroup) parent).getChildAt(position));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Matcher<View> withListSize (final int size) {
|
||||
return new TypeSafeMatcher<>() {
|
||||
@Override
|
||||
public boolean matchesSafely(final View view) {
|
||||
return ((ListView) view).getCount() == size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(final Description description) {
|
||||
description.appendText("ListView should have " + size + " items");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Matcher<View> withRecyclerViewItemCount(final int count) {
|
||||
return new TypeSafeMatcher<>() {
|
||||
@Override
|
||||
@@ -120,50 +84,6 @@ public class EspressoUtils {
|
||||
};
|
||||
}
|
||||
|
||||
public static ViewAction waitForView(final Matcher<View> viewMatcher, final Duration timeout) {
|
||||
return waitForViewCondition(viewMatcher, ignored -> true, "view to match " + viewMatcher, timeout);
|
||||
}
|
||||
|
||||
public static ViewAction waitForViewCondition(final Matcher<View> viewMatcher,
|
||||
final Predicate<View> condition,
|
||||
final String conditionDescription,
|
||||
final Duration timeout) {
|
||||
return new ViewAction() {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "wait up to " + timeout + " ms for " + conditionDescription;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Matcher<View> getConstraints() {
|
||||
return isRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(UiController uiController, View view) {
|
||||
long deadline = SystemClock.uptimeMillis() + timeout.toMillis();
|
||||
|
||||
do {
|
||||
uiController.loopMainThreadUntilIdle();
|
||||
|
||||
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
|
||||
if (viewMatcher.matches(child) && condition.test(child)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
uiController.loopMainThreadForAtLeast(VIEW_POLLING_INTERVAL_MS);
|
||||
} while (SystemClock.uptimeMillis() < deadline);
|
||||
|
||||
throw new PerformException.Builder()
|
||||
.withActionDescription(getDescription())
|
||||
.withViewDescription(HumanReadables.describe(view))
|
||||
.withCause(new TimeoutException("Timed out waiting for " + conditionDescription))
|
||||
.build();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void waitForResumedView(final Matcher<View> viewMatcher, final Duration timeout) {
|
||||
waitForResumedViewCondition(viewMatcher, ignored -> true, "view to match " + viewMatcher, timeout);
|
||||
}
|
||||
@@ -256,7 +176,7 @@ public class EspressoUtils {
|
||||
|
||||
@Override
|
||||
public Matcher<View> getConstraints() {
|
||||
return isDisplayed();
|
||||
return isAssignableFrom(View.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user