Java Code Examples for android.support.test.filters.MediumTest

The following are top voted examples for showing how to use android.support.test.filters.MediumTest. 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: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 7 votes vote down vote up
@Test
@MediumTest
public void testSwipeDownToHide() {
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              ViewActions.swipeDown(), ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(not(ViewMatchers.isDisplayed())));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_HIDDEN));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 2
Project: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 7 votes vote down vote up
@Test
@MediumTest
public void testSwipeUpToExpand() {
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  new CoordinatesProvider() {
                    @Override
                    public float[] calculateCoordinates(View view) {
                      return new float[] {view.getWidth() / 2, 0};
                    }
                  },
                  Press.FINGER),
              ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 3
Project: furry-sniffle   File: ViewEntertainmentTest2.java   Source Code and License 6 votes vote down vote up
@Test
@MediumTest
public void ViewTest3() throws InterruptedException{
    rule2.getActivity();
    Thread.sleep(15000);
    onView(isRoot()).perform(swipeUp());
    Thread.sleep(2000);
    String name = "Low Cost";
    for(int i=0; i<3;i++){
        if(i==1){ name = "Medium Cost"; }
        if(i==2){ name = "High Cost"; }
        onView(withId(R.id.averageCostSpinner)).perform(click());
        onData(allOf(is(instanceOf(String.class)), is(name))).perform(click());
        onView(withId(R.id.averageCostSpinner)).check(matches(withSpinnerText(containsString(name))));
    }
}
 
Example 4
Project: furry-sniffle   File: SumTest.java   Source Code and License 6 votes vote down vote up
@Test
  @MediumTest
  public void summarize() throws Exception {
      Sum sum = new Sum();
      assertEquals(sum.summarize("A wiki is run using wiki software, otherwise known as a wiki engine. " +
                      "A wiki engine is a type of content management system, but it differs from most other such systems, including blog software, " +
                      "in that the content is created without any defined owner or leader, and wikis have little implicit structure, " +
                      "allowing structure to emerge according to the needs of the users.[2] There are dozens of different wiki engines in use, " +
                      "both standalone and part of other software, such as bug tracking systems. Some wiki engines are open source, " +
                      "whereas others are proprietary. Some permit control over different functions (levels of access); for example, " +
                      "editing rights may permit changing, adding or removing material. Others may permit access without enforcing access control. " +
                      "Other rules may be imposed to organize content." +
              "The online encyclopedia project Wikipedia is by far the most popular wiki-based website, " +
                      "and is one of the most widely viewed sites of any kind in the world, having been ranked in the top ten since 2007.[3] " +
                      "Wikipedia is not a single wiki but rather a collection of hundreds of wikis, one for each language. " +
                      "There are tens of thousands of other wikis in use, both public and private, including wikis functioning as knowledge management resources, " +
                      "notetaking tools, community websites and intranets. The English-language Wikipedia has the largest collection of articles; as of September 2016, " +
                      "it had over five million articles. Ward Cunningham, the developer of the first wiki software")
," A wiki is run using wiki software, otherwise known as a wiki engine.  " +
                      "A wiki engine is a type of content management system, but it differs from most other such systems, " +
                      "including blog software, in that the content is created without any defined owner or leader, and wikis have little implicit structure, " +
                      "allowing structure to emerge according to the needs of the users. [2] There are dozens of different wiki engines in use, " +
                      "both standalone and part of other software, such as bug tracking systems." );

  }
 
Example 5
Project: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 6 votes vote down vote up
@Test
@MediumTest
public void testAutoPeekHeight() throws Throwable {
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          getBehavior().setPeekHeight(BottomSheetBehavior.PEEK_HEIGHT_AUTO);
        }
      });
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          CoordinatorLayout col = getCoordinatorLayout();
          assertThat(
              getBottomSheet().getTop(),
              is(
                  Math.min(
                      col.getWidth() * 9 / 16,
                      col.getHeight() - getBehavior().getPeekHeightMin())));
        }
      });
}
 
Example 6
Project: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 6 votes vote down vote up
@Test
@MediumTest
public void testExpandedPeekHeight() throws Throwable {
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          // Make the peek height as tall as the bottom sheet.
          BottomSheetBehavior<?> behavior = getBehavior();
          behavior.setPeekHeight(getBottomSheet().getHeight());
          assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        }
      });
  // Both of these will not animate the sheet , but the state should be changed.
  checkSetState(BottomSheetBehavior.STATE_EXPANDED, ViewMatchers.isDisplayed());
  checkSetState(BottomSheetBehavior.STATE_COLLAPSED, ViewMatchers.isDisplayed());
}
 
Example 7
Project: material-components-android   File: CustomSnackbarTest.java   Source Code and License 6 votes vote down vote up
@Test
@MediumTest
public void testDismissViaAnotherSnackbar() throws Throwable {
  final CustomSnackbar anotherSnackbar =
      makeCustomSnackbar()
          .setTitle("Different title")
          .setSubtitle("Different subtitle")
          .setDuration(Snackbar.LENGTH_SHORT);

  // Our dismiss action is to show another snackbar (and verify that the original snackbar
  // is now dismissed with CONSECUTIVE event)
  verifyDismissCallback(
      onView(isAssignableFrom(Snackbar.SnackbarLayout.class)),
      null,
      new DismissAction() {
        @Override
        public void dismiss(CustomSnackbar snackbar) {
          anotherSnackbar.show();
        }
      },
      Snackbar.LENGTH_LONG,
      Snackbar.Callback.DISMISS_EVENT_CONSECUTIVE);

  // And dismiss the second snackbar to get back to clean state
  SnackbarUtils.dismissTransientBottomBarAndWaitUntilFullyDismissed(anotherSnackbar);
}
 
