androidx.test.filters.SdkSuppress Java Examples

The following examples show how to use androidx.test.filters.SdkSuppress. 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: DrawerActionsTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Test
@SdkSuppress(minSdkVersion = 20) // b/26957451
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)));
}
 
Example #2
Source File: TransitionActivityMainTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Test
@SdkSuppress(minSdkVersion = 21)
public void testInterruptedBackDoesntExit() {
  // Set a flag in the activity to intercept the back button.
  activityScenario.onActivity(
      new ActivityAction<TransitionActivityMain>() {
        @Override
        public void perform(TransitionActivityMain activity) {
          activity.setExitOnBackPressed(false);
        }
      });
  pressBack();
  pressBack();
  pressBack();
  // Nothing should happen, activity doesn't exit.

  onView(withId(R.id.grid)).check(matches(isDisplayed()));
}
 
Example #3
Source File: ActivityTestRuleTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
@SdkSuppress(minSdkVersion = 17)
@Test
public void shouldAskInstrumentationToInterceptActivityUsingGivenFactoryAndResetItAfterTest()
    throws Throwable {
  SingleActivityFactory<ActivityFixture> singleActivityFactory =
      new SingleActivityFactory<ActivityFixture>(ActivityFixture.class) {
        @Override
        public ActivityFixture create(Intent intent) {
          return mockActivity;
        }
      };
  ActivityTestRule<ActivityFixture> activityTestRule =
      new ActivityTestRule<>(singleActivityFactory, true, false);
  MonitoringInstrumentation instrumentation = mock(MonitoringInstrumentation.class);
  when(instrumentation.getTargetContext()).thenReturn(getApplicationContext());
  activityTestRule.setInstrumentation(instrumentation);
  Statement baseStatement = mock(Statement.class);
  activityTestRule.apply(baseStatement, mock(Description.class)).evaluate();

  InOrder inOrder = Mockito.inOrder(instrumentation, baseStatement);
  inOrder.verify(instrumentation).interceptActivityUsing(singleActivityFactory);
  inOrder.verify(baseStatement).evaluate();
  inOrder.verify(instrumentation).useDefaultInterceptingActivityFactory();
}
 
Example #4
Source File: DelegatingContextTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
/**
 * Similar to test {@link #openOrCreateDatabaseWithoutHandler}, but test openOrCreateDatabase API
 * with errorHandler, which is added in API level 11.
 */
@Test
@SdkSuppress(minSdkVersion = 11)
public void openOrCreateDatabaseWithHandler() {
  assertEquals(delegatingContext.databaseList().length, 0);
  SQLiteDatabase testDatabase =
      context.openOrCreateDatabase(DUMMY_TEST_DB_NAME, MODE_PRIVATE, null, null);
  SQLiteDatabase renamedDatabase =
      delegatingContext.openOrCreateDatabase(DUMMY_TEST_DB_NAME, MODE_PRIVATE, null, null);

  assertThat(Arrays.asList(delegatingContext.databaseList()), hasItem(DUMMY_TEST_DB_NAME));
  assertIsRenamed(new File(testDatabase.getPath()), new File(renamedDatabase.getPath()));

  testDatabase.close();
  renamedDatabase.close();
}
 
Example #5
Source File: TextInputLayoutTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testDispatchProvideAutofillStructure() {
  final Activity activity = activityTestRule.getActivity();

  final TextInputLayout layout = activity.findViewById(R.id.textinput);

  final ViewStructureImpl structure = new ViewStructureImpl();
  layout.dispatchProvideAutofillStructure(structure, 0);

  assertEquals(2, structure.getChildCount()); // EditText and TextView

  // Asserts the structure.
  final ViewStructureImpl childStructure = structure.getChildAt(0);
  assertEquals(EditText.class.getName(), childStructure.getClassName());
  assertEquals("Hint to the user", childStructure.getHint().toString());

  // Make sure the widget's hint was restored.
  assertEquals("Hint to the user", layout.getHint().toString());
  final EditText editText = activity.findViewById(R.id.textinput_edittext);
  assertNull(editText.getHint());
}
 
