Java Code Examples for android.support.test.espresso.ViewAssertion

The following are top voted examples for showing how to use android.support.test.espresso.ViewAssertion. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: ConnectbotMatchers.java   View source code 6 votes vote down vote up
@NonNull
public static ViewAssertion hasHolderItem(final Matcher<RecyclerView.ViewHolder> viewHolderMatcher) {
	return new ViewAssertion() {
		@Override public void check(View view, NoMatchingViewException e) {
			if (!(view instanceof RecyclerView)) {
				throw e;
			}

			boolean hasMatch = false;
			RecyclerView rv = (RecyclerView) view;
			for (int i = 0; i < rv.getChildCount(); i++) {
				RecyclerView.ViewHolder vh = rv.findViewHolderForAdapterPosition(i);
				hasMatch |= viewHolderMatcher.matches(vh);
			}
			Assert.assertTrue(hasMatch);
		}
	};
}
 
Example 2
Project: PXLSRT   File: CameraViewTest.java   View source code 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 3
Project: PXLSRT   File: CameraViewTest.java   View source code 6 votes vote down vote up
private static ViewAssertion showingPreview() {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if (android.os.Build.VERSION.SDK_INT < 14) {
                return;
            }
            CameraView cameraView = (CameraView) view;
            TextureView 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 4
Project: polling-station-app   File: TestElectionChoice.java   View source code 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 5
Project: polling-station-app   File: TestElectionChoice.java   View source code 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 6
Project: ZeroKit-Android-SDK   File: SampleAppTest.java   View source code 6 votes vote down vote up
private String encrypt(String text) throws InterruptedException {
    final String[] result = new String[1];

    onView(withId(R.id.editText4)).perform(scrollTo(), replaceText(text), closeSoftKeyboard());
    onView(allOf(withId(R.id.button2), withText("Encrypt"))).perform(scrollTo(), click());
    onView(withId(R.id.editText5)).check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            result[0] = String.valueOf(((EditText) view).getText());
        }
    });
    onView(allOf(withId(R.id.button3), withText("Test Decrypt"))).perform(scrollTo(), click());
    onView(withId(R.id.textView5)).check(matches(withText(text)));
    onView(allOf(withId(R.id.button4), withText("Copy"))).perform(scrollTo(), click());

    return result[0];
}
 
Example 7
Project: ZeroKit-Android-Sample   File: SampleAppTest.java   View source code 6 votes vote down vote up
private String encrypt(String text) throws InterruptedException {
    final String[] result = new String[1];

    onView(withId(R.id.editText4)).perform(scrollTo(), replaceText(text), closeSoftKeyboard());
    onView(allOf(withId(R.id.button2), withText("Encrypt"))).perform(scrollTo(), click());
    onView(withId(R.id.editText5)).check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            result[0] = String.valueOf(((EditText) view).getText());
        }
    });
    onView(allOf(withId(R.id.button3), withText("Test Decrypt"))).perform(scrollTo(), click());
    onView(withId(R.id.textView5)).check(matches(withText(text)));
    onView(allOf(withId(R.id.button4), withText("Copy"))).perform(scrollTo(), click());

    return result[0];
}
 