Example 8
Project: material-components-android   File: CustomSnackbarTest.java   Source Code and License 6 votes vote down vote up
@Test
@MediumTest
public void testMultipleCallbacks() throws Throwable {
  final CustomSnackbar snackbar =
      makeCustomSnackbar()
          .setTitle(TITLE_TEXT)
          .setSubtitle(SUBTITLE_TEXT)
          .setDuration(Snackbar.LENGTH_INDEFINITE);
  final BaseTransientBottomBar.BaseCallback mockCallback1 =
      mock(BaseTransientBottomBar.BaseCallback.class);
  final BaseTransientBottomBar.BaseCallback mockCallback2 =
      mock(BaseTransientBottomBar.BaseCallback.class);
  snackbar.addCallback(mockCallback1);
  snackbar.addCallback(mockCallback2);

  SnackbarUtils.showTransientBottomBarAndWaitUntilFullyShown(snackbar);
  verify(mockCallback1, times(1)).onShown(snackbar);
  verify(mockCallback2, times(1)).onShown(snackbar);

  SnackbarUtils.dismissTransientBottomBarAndWaitUntilFullyDismissed(snackbar);
  verify(mockCallback1, times(1))
      .onDismissed(snackbar, BaseTransientBottomBar.BaseCallback.DISMISS_EVENT_MANUAL);
  verify(mockCallback2, times(1))
      .onDismissed(snackbar, BaseTransientBottomBar.BaseCallback.DISMISS_EVENT_MANUAL);
}
 
Example 9
Project: material-components-android   File: FabTransformationBehaviorTest.java   Source Code and License 6 votes vote down vote up
@Test
@MediumTest
public void testRotationInExpandedState() {
  ExpandableTransformationActivity activity = activityTestRule.getActivity();
  int oldOrientation = TestUtils.getScreenOrientation(activity);

  onView(withId(R.id.fab)).perform(setExpanded(true));
  TestUtils.switchScreenOrientation(activity);
  onView(isRoot()).perform(waitUntilIdle());

  onView(withId(R.id.fab)).check(matches(not(isDisplayed())));
  onView(withId(R.id.sheet)).check(matches(isDisplayed()));
  onView(withId(R.id.scrim)).check(matches(isDisplayed()));

  TestUtils.resetScreenOrientation(activity, oldOrientation);
}
 
Example 10
Project: android-plugin-host-sdk-for-locale   File: ConditionTest.java   Source Code and License 6 votes vote down vote up
@MediumTest
@Test
public void query_bad_state() {
    final Condition condition = getCondition();

    try {
        final Bundle bundle = new Bundle();
        bundle.putInt(PluginBundleManager.BUNDLE_EXTRA_INT_VERSION_CODE, 1);
        bundle.putInt(PluginBundleManager.BUNDLE_EXTRA_INT_RESULT_CODE,
                1); //$NON-NLS-1$

        assertThat(condition.query(getPluginInstanceData(bundle),
                com.twofortyfouram.locale.api.Intent.RESULT_CONDITION_UNKNOWN),
                is(com.twofortyfouram.locale.api.Intent.RESULT_CONDITION_UNKNOWN));
    } finally {
        condition.destroy();
    }
}
 
Example 11
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryTest.java   Source Code and License 6 votes vote down vote up
@MediumTest
@Test
public void peekPluginMap_after_blocking() {
    final PluginRegistry registry = new PluginRegistry(InstrumentationRegistry.getContext(),
            getIntentAction());

    try {
        registry.init();
        registry.blockUntilLoaded();

        assertThat(registry.peekPluginMap(PluginType.CONDITION), notNullValue());
        assertThat(registry.peekPluginMap(PluginType.SETTING), notNullValue());
    } finally {
        registry.destroy();
    }
}
 
Example 12
Project: AndroidViewModel   File: ViewModelActivityTest.java   Source Code and License 6 votes vote down vote up
@MediumTest
@Test
public void viewModelActivity_instance_count_test() {
    mActivityTestRule.launchActivity(VMTestActivity.makeIntent(InstrumentationRegistry.getContext(), false));

    String uniqueIdentifierActivity = mActivityTestRule.getActivity().getViewModel().getUniqueIdentifier();
    String uniqueIdentifierFragment = mActivityTestRule.getActivity().getTestFragment().getViewModel().getUniqueIdentifier();

    rotateScreen(5);

    Map<String, AbstractViewModel<? extends IView>> viewModels =
            mActivityTestRule.getActivity().getViewModelProvider().getViewModels();

    assertThat(viewModels.size(), is(2)); //activity + fragment

    assertThat(viewModels.containsKey(uniqueIdentifierActivity), is(true));
    assertThat(viewModels.containsKey(uniqueIdentifierFragment), is(true));
}
 
