android.support.test.espresso.NoMatchingViewException Java Examples

The following examples show how to use android.support.test.espresso.NoMatchingViewException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LayoutManagerItemVisibilityAssertion.java    From espresso-macchiato with MIT License 6 votes vote down vote up
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
    if (noViewFoundException != null) {
        throw noViewFoundException;
    }

    RecyclerView recyclerView = (RecyclerView) view;
    if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
        int lastVisibleItem = layoutManager.findLastVisibleItemPosition();

        boolean indexInRange = firstVisibleItem <= index && index <= lastVisibleItem;
        if ((shouldBeVisible && !indexInRange) || (!shouldBeVisible && indexInRange)) {
            String errorMessage = "expected item " + index + " to " +
                    (shouldBeVisible ? "" : "not") + " be visible, but was" +
                    (indexInRange ? "" : " not") + " visible";
            throw new AssertionError(errorMessage);

        }
    }
}
 
Example #2
Source File: TestElectionChoice.java    From polling-station-app with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
    public void clickOnElection() throws Exception {
        final Election e = electionActivity.getAdapter().getItem(1);

        onData(instanceOf(Election.class)) // We are using the position so don't need to specify a data matcher
                .inAdapterView(withId(R.id.election_list)) // Specify the explicit id of the ListView
                .atPosition(1) // Explicitly specify the adapter item to use
                .perform(click());
//        intended(hasComponent(MainActivity.class.getName()));
        onView(withId(R.id.app_bar)).check(new ViewAssertion() {
            @Override
            public void check(View view, NoMatchingViewException noViewFoundException) {
                assertEquals(((Toolbar) view).getTitle(), e.getKind());
                assertEquals(((Toolbar) view).getSubtitle(), e.getPlace());
            }
        });
    }
 
Example #3
Source File: TestElectionChoice.java    From polling-station-app with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
    public void searchCityAndClick() throws Exception {
        List<Election> unfilteredList = electionActivity.getAdapter().getList();

        onView(withId(R.id.search)).perform(click());

        final Election toClick = unfilteredList.get(0);
        onView(withId(android.support.design.R.id.search_src_text)).perform(typeText(toClick.getPlace()));

        onView (withId (R.id.election_list)).check (ViewAssertions.matches (new Matchers().withListSize (1)));

        onData(instanceOf(Election.class))
                .inAdapterView(withId(R.id.election_list))
                .atPosition(0)
                .perform(click());
//        intended(hasComponent(MainActivity.class.getName()));
        onView(withId(R.id.app_bar)).check(new ViewAssertion() {
            @Override
            public void check(View view, NoMatchingViewException noViewFoundException) {
                assertEquals(((Toolbar) view).getTitle(), toClick.getKind());
                assertEquals(((Toolbar) view).getSubtitle(), toClick.getPlace());
            }
        });
    }
 
Example #4
Source File: GridLayoutManagerColumnCountAssertion.java    From espresso-macchiato with MIT License 6 votes vote down vote up
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
    if (noViewFoundException != null) {
        throw noViewFoundException;
    }

    RecyclerView recyclerView = (RecyclerView) view;
    if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
        GridLayoutManager gridLayoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
        int spanCount = gridLayoutManager.getSpanCount();
        if (spanCount != expectedColumnCount) {
            String errorMessage = "expected column count " + expectedColumnCount
                    + " but was " + spanCount;
            throw new AssertionError(errorMessage);
        }
    } else {
        throw new IllegalStateException("no grid layout manager");
    }
}
 