Example 8
Project: espresso-macchiato   File: EspRecyclerViewItem.java   View source code 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 9
Project: SimpleCamera   File: CameraViewTest.java   View source code 6 votes vote down vote up
@Test
public void testAutoFocus() {
    onView(withId(com.google.android.cameraview.test.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
Project: SimpleCamera   File: CameraViewTest.java   View source code 6 votes vote down vote up
private static ViewAssertion showingPreview() {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if (android.os.Build.VERSION.SDK_INT < 14) {
                return;
            }
            CameraView cameraView = (CameraView) view;
            TextureView textureView = (TextureView) cameraView.findViewById(com.google.android.cameraview.test.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 11
Project: material-components-android   File: BottomSheetBehaviorTouchTest.java   View source code 6 votes vote down vote up
@Test
public void testTouchCoordinatorLayout() {
  final CoordinatorLayoutActivity activity = activityTestRule.getActivity();
  down = false;
  Espresso.onView(sameInstance((View) activity.mCoordinatorLayout))
      .perform(ViewActions.click()) // Click outside the bottom sheet
      .check(
          new ViewAssertion() {
            @Override
            public void check(View view, NoMatchingViewException e) {
              assertThat(e, is(nullValue()));
              assertThat(view, is(notNullValue()));
              // Check that the touch event fell through to the container
              assertThat(down, is(true));
            }
          });
}
 
Example 12
Project: DebugRank   File: Util.java   View source code 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 13
Project: cameraview   File: CameraViewTest.java   View source code 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 14
Project: cameraview   File: CameraViewTest.java   View source code 6 votes vote down vote up
private static ViewAssertion showingPreview() {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if (android.os.Build.VERSION.SDK_INT < 14) {
                return;
            }
            CameraView cameraView = (CameraView) view;
            TextureView 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 15
Project: zulip-android   File: ViewAssertions.java   View source code 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 16
Project: android-step-by-step   File: EspressoTools.java   View source code 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 17
Project: android-step-by-step   File: EspressoTools.java   View source code 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 18
Project: Bill-Calculator   File: RecyclerViewInteraction.java   View source code 6 votes vote down vote up
public RecyclerViewInteraction checkView(final @IdRes int id, final ViewAssertion itemViewAssertion) {
    viewInteraction.check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException ex) {
            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.findViewById(id);
                itemViewAssertion.check(viewAtPosition, ex);
            }
        }
    });
    return this;
}
 
Example 19
Project: android-training-2017   File: CalculatorAndroidTest.java   View source code 5 votes vote down vote up
@Test
public void testActivityRun() {
    calculatorActivity.launchActivity(new Intent());

    ViewInteraction calculateButton = onView(withId(R.id.calculate_button));
    calculateButton.check(matches(isDisplayed()));
    calculateButton.check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if(view.isEnabled()) {
                throw new IllegalStateException("button enabled");
            }
        }
    });

    onView(withId(R.id.input_field_edit_text)).perform(typeText("1+2"));

    calculateButton.check(matches(isEnabled()));

    calculateButton.perform(click());

    /*onView(withId(R.id.result_text_view)).check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            if(!((TextView)view).getText().toString().equals("3")) {
                throw new IllegalStateException("result wrong. Aspected 3");
            }
        }
    });*/

}
 
Example 20
Project: PXLSRT   File: CameraViewTest.java   View source code 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 21
Project: PXLSRT   File: CameraViewTest.java   View source code 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 22
Project: polling-station-app   File: TestElectionChoice.java   View source code 5 votes vote down vote up
@Test
public void atElectionActivity() throws Exception {
    onView(withId(R.id.app_bar)).check(new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            assertEquals(((Toolbar) view).getTitle(), "Choose election");
        }
    });
}
 
Example 23
Project: NumberPadTimePicker   File: NumberPadTimePickerDialogTest.java   View source code 5 votes vote down vote up
/**
 * @param enabled Whether the view should be matched to be enabled or not.
 * @return A {@link ViewAssertion} that asserts that a view should be matched
 *         to be enabled or disabled.
 */
private static ViewAssertion matchesIsEnabled(boolean enabled) {
    // TODO: When we're comfortable with the APIs, we can statically import them and
    // make direct calls to these methods and cut down on the verbosity, instead of
    // writing helper methods that wrap these APIs.
    return ViewAssertions.matches(enabled ? ViewMatchers.isEnabled() : Matchers.not(ViewMatchers.isEnabled()));
}
 
Example 24
Project: Android-Infrastructure   File: RecyclerViewAssertions.java   View source code 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;
      assertThat(rv.getAdapter(), notNullValue());
      assertThat(rv.getAdapter().getItemCount(), equalTo(count));
    }
  };
}
 