Example 13
Project: furry-sniffle   File: ViewOtherUserProfileTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void profileViewTests1() throws InterruptedException{
    rule2.getActivity();
    Thread.sleep(20000);
    onView(withId(R.id.displayNameTextView)).check(matches(isDisplayed()));
    onView(withId(R.id.describeEditText)).check(matches(isDisplayed()));
    onView(withId(R.id.fullNameTextView)).check(matches(isDisplayed()));
    onView(withId(R.id.imageView2)).check(matches(isDisplayed()));
}
 
Example 14
Project: furry-sniffle   File: ViewEntertainmentTest2.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void ViewTests1() throws InterruptedException{
    rule2.getActivity();
    Thread.sleep(10000);

    onView(withId(R.id.ViewAddedAreaOwnerText)).check(matches(isDisplayed()));
    onView(withId(R.id.ViewAddedAreaAddressText)).check(matches(isDisplayed()));
    onView(withId(R.id.likeFloatingActionButton)).check(matches(isDisplayed()));
    onView(withId(R.id.ViewAddedAreaImageView)).check(matches(isDisplayed()));
    onView(withId(R.id.authorImageView)).check(matches(isDisplayed()));
    onView(withId(R.id.navigationImageView)).check(matches(isDisplayed()));
}
 
Example 15
Project: furry-sniffle   File: ViewEntertainmentTest2.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void ViewTests2() throws InterruptedException{
    rule2.getActivity();
    Thread.sleep(10000);
    onView(isRoot()).perform(swipeUp());
    onView(withId(R.id.descriptImageView)).check(matches(isDisplayed()));
    onView(withId(R.id.averageCostImageView)).check(matches(isDisplayed()));
    onView(withId(R.id.ViewAddedAreaDescText)).check(matches(isDisplayed()));
    onView(withId(R.id.averageCostSpinner)).check(matches(isDisplayed()));
}
 
Example 16
Project: furry-sniffle   File: ViewEntertainmentTest2.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void ViewTest4() throws InterruptedException{
    rule2.getActivity();
    Thread.sleep(10000);
    onView(isRoot()).perform(swipeUp());
    onView(withId(R.id.comment_recyclerView)).check(matches(isDisplayed()));
    onView(withId(R.id.commentEditText)).check(matches(isDisplayed()));
    onView(withId(R.id.commentImageButton)).check(matches(isDisplayed()));

}
 
Example 17
Project: furry-sniffle   File: createPasswordTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void test1() throws InterruptedException {
    Thread.sleep(2000);
    onView(withId(R.id.loginEmailEditText)).perform(click());
    onView(withId(R.id.loginEmailEditText)).perform(typeText("[email protected]"));
    //onView(withId(R.id.loginPasswordEditText)).perform(click()).perform(typeText("sandile11"));
    onView(withId(R.id.createAccountButton)).perform(click());
    Thread.sleep(5000);
}
 
Example 18
Project: furry-sniffle   File: createPasswordTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void test2() throws InterruptedException {
    Thread.sleep(2000);
    onView(withId(R.id.loginEmailEditText)).perform(typeText("[email protected]"), closeSoftKeyboard());
    onView(withId(R.id.loginPasswordEditText)).perform(typeText("sandile11"), closeSoftKeyboard());
    onView(withId(R.id.createAccountButton)).perform(click());
    Thread.sleep(5000);
}
 
Example 19
Project: furry-sniffle   File: createPasswordTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void test3() throws InterruptedException {
    Thread.sleep(2000);
    onView(withId(R.id.loginEmailEditText)).perform(click()).perform(typeText("[email protected]"));
    onView(withId(R.id.loginPasswordEditText)).perform(click()).perform(typeText("sandile11"));
    onView(withId(R.id.createAccountButton)).perform(click());
    Thread.sleep(5000);
}
 
Example 20
Project: furry-sniffle   File: MainTest1.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void signOutTest() throws InterruptedException {
    Thread.sleep(6000);
    mAuth.signOut();
    Thread.sleep(2000);
    login();
    Thread.sleep(2000);
}
 
Example 21
Project: furry-sniffle   File: CreateProfileTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void test1() throws InterruptedException{
    Thread.sleep(3000);
    onView(withId(R.id.displayNameEditText)).check(matches(isClickable()));
    onView(withId(R.id.setupPictureButton)).check(matches(isClickable()));

    onView(withId(R.id.displayNameEditText)).perform(typeText(displayName),pressBack());
    onView(withId(R.id.fullNameEditText)).perform(typeText(fullName),pressBack());
}
 
Example 22
Project: android-EmojiCompat   File: MainActivityTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void allTextsDisplayed() throws Exception {
    @StringRes final int[] resIds = {
            R.string.emoji_text_view,
            R.string.emoji_edit_text,
            R.string.emoji_button,
            R.string.regular_text_view,
            R.string.custom_text_view,
    };
    for (int resId : resIds) {
        final String text = rule.getActivity().getString(resId, MainActivity.EMOJI);
        onView(withText(text)).check(matches(isDisplayed()));
    }
}
 
Example 23
Project: AndroidRTC   File: SurfaceTextureHelperTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test disposing the SurfaceTextureHelper, but keep trying to produce more texture frames. No
 * frames should be delivered to the listener.
 */