Example #5
Source File: ViewAssertions.java    From zulip-android with Apache License 2.0 6 votes vote down vote up
public static ViewAssertion checkMessagesOnlyFromToday() {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException e) {
            if (!(view instanceof RecyclerView)) {
                throw e;
            }
            RecyclerView rv = (RecyclerView) view;
            RecyclerMessageAdapter recyclerMessageAdapter = (RecyclerMessageAdapter) rv.getAdapter();
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("OfDate-" + (new Date()).toString() + " { ");
            for (int index = 0; index < recyclerMessageAdapter.getItemCount(); index++) {
                if (recyclerMessageAdapter.getItem(index) instanceof Message) {
                    Message message = (Message) recyclerMessageAdapter.getItem(index);
                    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.US);
                    stringBuilder.append(message.getID() + "-" + sdf.format(message.getTimestamp()) + " , ");
                    assertTrue("This message is not of today ID=" + message.getID() + ":" + message.getIdForHolder() + "\ncontent=" + message.getContent(), DateUtils.isToday(message.getTimestamp().getTime()));
                }
            }
            stringBuilder.append(" }");
            printLogInPartsIfExceeded(stringBuilder, "checkMessagesOnlyFromToday");
        }
    };
}
 
Example #6
Source File: Util.java    From DebugRank with Apache License 2.0 6 votes vote down vote up
public static ViewAssertion flexGridHasCode(final List<CodeLine> expectedCodeLines)
{
    return new ViewAssertion()
    {
        @Override
        public void check(View view, NoMatchingViewException noViewException)
        {
            FlexGrid flexGrid = (FlexGrid) view;

            List<CodeLine> actualCodeLines = (List<CodeLine>) flexGrid.getItemsSource();

            for (int i = 0; i < expectedCodeLines.size(); i++)
            {
                CodeLine expected = expectedCodeLines.get(i);
                CodeLine actual = actualCodeLines.get(i);

                assertEquals(expected.getCodeText(), actual.getCodeText());
            }
        }
    };
}
 
Example #7
Source File: CameraViewTest.java    From cameraview with Apache License 2.0 6 votes vote down vote up
private static ViewAssertion showingPreview() {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            CameraView cameraView = (CameraView) view;
            TextureView textureView = cameraView.findViewById(R.id.texture_view);
            Bitmap bitmap = textureView.getBitmap();
            int topLeft = bitmap.getPixel(0, 0);
            int center = bitmap.getPixel(bitmap.getWidth() / 2, bitmap.getHeight() / 2);
            int bottomRight = bitmap.getPixel(
                    bitmap.getWidth() - 1, bitmap.getHeight() - 1);
            assertFalse("Preview possibly blank: " + Integer.toHexString(topLeft),
                    topLeft == center && center == bottomRight);
        }
    };
}
 
Example #8
Source File: EspressoTools.java    From android-step-by-step with Apache License 2.0 6 votes vote down vote up
public static ViewAssertion doesntHaveViewWithText(final String text) {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException e) {
            if (!(view instanceof RecyclerView)) {
                throw e;
            }
            RecyclerView rv = (RecyclerView) view;
            ArrayList<View> outviews = new ArrayList<>();
            for (int index = 0; index < rv.getAdapter().getItemCount(); index++) {
                rv.findViewHolderForAdapterPosition(index).itemView.findViewsWithText(outviews, text,
                        FIND_VIEWS_WITH_TEXT);
                if (outviews.size() > 0) break;
            }
            Truth.assertThat(outviews).isEmpty();
        }
    };
}
 
Example #9
Source File: CameraViewTest.java    From cameraview with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoFocus() {
    onView(withId(R.id.camera))
            .check(new ViewAssertion() {
                @Override
                public void check(View view, NoMatchingViewException noViewFoundException) {
                    CameraView cameraView = (CameraView) view;
                    // This can fail on devices without auto-focus support
                    assertThat(cameraView.getAutoFocus(), is(true));
                    cameraView.setAutoFocus(false);
                    assertThat(cameraView.getAutoFocus(), is(false));
                    cameraView.setAutoFocus(true);
                    assertThat(cameraView.getAutoFocus(), is(true));
                }
            });
}
 
Example #10
Source File: EspRecyclerViewItem.java    From espresso-macchiato with MIT License 6 votes vote down vote up
/**
 * Check that this item exist.
 *
 * Is true when adapter has matching item ignores the display state.
 *
 * @since Espresso Macchiato 0.6
 */