Example 25
Project: espresso-macchiato   File: AppBarLayoutAssertion.java   View source code 5 votes vote down vote up
public static ViewAssertion assertIsExpanded() {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            AppBarLayout appBarLayout = (AppBarLayout) view;
            boolean isFullExpanded = appBarLayout.getHeight() - appBarLayout.getBottom() == 0;
            ViewMatchers.assertThat("is full expanded", isFullExpanded, is(true));
        }
    };
}
 
Example 26
Project: espresso-macchiato   File: AppBarLayoutAssertion.java   View source code 5 votes vote down vote up
public static ViewAssertion assertIsCollapsed() {
    return new ViewAssertion() {
        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            CollapsingToolbarLayout collapsingToolbarLayout = null;
            Toolbar toolbar = null;
            AppBarLayout appBarLayout = (AppBarLayout) view;

            for (int i = 0; i < appBarLayout.getChildCount(); i++) {
                if(appBarLayout.getChildAt(i) instanceof CollapsingToolbarLayout) {
                    collapsingToolbarLayout = (CollapsingToolbarLayout) appBarLayout.getChildAt(i);
                }
            }

            if(collapsingToolbarLayout == null) {
                throw new IllegalStateException("Current only AppBarLayouts with CollapsingToolbarLayout are supported.");
            }

            for (int i = 0; i < collapsingToolbarLayout.getChildCount(); i++) {
                if(collapsingToolbarLayout.getChildAt(i) instanceof Toolbar) {
                    toolbar = (Toolbar) collapsingToolbarLayout.getChildAt(i);
                }
            }

            if(toolbar == null) {
                throw new IllegalStateException("Current only CollapsingToolbarLayout with support Toolbar are supported.");
            }

            boolean isFullCollapsed = appBarLayout.getBottom() - toolbar.getHeight() == 0;
            isFullCollapsed |= appBarLayout.getBottom() - toolbar.getHeight() - EspResourceTool.getStatusBarHeight(view.getContext()) == 0;
            ViewMatchers.assertThat("is full collapsed", isFullCollapsed, is(true));
        }
    };
}
 