@Test
@MediumTest
public void testDispose() throws InterruptedException {
  // Create SurfaceTextureHelper and listener.
  final SurfaceTextureHelper surfaceTextureHelper =
      SurfaceTextureHelper.create("SurfaceTextureHelper test" /* threadName */, null);
  final MockTextureListener listener = new MockTextureListener();
  surfaceTextureHelper.startListening(listener);
  // Create EglBase with the SurfaceTexture as target EGLSurface.
  final EglBase eglBase = EglBase.create(null, EglBase.CONFIG_PLAIN);
  eglBase.createSurface(surfaceTextureHelper.getSurfaceTexture());
  eglBase.makeCurrent();
  // Assert no frame has been received yet.
  assertFalse(listener.waitForNewFrame(1));
  // Draw and wait for one frame.
  GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
  // swapBuffers() will ultimately trigger onTextureFrameAvailable().
  eglBase.swapBuffers();
  listener.waitForNewFrame();
  surfaceTextureHelper.returnTextureFrame();

  // Dispose - we should not receive any textures after this.
  surfaceTextureHelper.dispose();

  // Draw one frame.
  GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
  eglBase.swapBuffers();
  // swapBuffers() should not trigger onTextureFrameAvailable() because disposed has been called.
  // Assert that no OES texture was delivered.
  assertFalse(listener.waitForNewFrame(500));

  eglBase.release();
}
 
Example 24
Project: AndroidRTC   File: SurfaceTextureHelperTest.java   Source Code and License 5 votes vote down vote up
/**
 * Call stopListening(), but keep trying to produce more texture frames. No frames should be
 * delivered to the listener.
 */
@Test
@MediumTest
public void testStopListening() throws InterruptedException {
  // Create SurfaceTextureHelper and listener.
  final SurfaceTextureHelper surfaceTextureHelper =
      SurfaceTextureHelper.create("SurfaceTextureHelper test" /* threadName */, null);
  final MockTextureListener listener = new MockTextureListener();
  surfaceTextureHelper.startListening(listener);
  // Create EglBase with the SurfaceTexture as target EGLSurface.
  final EglBase eglBase = EglBase.create(null, EglBase.CONFIG_PLAIN);
  eglBase.createSurface(surfaceTextureHelper.getSurfaceTexture());
  eglBase.makeCurrent();
  // Assert no frame has been received yet.
  assertFalse(listener.waitForNewFrame(1));
  // Draw and wait for one frame.
  GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
  // swapBuffers() will ultimately trigger onTextureFrameAvailable().
  eglBase.swapBuffers();
  listener.waitForNewFrame();
  surfaceTextureHelper.returnTextureFrame();

  // Stop listening - we should not receive any textures after this.
  surfaceTextureHelper.stopListening();

  // Draw one frame.
  GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
  eglBase.swapBuffers();
  // swapBuffers() should not trigger onTextureFrameAvailable() because disposed has been called.
  // Assert that no OES texture was delivered.
  assertFalse(listener.waitForNewFrame(500));

  surfaceTextureHelper.dispose();
  eglBase.release();
}
 
Example 25
Project: Presenter-Client-Android   File: MainActivityTest.java   Source Code and License 5 votes vote down vote up
/**
 * Verify that the settings activity can be started from main menu.
 */
@Test
@MediumTest
public void startSettingsActivity() {
    CharSequence settingsTitle =
            InstrumentationRegistry.getTargetContext().getString(R.string.settings);

    onView(withId(R.id.settings)).perform(click());
    onView(isAssignableFrom(Toolbar.class))
            .check(matches(withToolbarTitle(is(settingsTitle))));
}
 
Example 26
Project: Presenter-Client-Android   File: MainActivityTest.java   Source Code and License 5 votes vote down vote up
/**
 * Verify that the about activity can be started from main menu.
 */
@Test
@MediumTest
public void startAboutActivity() {
    CharSequence aboutTitle =
            InstrumentationRegistry.getTargetContext().getString(R.string.about,
                    InstrumentationRegistry.getTargetContext().getString(R.string.app_name));

    onView(withId(R.id.about)).perform(click());
    onView(isAssignableFrom(Toolbar.class))
            .check(matches(withToolbarTitle(is(aboutTitle))));
}
 
Example 27
Project: material-components-android   File: FloatingActionButtonTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testShowHide() {
  onView(withId(R.id.fab_standard))
      .perform(setVisibility(View.GONE))
      .perform(showThenHide())
      .check(matches(not(isDisplayed())));
}
 
Example 28
Project: material-components-android   File: FloatingActionButtonTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testOnClickListener() {
    final View.OnClickListener listener = mock(View.OnClickListener.class);
    final View view = activityTestRule.getActivity().findViewById(R.id.fab_standard);
    view.setOnClickListener(listener);

    // Click on the fab
    onView(withId(R.id.fab_standard)).perform(click());

    // And verify that the listener was invoked once
    verify(listener, times(1)).onClick(view);
}
 
Example 29
Project: material-components-android   File: FloatingActionButtonTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testElevationOnPressed() {
  onView(withId(R.id.fab_standard)).perform(setPressed(true));
  // It's unclear why the 21+ state list animator is not affected by loopMainThreadUntilIdle().
  onView(isRoot()).perform(waitFor(1000));
  onView(withId(R.id.fab_standard)).check(matches(hasTranslationZ()));
}
 