Example #6
Source File: PermissionRequesterTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Test
@SdkSuppress(minSdkVersion = 23)
public void permissionAddsPermissionToSet() {
  RequestPermissionCallable requestPermissionCallable1 =
      withGrantPermissionCallable(RUNTIME_PERMISSION1);
  RequestPermissionCallable requestPermissionCallable2 =
      withGrantPermissionCallable(RUNTIME_PERMISSION2);
  RequestPermissionCallable requestPermissionCallable3 =
      withGrantPermissionCallable(RUNTIME_PERMISSION3);

  permissionRequester.addPermissions(RUNTIME_PERMISSION1);
  permissionRequester.addPermissions(RUNTIME_PERMISSION2);
  permissionRequester.addPermissions(RUNTIME_PERMISSION3);

  assertThat(permissionRequester.requestedPermissions, hasSize(3));
  assertThat(
      permissionRequester.requestedPermissions,
      containsInAnyOrder(
          equalTo(requestPermissionCallable1),
          equalTo(requestPermissionCallable2),
          equalTo(requestPermissionCallable3)));
}
 
Example #7
Source File: DrawerActionsTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Test
@SdkSuppress(minSdkVersion = 20) // b/26957451
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()));
}
 
Example #8
Source File: TabLayoutTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@UiThreadTest
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N)
@TargetApi(Build.VERSION_CODES.N)
public void testPointerIcon() {
  final LayoutInflater inflater = LayoutInflater.from(activityTestRule.getActivity());
  final TabLayout tabLayout = (TabLayout) inflater.inflate(R.layout.design_tabs_items, null);
  final PointerIcon expectedIcon =
      PointerIcon.getSystemIcon(activityTestRule.getActivity(), PointerIcon.TYPE_HAND);

  final int tabCount = tabLayout.getTabCount();
  assertEquals(3, tabCount);

  final MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_HOVER_MOVE, 0, 0, 0);
  for (int i = 0; i < tabCount; i++) {
    assertEquals(expectedIcon, tabLayout.getTabAt(i).view.onResolvePointerIcon(event, 0));
  }
}
 
Example #9
Source File: BottomNavigationViewTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@UiThreadTest
@Test
@SmallTest
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N)
@TargetApi(Build.VERSION_CODES.N)
public void testPointerIcon() throws Throwable {
  final Activity activity = activityTestRule.getActivity();
  final PointerIcon expectedIcon = PointerIcon.getSystemIcon(activity, PointerIcon.TYPE_HAND);
  final MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_HOVER_MOVE, 0, 0, 0);
  final Menu menu = bottomNavigation.getMenu();
  for (int i = 0; i < menu.size(); i++) {
    final MenuItem item = menu.getItem(i);
    assertTrue(item.isEnabled());
    final View itemView = activity.findViewById(item.getItemId());
    assertEquals(expectedIcon, itemView.onResolvePointerIcon(event, 0));
    item.setEnabled(false);
    assertEquals(null, itemView.onResolvePointerIcon(event, 0));
    item.setEnabled(true);
    assertEquals(expectedIcon, itemView.onResolvePointerIcon(event, 0));
  }
}
 
Example #10
Source File: ShowImeWithHardKeyboardHelperTest.java    From test-butler with Apache License 2.0 6 votes vote down vote up
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.LOLLIPOP_MR1)
@Test
public void keyboardDoesShow() {
    TestButler.setShowImeWithHardKeyboardState(true);
    EditText editText = (EditText) testRule.getActivity().findViewById(R.id.editText);

    int before[] = new int[2];
    editText.getLocationOnScreen(before);

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

    int after[] = new int[2];
    editText.getLocationOnScreen(after);

    // Only check that the y position changed
    assertNotEquals(before[1], after[1]);
}
 