public void assertExist() {
    findRecyclerView().check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if (noViewFoundException != null) {
                throw noViewFoundException;
            }

            RecyclerView recyclerView = (RecyclerView) view;
            if (index >= recyclerView.getAdapter().getItemCount()) {
                throw new AssertionFailedError("Requested item should exist.");
            }
        }
    });
}
 
Example #11
Source File: EspressoTools.java    From android-step-by-step with Apache License 2.0 6 votes vote down vote up
public static ViewAssertion hasViewWithTextAtPosition(final int index, final CharSequence text) {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException e) {
            if (!(view instanceof RecyclerView)) {
                throw e;
            }
            RecyclerView rv = (RecyclerView) view;
            ArrayList<View> outviews = new ArrayList<>();
            rv.findViewHolderForAdapterPosition(index).itemView.findViewsWithText(outviews, text,
                    FIND_VIEWS_WITH_TEXT);
            Truth.assert_().withFailureMessage("There's no view at index " + index + " of recyclerview that has text : " + text)
                    .that(outviews).isNotEmpty();
        }
    };
}
 
Example #12
Source File: ViewAssertions.java    From zulip-android with Apache License 2.0 5 votes vote down vote up
public static ViewAssertion checkIfMessagesMatchTheHeaderParent(final ZulipActivity zulipActivity) {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noMatchingViewException) {
            if (!(view instanceof RecyclerView)) {
                throw noMatchingViewException;
            }

            RecyclerMessageAdapter recyclerMessageAdapter = (RecyclerMessageAdapter) ((RecyclerView) view).getAdapter();
            String lastHolderId = null;
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < recyclerMessageAdapter.getItemCount() - 1; i++) {
                Object object = recyclerMessageAdapter.getItem(i);
                if (object instanceof MessageHeaderParent) {
                    lastHolderId = ((MessageHeaderParent) object).getId();
                    stringBuilder.append("} \'MHP\'-\'" + lastHolderId + " {");
                } else if (object instanceof Message) {
                    Message message = (Message) object;
                    boolean checkOrder = (lastHolderId.equals(message.getIdForHolder()));
                    assertTrue(generateDetailDebugInfoForCorrectHeaderParent(message, zulipActivity, lastHolderId, i), checkOrder);
                    stringBuilder.append(message.getIdForHolder() + "-" + message.getID() + " , ");
                }
            }
            stringBuilder.append('}');
            printLogInPartsIfExceeded(stringBuilder, "checkIfMessagesMatchTheHeaderParent");
        }
    };
}
 
Example #13
Source File: RecyclerItemViewAssertion.java    From Game-of-Thrones with Apache License 2.0 5 votes vote down vote up
@Override
public final void check(View view, NoMatchingViewException e) {
  RecyclerView recyclerView = (RecyclerView) view;
  RecyclerView.ViewHolder viewHolderForPosition =
      recyclerView.findViewHolderForLayoutPosition(position);
  if (viewHolderForPosition == null) {
    throw (new PerformException.Builder()).withActionDescription(toString())
        .withViewDescription(HumanReadables.describe(view))
        .withCause(new IllegalStateException("No view holder at position: " + position))
        .build();
  } else {
    View viewAtPosition = viewHolderForPosition.itemView;
    itemViewAssertion.check(item, viewAtPosition, e);
  }
}
 