Example 30
Project: material-components-android   File: FloatingActionButtonTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testInstanceState() throws Throwable {
  FloatingActionButtonActivity activity = activityTestRule.getActivity();

  onView(withId(R.id.fab_standard)).perform(setExpanded(false));
  ActivityUtils.recreateActivity(activityTestRule, activity);
  ActivityUtils.waitForExecution(activityTestRule);
  onView(withId(R.id.fab_standard)).check(matches(not(isExpanded())));

  onView(withId(R.id.fab_standard)).perform(setExpanded(true));
  ActivityUtils.recreateActivity(activityTestRule, activity);
  ActivityUtils.waitForExecution(activityTestRule);
  onView(withId(R.id.fab_standard)).check(matches(isExpanded()));
}
 
Example 31
Project: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testHalfExpandedToExpanded() throws Throwable {
  getBehavior().setFitToContents(false);
  checkSetState(BottomSheetBehavior.STATE_HALF_EXPANDED, ViewMatchers.isDisplayed());
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  new CoordinatesProvider() {
                    @Override
                    public float[] calculateCoordinates(View view) {
                      return new float[] {view.getWidth() / 2, 0};
                    }
                  },
                  Press.FINGER),
              ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 32
Project: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testCollapsedToExpanded() throws Throwable {
  getBehavior().setFitToContents(false);
  checkSetState(BottomSheetBehavior.STATE_COLLAPSED, ViewMatchers.isDisplayed());
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  new CoordinatesProvider() {
                    @Override
                    public float[] calculateCoordinates(View view) {
                      return new float[] {view.getWidth() / 2, 0};
                    }
                  },
                  Press.FINGER),
              ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 33
Project: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testInvisible() throws Throwable {
  // Make the bottomsheet invisible
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          getBottomSheet().setVisibility(View.INVISIBLE);
          assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        }
      });
  // Swipe up as if to expand it
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  new CoordinatesProvider() {
                    @Override
                    public float[] calculateCoordinates(View view) {
                      return new float[] {view.getWidth() / 2, 0};
                    }
                  },
                  Press.FINGER),
              not(ViewMatchers.isDisplayed())));
  // Check that the bottom sheet stays the same collapsed state
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        }
      });
}
 
Example 34
Project: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testAutoPeekHeightHide() throws Throwable {
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          getBehavior().setHideable(true);
          getBehavior().setPeekHeight(0);
          getBehavior().setPeekHeight(BottomSheetBehavior.PEEK_HEIGHT_AUTO);
        }
      });
  checkSetState(BottomSheetBehavior.STATE_HIDDEN, not(ViewMatchers.isDisplayed()));
}
 
Example 35
Project: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testDynamicContent() throws Throwable {
  registerIdlingResourceCallback();
  try {
    activityTestRule.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            ViewGroup.LayoutParams params = getBottomSheet().getLayoutParams();
            params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
            getBottomSheet().setLayoutParams(params);
            View view = new View(getBottomSheet().getContext());
            int size = getBehavior().getPeekHeight() * 2;
            getBottomSheet().addView(view, new ViewGroup.LayoutParams(size, size));
            assertThat(getBottomSheet().getChildCount(), is(1));
            // Shrink the content height.
            ViewGroup.LayoutParams lp = view.getLayoutParams();
            lp.height = (int) (size * 0.8);
            view.setLayoutParams(lp);
            // Immediately expand the bottom sheet.
            getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED);
          }
        });
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
    // Make sure that the bottom sheet is not floating above the bottom.
    assertThat(getBottomSheet().getBottom(), is(getCoordinatorLayout().getBottom()));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example 36
Project: material-components-android   File: CustomSnackbarTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testDismissViaSwipe() throws Throwable {
  verifyDismissCallback(
      onView(isAssignableFrom(Snackbar.SnackbarLayout.class)),
      swipeRight(),
      null,
      Snackbar.LENGTH_LONG,
      Snackbar.Callback.DISMISS_EVENT_SWIPE);
}
 
Example 37
Project: material-components-android   File: CustomSnackbarTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testDismissViaSwipeRtl() throws Throwable {
  onView(withId(R.id.col)).perform(setLayoutDirection(ViewCompat.LAYOUT_DIRECTION_RTL));
  if (ViewCompat.getLayoutDirection(coordinatorLayout) == ViewCompat.LAYOUT_DIRECTION_RTL) {
    // On devices that support RTL layout, the start-to-end dismiss swipe is done
    // with swipeLeft() action
    verifyDismissCallback(
        onView(isAssignableFrom(Snackbar.SnackbarLayout.class)),
        swipeLeft(),
        null,
        Snackbar.LENGTH_LONG,
        Snackbar.Callback.DISMISS_EVENT_SWIPE);
  }
}
 
Example 38
Project: material-components-android   File: CustomSnackbarTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testDismissViaApi() throws Throwable {
  verifyDismissCallback(
      onView(isAssignableFrom(Snackbar.SnackbarLayout.class)),
      null,
      new DismissAction() {
        @Override
        public void dismiss(CustomSnackbar snackbar) {
          snackbar.dismiss();
        }
      },
      Snackbar.LENGTH_LONG,
      Snackbar.Callback.DISMISS_EVENT_MANUAL);
}
 
Example 39
Project: material-components-android   File: CustomSnackbarTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testDismissViaTimeout() throws Throwable {
  verifyDismissCallback(
      onView(isAssignableFrom(Snackbar.SnackbarLayout.class)),
      null,
      null,
      Snackbar.LENGTH_LONG,
      Snackbar.Callback.DISMISS_EVENT_TIMEOUT);
}
 