Example #11
Source File: ShowImeWithHardKeyboardHelperTest.java    From test-butler with Apache License 2.0 6 votes vote down vote up
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.LOLLIPOP_MR1)
@Test
public void keyboardDoesNotShow() {
    TestButler.setShowImeWithHardKeyboardState(false);
    EditText editText = (EditText) testRule.getActivity().findViewById(R.id.editText);

    int before[] = new int[2];
    editText.getLocationOnScreen(before);

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

    int after[] = new int[2];
    editText.getLocationOnScreen(after);

    // Check that the position has not changed at all
    assertEquals(before[0], after[0]);
    assertEquals(before[1], after[1]);
}
 
Example #12
Source File: RuntimePermissionsIntegrationTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Test
@SdkSuppress(minSdkVersion = 24)
public void verifyEssentialRuntimePermissionsAreGranted() {
  assertThat(
      getInstrumentation()
          .getContext()
          .getPackageManager()
          .checkPermission(permission.READ_EXTERNAL_STORAGE, ORCHESTRATOR_PACKAGE),
      equalTo(PackageManager.PERMISSION_GRANTED));
  assertThat(
      getInstrumentation()
          .getContext()
          .getPackageManager()
          .checkPermission(permission.WRITE_EXTERNAL_STORAGE, ORCHESTRATOR_PACKAGE),
      equalTo(PackageManager.PERMISSION_GRANTED));
}
 
Example #13
Source File: ViewMatchersTest.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Test
@SdkSuppress(minSdkVersion = 11)
public void withAlphaTest() {
  View view = new TextView(context);

  view.setAlpha(0f);
  assertTrue(withAlpha(0f).matches(view));
  assertFalse(withAlpha(0.01f).matches(view));
  assertFalse(withAlpha(0.99f).matches(view));
  assertFalse(withAlpha(1f).matches(view));

  view.setAlpha(0.01f);
  assertFalse(withAlpha(0f).matches(view));
  assertTrue(withAlpha(0.01f).matches(view));
  assertFalse(withAlpha(0.99f).matches(view));
  assertFalse(withAlpha(1f).matches(view));

  view.setAlpha(1f);
  assertFalse(withAlpha(0f).matches(view));
  assertFalse(withAlpha(0.01f).matches(view));
  assertFalse(withAlpha(0.99f).matches(view));
  assertTrue(withAlpha(1f).matches(view));
}
 
Example #14
Source File: FileUtilitiesTest.java    From google-authenticator-android with Apache License 2.0 6 votes vote down vote up
@Test
@SdkSuppress(maxSdkVersion = KITKAT)
public void testGetStat_withActualDirectory() throws Exception {
  File dir = createTempDirInCacheDir();
  try {
    String path = dir.getPath();
    setFilePermissions(path, 0755);
    FileUtilities.StatStruct s1 = FileUtilities.getStat(path);
    assertThat(s1.mode & 0777).isEqualTo(0755);
    long ctime1 = s1.ctime;
    assertThat(s1.toString()).contains(Long.toString(ctime1));
    
    setFilePermissions(path, 0700);
    FileUtilities.StatStruct s2 = FileUtilities.getStat(path);
    assertThat(s2.mode & 0777).isEqualTo(0700);
    long ctime2 = s2.ctime;
    assertThat(ctime2 >= ctime1).isTrue();
  } finally {
    dir.delete();
  }
}
 
Example #15
Source File: WindowOrderingIntegrationTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@SdkSuppress(minSdkVersion = 11)
@Test
public void popupMenuTesting() {
  onView(withText(R.string.item_1_text)).check(doesNotExist());
  onView(withId(R.id.make_popup_menu_button)).perform(scrollTo(), click());
  onView(withText(R.string.item_1_text)).check(matches(isDisplayed())).perform(click());
  onView(withText(R.string.item_1_text)).check(doesNotExist());
}
 