Example #14
Source File: ViewAssertions.java    From zulip-android with Apache License 2.0 5 votes vote down vote up
public static ViewAssertion checkOrderOfMessages(final ZulipActivity zulipActivity) {
    //ZulipActivity is needed for generating detailed info about position if doesn't matches
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noMatchingViewException) {
            if (!(view instanceof RecyclerView)) {
                throw noMatchingViewException;
            }
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append('{');
            RecyclerMessageAdapter recyclerMessageAdapter = (RecyclerMessageAdapter) ((RecyclerView) view).getAdapter();
            for (int i = 0; i < recyclerMessageAdapter.getItemCount() - 1; i++) {
                Object object = recyclerMessageAdapter.getItem(i);
                if (object instanceof Message) {
                    if (recyclerMessageAdapter.getItem(i + 1) instanceof Message) {
                        boolean checkOrder = (((Message) object).getID() < ((Message) recyclerMessageAdapter.getItem(i + 1)).getID());
                        assertTrue(generateDetailedInfoForOrder(((Message) object), ((Message) recyclerMessageAdapter.getItem(i + 1)), zulipActivity, i), checkOrder);
                    }
                    stringBuilder.append(((Message) object).getID() + ",");
                } else if (object instanceof MessageHeaderParent) {
                    stringBuilder.append("} | { ");
                }
            }
            stringBuilder.append('}');
            printLogInPartsIfExceeded(stringBuilder, "checkOrderOfMessages");
        }
    };
}
 
Example #15
Source File: ViewAssertions.java    From zulip-android with Apache License 2.0 5 votes vote down vote up
public static ViewAssertion checkIfBelongToSameNarrow(final ZulipActivity zulipActivity) {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noMatchingViewException) {
            if (!(view instanceof RecyclerView)) {
                throw noMatchingViewException;
            }
            RecyclerMessageAdapter recyclerMessageAdapter = (RecyclerMessageAdapter) ((RecyclerView) view).getAdapter();
            String lastHolderId = null;
            int headerParentsCount = 0;
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < recyclerMessageAdapter.getItemCount() - 1; i++) {
                Object object = recyclerMessageAdapter.getItem(i);
                if (object instanceof MessageHeaderParent) {
                    headerParentsCount++;
                    assertTrue(generateDetailInfoSameNarrow((MessageHeaderParent) object, i, zulipActivity, lastHolderId), headerParentsCount <= 1);
                    lastHolderId = ((MessageHeaderParent) object).getId();
                    stringBuilder.append(lastHolderId + " { ");
                } else if (object instanceof Message) {
                    boolean checkId = ((Message) object).getIdForHolder().equals(lastHolderId);
                    assertTrue(generateDetailInfoSameNarrow(((Message) object), zulipActivity, lastHolderId, i), checkId);
                    stringBuilder.append(((Message) object).getIdForHolder() + " , ");
                }
            }
            stringBuilder.append(" }");
            printLogInPartsIfExceeded(stringBuilder, "checkIfBelongToSameNarrow");
        }
    };
}
 
Example #16
Source File: CameraViewTest.java    From cameraview with Apache License 2.0 5 votes vote down vote up
@Test
public void testFlash() {
    onView(withId(R.id.camera))
            .check(new ViewAssertion() {
                @Override
                public void check(View view, NoMatchingViewException noViewFoundException) {
                    CameraView cameraView = (CameraView) view;
                    assertThat(cameraView.getFlash(), is(CameraView.FLASH_AUTO));
                    cameraView.setFlash(CameraView.FLASH_TORCH);
                    assertThat(cameraView.getFlash(), is(CameraView.FLASH_TORCH));
                }
            });
}
 
Example #17
Source File: CameraViewTest.java    From cameraview with Apache License 2.0 5 votes vote down vote up
@Test
public void testFacing() {
    onView(withId(R.id.camera))
            .check(new ViewAssertion() {
                @Override
                public void check(View view, NoMatchingViewException noViewFoundException) {
                    CameraView cameraView = (CameraView) view;
                    assertThat(cameraView.getFacing(), is(CameraView.FACING_BACK));
                    cameraView.setFacing(CameraView.FACING_FRONT);
                    assertThat(cameraView.getFacing(), is(CameraView.FACING_FRONT));
                }
            })
            .perform(waitFor(1000))
            .check(showingPreview());
}
 