Example 40
Project: material-components-android   File: BottomSheetDialogTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testHideThenShow() throws Throwable {
  // Hide the bottom sheet and wait for the dialog to be canceled.
  final DialogInterface.OnCancelListener onCancelListener =
      mock(DialogInterface.OnCancelListener.class);
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          showDialog();
          dialog.setOnCancelListener(onCancelListener);
        }
      });
  Espresso.onView(ViewMatchers.withId(R.id.design_bottom_sheet))
      .perform(setState(BottomSheetBehavior.STATE_HIDDEN));
  verify(onCancelListener, timeout(3000)).onCancel(any(DialogInterface.class));
  // Reshow the same dialog instance and wait for the bottom sheet to be collapsed.
  final BottomSheetBehavior.BottomSheetCallback callback =
      mock(BottomSheetBehavior.BottomSheetCallback.class);
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          BottomSheetBehavior.from(dialog.findViewById(R.id.design_bottom_sheet))
              .setBottomSheetCallback(callback);
          dialog.show(); // Show the same dialog again.
        }
      });
  verify(callback, timeout(3000))
      .onStateChanged(any(View.class), eq(BottomSheetBehavior.STATE_SETTLING));
  verify(callback, timeout(3000))
      .onStateChanged(any(View.class), eq(BottomSheetBehavior.STATE_COLLAPSED));
}
 
Example 41
Project: material-components-android   File: TabLayoutWithViewPagerTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testFixedTabMode() {
  // Create a new adapter (with no content)
  final TextPagerAdapter newAdapter = new TextPagerAdapter();
  // And set it on the ViewPager
  onView(withId(R.id.tabs_viewpager)).perform(setAdapter(newAdapter));
  // As TabLayout doesn't track adapter changes, we need to re-wire the new adapter
  onView(withId(R.id.tabs)).perform(setupWithViewPager(viewPager));

  // Set fixed mode on the TabLayout
  onView(withId(R.id.tabs)).perform(TabLayoutActions.setTabMode(TabLayout.MODE_FIXED));
  assertEquals("Fixed tab mode", TabLayout.MODE_FIXED, tabLayout.getTabMode());

  // Add a bunch of tabs and verify that all of them are visible on the screen
  for (int i = 0; i < 8; i++) {
    onView(withId(R.id.tabs_viewpager)).perform(addItemToPager("Title " + i, "Body " + i));

    int expectedTabCount = i + 1;
    assertEquals("Tab count after adding #" + i, expectedTabCount, tabLayout.getTabCount());
    assertEquals(
        "Page count after adding #" + i, expectedTabCount, viewPager.getAdapter().getCount());

    verifyViewPagerSelection();
    verifyTabLayoutSelection();

    // Check that all tabs are fully visible (the content may or may not be elided)
    for (int j = 0; j < expectedTabCount; j++) {
      onView(allOf(isDescendantOfA(withId(R.id.tabs)), withText("Title " + j)))
          .check(matches(isCompletelyDisplayed()));
    }
  }
}
 
Example 42
Project: material-components-android   File: SnackbarWithTranslucentNavBarTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testDrawsAboveNavigationBar() {
  // Show a simple Snackbar and wait for it to be shown
  final Snackbar snackbar = Snackbar.make(coordinatorLayout, MESSAGE_TEXT, Snackbar.LENGTH_SHORT);
  SnackbarUtils.showTransientBottomBarAndWaitUntilFullyShown(snackbar);

  final WindowInsetsCompat colLastInsets = coordinatorLayout.getLastWindowInsets();
  assertNotNull(colLastInsets);

  // Check that the Snackbar view has padding set to display above the nav bar
  final View view = snackbar.getView();
  assertNotNull(view);
  assertEquals(colLastInsets.getSystemWindowInsetBottom(), view.getPaddingBottom());
}
 
Example 43
Project: LazyStorage   File: LazyStorageTest.java   Source Code and License 5 votes vote down vote up
@Test @MediumTest public void testSaveAllAndDeleteByClass() {
    List<Car> source = givenAList(10);
    lazy.saveAll(source);
    List<Car> result = lazy.loadAll(Car.class);
    assertEquals(source, result);
    lazy.deleteAll(Car.class);
    List<Car> loadAfterDelete = lazy.loadAll(Car.class);
    assertTrue(loadAfterDelete.isEmpty());
}
 
Example 44
Project: LazyStorage   File: LazyStorageTest.java   Source Code and License 5 votes vote down vote up
@Test @MediumTest public void testSaveAllAndDeleteList() {
    List<Car> source = givenAList(10);
    lazy.saveAll(source);
    List<Car> result = lazy.loadAll(Car.class);
    assertEquals(source, result);
    lazy.deleteAll(source);
    List<Car> loadAfterDelete = lazy.loadAll(Car.class);
    assertTrue(loadAfterDelete.isEmpty());
}
 
Example 45
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test(timeout = REGISTRY_LOAD_WAIT_MILLIS)
public void getInstance_initialized() {
    final PluginRegistry registrySingleton = PluginRegistry
            .getInstance(InstrumentationRegistry.getContext());

    assertThat(registrySingleton, notNullValue());
    assertThat(PluginRegistry.getInstance(InstrumentationRegistry.getContext()),
            sameInstance(registrySingleton));

    registrySingleton.blockUntilLoaded();
}
 