Example #16
Source File: EventActionIntegrationTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@SdkSuppress(minSdkVersion = 15)
@Test
public void doubleClickTesting() {
  onView(withText(is(activity.getString(R.string.text_double_click))))
      .check(matches(not(ViewMatchers.isDisplayed())));
  onView(withId(is(R.id.gesture_area))).perform(doubleClick());
  onView(withId(is(R.id.text_double_click))).check(matches(isDisplayed()));
  onView(withText(is("Double Click"))).check(matches(isDisplayed()));
  onView(withText(is(activity.getString(R.string.text_double_click))))
      .check(matches(isDisplayed()));
}
 
Example #17
Source File: ChromeCustomTabsTest.java    From browser-switch-android with MIT License 5 votes vote down vote up
@Test
@SdkSuppress(maxSdkVersion = 23)
public void isAvailable_whenCustomTabsAreNotSupported_returnsFalse() {
    scenario.onFragment(fragment -> {
        FragmentActivity activity = fragment.getActivity();
        assertFalse(ChromeCustomTabs.isAvailable(activity.getApplication()));
    });
}
 
Example #18
Source File: ClickActionIntegrationTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@SdkSuppress(minSdkVersion = 14)
@Test
public void rightClickTest() {
  onView(withId(R.id.large_view))
      .perform(click(InputDevice.SOURCE_MOUSE, MotionEvent.BUTTON_SECONDARY));
  onView(withText(R.string.context_item_1_text)).check(matches(isDisplayed()));
  onView(withText(R.string.context_item_2_text)).check(matches(isDisplayed()));
  onView(withText(R.string.context_item_3_text)).check(matches(isDisplayed()));
}
 
Example #19
Source File: ClickActionIntegrationTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Test
@SdkSuppress(maxSdkVersion = 13)
public void rightClickTest_unsupportedApiLevel() {
  boolean exceptionThrown = false;
  try {
    onView(withId(R.id.large_view)).perform(click(0, 0));
  } catch (UnsupportedOperationException e) {
    exceptionThrown = true;
  } finally {
    assertTrue(exceptionThrown);
  }
}
 
Example #20
Source File: EventActionIntegrationTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@SdkSuppress(minSdkVersion = 15)
@Test
public void longClickTesting() {
  onView(withText(is(activity.getString(R.string.text_long_click))))
      .check(matches(not(isDisplayed())));
  onView(withId(is(R.id.gesture_area))).perform(longClick());
  onView(withId(is(R.id.text_long_click))).check(matches(isDisplayed()));
  onView(withText(is(activity.getString(R.string.text_long_click))))
      .check(matches(isDisplayed()));
}
 
Example #21
Source File: TestRequestBuilder.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean evaluateTest(Description description) {
  final SdkSuppress sdkSuppress = getAnnotationForTest(description);
  if (sdkSuppress != null) {
    if ((getDeviceSdkInt() >= sdkSuppress.minSdkVersion()
            && getDeviceSdkInt() <= sdkSuppress.maxSdkVersion())
        || getDeviceCodeName().equals(sdkSuppress.codeName())) {
      return true; // run the test
    }
    return false; // don't run the test
  }
  return true; // no SdkSuppress, run the test
}
 
Example #22
Source File: TestRequestBuilder.java    From android-test with Apache License 2.0 5 votes vote down vote up
private SdkSuppress getAnnotationForTest(Description description) {
  final SdkSuppress s = description.getAnnotation(SdkSuppress.class);
  if (s != null) {
    return s;
  }
  final Class<?> testClass = description.getTestClass();
  if (testClass != null) {
    return testClass.getAnnotation(SdkSuppress.class);
  }
  return null;
}
 