Example #18
Source File: EspressoTools.java    From android-step-by-step with Apache License 2.0 5 votes vote down vote up
public static ViewAssertion hasItemsCount(final int count) {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException e) {
            if (!(view instanceof RecyclerView)) {
                throw e;
            }
            RecyclerView rv = (RecyclerView) view;
            if (rv.getAdapter() == null && count == 0) {
                return;
            }
            Truth.assertThat(rv.getAdapter().getItemCount()).isEqualTo(count);
        }
    };
}
 
Example #19
Source File: RecyclerSortedViewAssertion.java    From Game-of-Thrones with Apache License 2.0 5 votes vote down vote up
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
  StringDescription description = new StringDescription();
  RecyclerView recyclerView = (RecyclerView) view;
  sortedList = withAdapter.itemsToSort(recyclerView);

  checkIsNotEmpty(view, description);

  description.appendText("The list " + sortedList + " is not sorted");
  assertTrue(description.toString(), Ordering.natural().<T>isOrdered(sortedList));
}
 
Example #20
Source File: LayoutManagerTypeAssertion.java    From espresso-macchiato with MIT License 5 votes vote down vote up
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
    if (noViewFoundException != null) {
        throw noViewFoundException;
    }

    RecyclerView recyclerView = (RecyclerView) view;
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManagerClass != layoutManager.getClass()) {
        String errorMessage = "expected " + layoutManagerClass.getSimpleName()
                + " but was " + layoutManager.getClass().getSimpleName();
        throw new AssertionError(errorMessage);
    }
}
 
Example #21
Source File: EspressoTools.java    From android-step-by-step with Apache License 2.0 5 votes vote down vote up
public static ViewAssertion hasHolderItemAtPosition(final int index,
                                                    final Matcher<RecyclerView.ViewHolder> viewHolderMatcher) {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException e) {
            if (!(view instanceof RecyclerView)) {
                throw e;
            }
            RecyclerView rv = (RecyclerView) view;
            Assert.assertThat(rv.findViewHolderForAdapterPosition(index), viewHolderMatcher);
        }
    };
}
 
Example #22
Source File: CameraViewTest.java    From cameraview with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetup() {
    onView(withId(R.id.camera))
            .check(matches(isDisplayed()));
    try {
        onView(withId(R.id.texture_view))
                .check(matches(isDisplayed()));
    } catch (NoMatchingViewException e) {
        onView(withId(R.id.surface_view))
                .check(matches(isDisplayed()));
    }
}
 
Example #23
Source File: RecyclerViewItemCountAssertion.java    From incubator-taverna-mobile with Apache License 2.0 5 votes vote down vote up
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
    if (noViewFoundException != null) {
        throw noViewFoundException;
    }

    RecyclerView recyclerView = (RecyclerView) view;
    RecyclerView.Adapter adapter = recyclerView.getAdapter();
    ViewMatchers.assertThat(adapter.getItemCount(), equalTo(5));
}
 
Example #24
Source File: SetupFlowTest.java    From particle-android with Apache License 2.0 5 votes vote down vote up
@Test
    public void testSetupFlow() {
        //create/mock photon device SSID
        String ssid = (InstrumentationRegistry.getInstrumentation().getTargetContext()
                .getApplicationContext().getString(R.string.network_name_prefix) + "-") + "TestSSID";
        //mock scan results object to fake photon device SSID as scan result
        mockDeviceDiscoveryResult(ssid);
        //fake scan wifi screen results by creating mock wifi scan result
        CommandClient commandClient = mock(CommandClient.class);
        when(commandClientFactory.newClientUsingDefaultsForDevices(any(WifiFacade.class), any(SSID.class))).thenReturn(commandClient);
        String wifiSSID = "fakeWifiToConnectTo";
        mockWifiResult(wifiSSID, commandClient);
        //fake configuration steps
        mockSetupSteps();
        mockConfigureApStep(commandClient);
        mockConnectApStep(commandClient);
        //launch test activity
        activityRule.launchActivity(null);
        //launch setup process
        ParticleDeviceSetupLibrary.startDeviceSetup(activityRule.getActivity(), MainActivity.class);
        try {
            setupFlow(ssid, wifiSSID);
        } catch (NoMatchingViewException e) {
//            loginFlow(ssid, wifiSSID);
            loginFlow();
        }
    }
 