Example 46
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void getPluginMap_conditions() {
    final PluginRegistry registry = new PluginRegistry(InstrumentationRegistry.getContext(),
            getIntentAction());

    try {
        registry.init();

        final Map<String, Plugin> conditions = registry.getPluginMap(PluginType.CONDITION);
        assertThat(conditions, notNullValue());
    } finally {
        registry.destroy();
    }
}
 
Example 47
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void getPluginMap_settings() {
    final PluginRegistry registry = new PluginRegistry(InstrumentationRegistry.getContext(),
            getIntentAction());

    try {
        registry.init();

        final Map<String, Plugin> settings = registry.getPluginMap(PluginType.SETTING);
        assertThat(settings, notNullValue());
    } finally {
        registry.destroy();
    }
}
 
Example 48
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void loadCompleteNotification() {
    final String intentAction = getIntentAction();

    final PluginRegistry registry = new PluginRegistry(InstrumentationRegistry.getContext(),
            intentAction);

    final HandlerThread backgroundThread = ThreadUtil.newHandlerThread(intentAction,
            ThreadUtil.ThreadPriority.DEFAULT);
    try {
        final CountDownLatch latch = new CountDownLatch(1);

        final BroadcastReceiver receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(final Context context, final Intent intent) {
                Lumberjack.v("Received %s", intent); //$NON-NLS-1$
                latch.countDown();
            }
        };

        InstrumentationRegistry.getContext()
                .registerReceiver(receiver, new IntentFilter(intentAction), null,
                        new Handler(backgroundThread.getLooper()));

        registry.init();

        try {
            assertThat(latch.await(REGISTRY_LOAD_WAIT_MILLIS, TimeUnit.MILLISECONDS), is(true));
        } catch (final InterruptedException e) {
            throw new RuntimeException(e);
        }

        InstrumentationRegistry.getContext().unregisterReceiver(receiver);
    } finally {
        registry.destroy();
        backgroundThread.quit();
    }
}
 
Example 49
Project: android-plugin-host-sdk-for-locale   File: SupportPluginRegistryLoaderTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void testLoad_conditions() {
    final SupportPluginRegistryLoader loader = new SupportPluginRegistryLoader(
            InstrumentationRegistry.getContext(),
            PluginType.CONDITION);

    final Map<String, Plugin> loaderRegistry = getLoaderResultSynchronously(loader);

    assertThat(loaderRegistry, notNullValue());
    assertThat(loaderRegistry,
            hasKey(DebugPluginFixture.getDebugPluginCondition().getRegistryName()));
}
 
Example 50
Project: android-plugin-host-sdk-for-locale   File: SupportPluginRegistryLoaderTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void testLoad_settings() {
    final SupportPluginRegistryLoader loader = new SupportPluginRegistryLoader(
            InstrumentationRegistry.getContext(),
            PluginType.SETTING);

    final Map<String, Plugin> loaderRegistry = getLoaderResultSynchronously(loader);

    assertThat(loaderRegistry, notNullValue());
    assertThat(loaderRegistry,
            hasKey(DebugPluginFixture.getDebugPluginSetting().getRegistryName()));
}
 
Example 51
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryLoaderTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void testLoad_conditions() {
    final PluginRegistryLoader loader = new PluginRegistryLoader(
            InstrumentationRegistry.getContext(),
            PluginType.CONDITION);

    final Map<String, Plugin> loaderRegistry = getLoaderResultSynchronously(loader);

    assertThat(loaderRegistry, notNullValue());
    assertThat(loaderRegistry,
            hasKey(DebugPluginFixture.getDebugPluginCondition().getRegistryName()));
}
 
Example 52
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryLoaderTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void testLoad_settings() {
    final PluginRegistryLoader loader = new PluginRegistryLoader(
            InstrumentationRegistry.getContext(),
            PluginType.SETTING);

    final Map<String, Plugin> loaderRegistry = getLoaderResultSynchronously(loader);

    assertThat(loaderRegistry, notNullValue());
    assertThat(loaderRegistry,
            hasKey(DebugPluginFixture.getDebugPluginSetting().getRegistryName()));
}
 