Example 27
Project: SimpleCamera   File: CameraViewTest.java   View source code 5 votes vote down vote up
@Test
public void testFacing() {
    onView(withId(com.google.android.cameraview.test.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 28
Project: SimpleCamera   File: CameraViewTest.java   View source code 5 votes vote down vote up
@Test
public void testFlash() {
    onView(withId(com.google.android.cameraview.test.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 29
Project: Expander   File: TestUtils.java   View source code 5 votes vote down vote up
public static ViewAssertion isGone() {
    return new ViewAssertion() {
        public void check(View view, NoMatchingViewException noView) {
            assertThat(view, new VisibilityMatcher(View.GONE));
        }
    };
}
 
Example 30
Project: Expander   File: TestUtils.java   View source code 5 votes vote down vote up
public static ViewAssertion isInvisible() {
    return new ViewAssertion() {
        public void check(View view, NoMatchingViewException noView) {
            assertThat(view, new VisibilityMatcher(View.INVISIBLE));
        }
    };
}
 
Example 31
Project: material-components-android   File: TextInputLayoutTest.java   View source code 5 votes vote down vote up
private static ViewAssertion isHintExpanded(final boolean expanded) {
  return new ViewAssertion() {
    @Override
    public void check(View view, NoMatchingViewException noViewFoundException) {
      assertTrue(view instanceof TextInputLayout);
      assertEquals(expanded, ((TextInputLayout) view).isHintExpanded());
    }
  };
}
 
Example 32
Project: material-components-android   File: TextInputLayoutTest.java   View source code 5 votes vote down vote up
private static ViewAssertion isBoxStrokeColor(@ColorInt final int boxStrokeColor) {
  return new ViewAssertion() {
    @Override
    public void check(View view, NoMatchingViewException noViewFoundException) {
      assertTrue(view instanceof TextInputLayout);
      assertEquals(boxStrokeColor, ((TextInputLayout) view).getBoxStrokeColor());
    }
  };
}
 
Example 33
Project: material-components-android   File: TextInputLayoutTest.java   View source code 5 votes vote down vote up
private static ViewAssertion isBoxBackgroundColor(@ColorInt final int boxBackgroundColor) {
  return new ViewAssertion() {
    @Override
    public void check(View view, NoMatchingViewException noViewFoundException) {
      assertTrue(view instanceof TextInputLayout);
      assertEquals(boxBackgroundColor, ((TextInputLayout) view).getBoxBackgroundColor());
    }
  };
}
 
Example 34
Project: material-components-android   File: TextInputLayoutTest.java   View source code 5 votes vote down vote up
private static ViewAssertion isBoxCornerRadiusTopRight(final float boxCornerRadiusTopRight) {
  return new ViewAssertion() {
    @Override
    public void check(View view, NoMatchingViewException noViewFoundException) {
      assertTrue(view instanceof TextInputLayout);
      assertEquals(
          boxCornerRadiusTopRight, ((TextInputLayout) view).getBoxCornerRadiusTopRight(), 0.01);
    }
  };
}
 
Example 35
Project: material-components-android   File: TextInputLayoutTest.java   View source code 5 votes vote down vote up
private static ViewAssertion isCutoutOpen(final boolean open) {
  return new ViewAssertion() {
    @Override
    public void check(View view, NoMatchingViewException noViewFoundException) {
      assertTrue(view instanceof TextInputLayout);
      assertEquals(open, ((TextInputLayout) view).cutoutIsOpen());
    }
  };
}
 
Example 36
Project: material-components-android   File: TextInputLayoutTest.java   View source code 5 votes vote down vote up
static ViewAssertion isPasswordToggledVisible(final boolean isToggledVisible) {
  return new ViewAssertion() {
    @Override
    public void check(View view, NoMatchingViewException noViewFoundException) {
      assertTrue(view instanceof TextInputLayout);
      EditText editText = ((TextInputLayout) view).getEditText();
      TransformationMethod transformationMethod = editText.getTransformationMethod();
      if (isToggledVisible) {
        assertNull(transformationMethod);
      } else {
        assertEquals(PasswordTransformationMethod.getInstance(), transformationMethod);
      }
    }
  };
}
 
Example 37
Project: DebugRank   File: Util.java   View source code 5 votes vote down vote up
public static ViewAssertion flexGridReadOnly(final boolean expected)
{
    return new ViewAssertion()
    {
        @Override
        public void check(View view, NoMatchingViewException noViewException)
        {
            FlexGrid flexGrid = (FlexGrid) view;

            assertEquals(expected, flexGrid.isReadOnly());
        }
    };
}
 
Example 38
Project: DebugRank   File: Util.java   View source code 5 votes vote down vote up
public static ViewAssertion mockDrawable(final String expectedTag)
{
    return new ViewAssertion()
    {
        @Override
        public void check(View view, NoMatchingViewException noViewException)
        {
            String tag = (String) ((MockDrawable) ((ImageView) view).getDrawable()).getTag();

            assertEquals(expectedTag, tag);
        }
    };
}
 
Example 39
Project: DebugRank   File: Util.java   View source code 5 votes vote down vote up
public static ViewAssertion withDrawable(@DrawableRes final int expectedResourceId)
{
    return new ViewAssertion()
    {
        @Override
        public void check(View view, NoMatchingViewException noViewException)
        {
            @DrawableRes int tag = (int) ((MockDrawable) ((ImageView) view).getDrawable()).getTag();

            assertEquals(expectedResourceId, tag);
        }
    };
}
 
Example 40
Project: cameraview   File: CameraViewTest.java   View source code 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());
}