Example #25
Source File: EspViewTest.java    From espresso-macchiato with MIT License 5 votes vote down vote up
@Test
public void testClickFailureWhenNotVisible() {
    exception.expect(NoMatchingViewException.class);
    exception.expectMessage("No views in hierarchy found matching: (with id: android:id/button1 and is displayed on the screen to the user)");

    givenClickableView();
    givenViewIsInvisible();
    espView.click();
}
 
Example #26
Source File: EspNavigationMenuItemTest.java    From espresso-macchiato with MIT License 5 votes vote down vote up
@Test
public void testClickFailureWhenInvisible() {
    exception.expect(NoMatchingViewException.class);
    exception.expectMessage("No views in hierarchy found matching: ((an instance of android.support.design.internal.NavigationMenuItemView and has child: with text: is \"standard navigation item\" and is displayed on the screen to the user) and is displayed on the screen to the user)");

    espNavigationMenuItemStandard.click();
}
 
Example #27
Source File: EspRecyclerViewItemTest.java    From espresso-macchiato with MIT License 5 votes vote down vote up
@Test
public void testMatcherFailureWhenRecyclerViewNotExist() {
    getActivity().startActivity(new Intent(getActivity(), BaseActivity.class));

    exception.expect(NoMatchingViewException.class);
    exception.expectMessage("No views in hierarchy found matching: (with id: de.nenick.espressomacchiato.test:id/list and Adapter has minimal <1> items (to access requested index <0>)");

    itemInitialDisplayed.scrollTo();
}
 
Example #28
Source File: SetupFlowTest.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
@Test
    public void testSetupFlow() {
        //create/mock photon device SSID
        String ssid = (InstrumentationRegistry.getInstrumentation().getTargetContext()
                .getApplicationContext().getString(R.string.network_name_prefix) + "-") + "TestSSID";
        //mock scan results object to fake photon device SSID as scan result
        mockDeviceDiscoveryResult(ssid);
        //fake scan wifi screen results by creating mock wifi scan result
        CommandClient commandClient = mock(CommandClient.class);
        when(commandClientFactory.newClientUsingDefaultsForDevices(any(WifiFacade.class), any(SSID.class))).thenReturn(commandClient);
        String wifiSSID = "fakeWifiToConnectTo";
        mockWifiResult(wifiSSID, commandClient);
        //fake configuration steps
        mockSetupSteps();
        mockConfigureApStep(commandClient);
        mockConnectApStep(commandClient);
        //launch test activity
        activityRule.launchActivity(null);
        //launch setup process
        ParticleDeviceSetupLibrary.startDeviceSetup(activityRule.getActivity(), MainActivity.class);
        try {
            setupFlow(ssid, wifiSSID);
        } catch (NoMatchingViewException e) {
//            loginFlow(ssid, wifiSSID);
            loginFlow();
        }
    }
 
Example #29
Source File: OrientationAssertion.java    From espresso-macchiato with MIT License 5 votes vote down vote up
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
    if (noViewFoundException != null) {
        throw noViewFoundException;
    }

    int currentOrientation = currentOrientation();
    if (currentOrientation != expectedOrientation) {
        String errorMessage = "expected device orientation "
                + orientationAsString(expectedOrientation)
                + " but was " + orientationAsString(currentOrientation);
        throw new AssertionError(errorMessage);
    }
}
 
Example #30
Source File: RecyclerViewItemCountAssertion.java    From espresso-macchiato with MIT License 5 votes vote down vote up
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
    if (noViewFoundException != null) {
        throw noViewFoundException;
    }

    RecyclerView recyclerView = (RecyclerView) view;
    RecyclerView.Adapter adapter = recyclerView.getAdapter();
    assertThat(adapter.getItemCount(), is(expectedCount));
}