Example 53
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleInit() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        assertThat(registryHandler.mMutableConditionMap, nullValue());
        assertThat(registryHandler.mMutableSettingMap, nullValue());

        registryHandler.handleInit();

        assertThat(registryHandler.mMutableConditionMap, notNullValue());
        assertThat(registryHandler.mMutableSettingMap, notNullValue());

        assertThat(registryHandler.mMutableConditionMap.isEmpty(), is(false));
        assertThat(registryHandler.mMutableSettingMap.isEmpty(), is(false));

        /*
         * Verify the debug plug-in condition and debug plug-in setting were
         * detected.
         */
        assertThat(registryHandler.mMutableConditionMap, hasKey(Plugin
                .generateRegistryName(context.getPackageName(),
                        PluginConditionActivity.class.getName())));
        assertThat(registryHandler.mMutableSettingMap, hasKey(Plugin.generateRegistryName(
                context.getPackageName(), PluginSettingActivity.class.getName())));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 54
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleRemovePackage_no_plugin() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        final Map<String, Plugin> conditionsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableConditionMap);
        final Map<String, Plugin> settingsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableSettingMap);

        assertThat(registryHandler
                        .handlePackageRemoved("com.twofortyfouram.locale.hack"), //$NON-NLS-1$
                is(PackageResult.NOTHING_CHANGED));

        /*
         * Verify the maps were unchanged
         */
        assertThat(registryHandler.mMutableConditionMap, is(conditionsBefore));
        assertThat(registryHandler.mMutableSettingMap, is(settingsBefore));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 55
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleAddPackage_no_package() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        final Map<String, Plugin> conditionsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableConditionMap);
        final Map<String, Plugin> settingsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableSettingMap);

        assertThat(registryHandler
                        .handlePackageAdded("com.twofortyfouram.locale.hack"), //$NON-NLS-1$
                is(PackageResult.NOTHING_CHANGED));

        /*
         * Verify the maps were unchanged
         */
        assertThat(registryHandler.mMutableConditionMap, is(conditionsBefore));
        assertThat(registryHandler.mMutableSettingMap, is(settingsBefore));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 56
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleAddPackage_no_plugin() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        final Map<String, Plugin> conditionsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableConditionMap);
        final Map<String, Plugin> settingsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableSettingMap);

        assertThat(registryHandler.handlePackageAdded("com.google.maps"), //$NON-NLS-1$
                is(PackageResult.NOTHING_CHANGED));

        /*
         * Verify the maps were unchanged
         */
        assertThat(registryHandler.mMutableConditionMap, is(conditionsBefore));
        assertThat(registryHandler.mMutableSettingMap, is(settingsBefore));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 57
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleAddPackage_condition() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final ComponentName disabledComponent = new ComponentName(context,
            PluginSettingActivity.class.getName());

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        context.getPackageManager().setComponentEnabledSetting(disabledComponent,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

        registryHandler.handleInit();

        registryHandler.mMutableConditionMap.clear();
        registryHandler.mMutableSettingMap.clear();

        assertThat(registryHandler
                .handlePackageAdded(
                        context.getPackageName()), is(PackageResult.CONDITIONS_CHANGED));

        final String conditionKey = Plugin.generateRegistryName(context.getPackageName(),
                PluginConditionActivity.class.getName());

        assertThat(registryHandler.mMutableConditionMap, hasKey(conditionKey));
        assertThat(registryHandler.mMutableSettingMap.isEmpty(), is(true));
    } finally {
        context.getPackageManager().setComponentEnabledSetting(disabledComponent,
                PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);

        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 58
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleAddPackage_setting() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final ComponentName disabledComponent = new ComponentName(context,
            PluginConditionActivity.class.getName());

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        context.getPackageManager().setComponentEnabledSetting(disabledComponent,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

        registryHandler.handleInit();

        registryHandler.mMutableConditionMap.clear();
        registryHandler.mMutableSettingMap.clear();

        assertThat(registryHandler
                .handlePackageAdded(
                        context.getPackageName()), is(PackageResult.SETTINGS_CHANGED));

        final String settingKey = Plugin.generateRegistryName(context.getPackageName(),
                PluginSettingActivity.class.getName());

        assertThat(registryHandler.mMutableConditionMap.isEmpty(), is(true));
        assertThat(registryHandler.mMutableSettingMap, hasKey(settingKey));
    } finally {
        context.getPackageManager().setComponentEnabledSetting(disabledComponent,
                PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);

        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 59
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleAddPackage_condition_and_setting() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        registryHandler.mMutableConditionMap.clear();
        registryHandler.mMutableSettingMap.clear();

        assertThat(registryHandler
                        .handlePackageAdded(
                                context.getPackageName()),
                is(PackageResult.CONDITIONS_AND_SETTINGS_CHANGED));

        final String conditionKey = Plugin.generateRegistryName(context.getPackageName(),
                PluginConditionActivity.class.getName());
        final String settingKey = Plugin.generateRegistryName(context.getPackageName(),
                PluginSettingActivity.class.getName());

        assertThat(registryHandler.mMutableConditionMap, hasKey(conditionKey));
        assertThat(registryHandler.mMutableSettingMap, hasKey(settingKey));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}
 
Example 60
Project: android-plugin-host-sdk-for-locale   File: PluginRegistryHandlerTest.java   Source Code and License 5 votes vote down vote up
@MediumTest
@Test
public void handleAddPackage_no_change() {
    final Context context = InstrumentationRegistry.getContext();
    final String uuid = UUID.randomUUID().toString();

    final HandlerThread thread = ThreadUtil
            .newHandlerThread(uuid, ThreadUtil.ThreadPriority.DEFAULT);
    final PluginRegistryHandler registryHandler = new PluginRegistryHandler(thread.getLooper(),
            context, uuid, uuid);
    try {
        registryHandler.handleInit();

        final Map<String, Plugin> conditionsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableConditionMap);
        final Map<String, Plugin> settingsBefore = new HashMap<String, Plugin>(
                registryHandler.mMutableSettingMap);

        assertThat(registryHandler
                .handlePackageChanged(
                        context.getPackageName()), is(PackageResult.NOTHING_CHANGED));

        assertThat(registryHandler.mMutableConditionMap, is(conditionsBefore));
        assertThat(registryHandler.mMutableSettingMap, is(settingsBefore));
    } finally {
        registryHandler.handleDestroy();
        thread.quit();
    }
}