Example #23
Source File: PermissionRequesterTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Test
@SdkSuppress(minSdkVersion = 23)
public void requestPermission_SuccessInGrantingPermissionRunsTest() throws Throwable {
  RequestPermissionCallable stubbedCallable = withStubbedCallable(Result.SUCCESS);

  permissionRequester.requestPermissions();

  verify(stubbedCallable).call();
}
 
Example #24
Source File: PermissionRequesterTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Test
@SdkSuppress(minSdkVersion = 23)
public void failureInGrantingPermissionFailsTest() throws Throwable {
  expected.expect(AssertionError.class);

  RequestPermissionCallable stubbedCallable = withStubbedCallable(Result.FAILURE);

  permissionRequester.requestPermissions();

  verify(stubbedCallable).call();
}
 
Example #25
Source File: PermissionRequesterTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Test
@SdkSuppress(minSdkVersion = 23)
public void callableThrowsExceptionFailsTest() throws Throwable {
  expected.expect(AssertionError.class);

  RequestPermissionCallable stubbedCallable = withStubbedCallable(Result.FAILURE);
  when(stubbedCallable.call()).thenThrow(Exception.class);

  permissionRequester.requestPermissions();

  verify(stubbedCallable).call();
}
 
Example #26
Source File: UiAutomationShellCommandTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Test
@SdkSuppress(minSdkVersion = 23)
public void commandForPermission() {
  assertTrue(true);
  UiAutomationShellCommand shellCmdGrant =
      new UiAutomationShellCommand(
          TARGET_PACKAGE, RUNTIME_PERMISSION1, PmCommand.GRANT_PERMISSION);

  String expectedCmdGrant = "pm grant " + TARGET_PACKAGE + " " + RUNTIME_PERMISSION1;
  assertThat(shellCmdGrant.commandForPermission(), equalTo(expectedCmdGrant));
}
 
Example #27
Source File: ActivityScenarioTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Test
@SdkSuppress(minSdkVersion = 16) // ActivityOptions is added in API 16.
public void launch_withActivityOptionsBundle() throws Exception {
  try (ActivityScenario<RecreationRecordingActivity> scenario =
      ActivityScenario.launch(
          RecreationRecordingActivity.class,
          ActivityOptions.makeCustomAnimation(ApplicationProvider.getApplicationContext(), 0, 0)
              .toBundle())) {
    assertThat(scenario.getState()).isEqualTo(State.RESUMED);
  }
}
 
Example #28
Source File: BindFontFailureTest.java    From butterknife with Apache License 2.0 5 votes vote down vote up
@SdkSuppress(minSdkVersion = 24) // AndroidX problems on earlier versions
@Test public void styleMustBeValid() {
  TargetStyle target = new TargetStyle();

  try {
    ButterKnife.bind(target, tree);
    fail();
  } catch (IllegalStateException e) {
    assertThat(e).hasMessageThat()
        .isEqualTo("@BindFont style must be NORMAL, BOLD, ITALIC, or BOLD_ITALIC. "
            + "(com.example.butterknife.functional.BindFontFailureTest$TargetStyle.actual)");
  }
}
 
Example #29
Source File: HasBackgroundMatcherTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Test
@SdkSuppress(minSdkVersion = 16)
public void verifyBackgroundWhenBackgroundIsNotSet() {
  View view = new View(context);
  view.setBackground(null);
  int drawable1 = androidx.test.ui.app.R.drawable.drawable_1;

  assertFalse(new HasBackgroundMatcher(drawable1).matches(view));
}
 
Example #30
Source File: ChromeCustomTabsTest.java    From browser-switch-android with MIT License 5 votes vote down vote up
@Test
@SdkSuppress(minSdkVersion = 24)
public void isAvailable_whenCustomTabsAreSupported_returnsTrue() {
    scenario.onFragment(fragment -> {
        FragmentActivity activity = fragment.getActivity();
        assertTrue(ChromeCustomTabs.isAvailable(activity.getApplication()));
    });
}