类android.test.UiThreadTest源码实例Demo

下面列出了怎么用android.test.UiThreadTest的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: animation-samples   文件: SampleTests.java
/**
 * Test if all Interpolators can be used to start an animation.
 */
@UiThreadTest
public void testStartInterpolators() {

    // Start an animation for each interpolator
    final Interpolator[] interpolators = mTestFragment.getInterpolators();

    for (final Interpolator i : interpolators) {
        // Start the animation
        ObjectAnimator animator = mTestFragment.startAnimation(i, 1000L, mTestFragment.getPathIn());
        // Check that the correct interpolator is used for the animation
        assertEquals(i, animator.getInterpolator());
        // Verify the animation has started
        assertTrue(animator.isStarted());
        // Cancel before starting the next animation
        animator.cancel();
    }
}
 
源代码2 项目: android-project-wo2b   文件: RequestQueueTest.java
@UiThreadTest
public void testAdd_requestProcessedInCorrectOrder() throws Exception {
    int requestsToMake = 100;

    OrderCheckingNetwork network = new OrderCheckingNetwork();
    RequestQueue queue = new RequestQueue(new NoCache(), network, 1, mDelivery);

    for (Request<?> request : makeRequests(requestsToMake)) {
        queue.add(request);
    }

    network.setExpectedRequests(requestsToMake);
    queue.start();
    network.waitUntilExpectedDone(2000); // 2 seconds
    queue.stop();
}
 
源代码3 项目: StoreBox   文件: ChangesListenersTestCase.java
@UiThreadTest
@SmallTest
public void testIntChanged() {
    final AtomicInteger value = new AtomicInteger(-1);
    final OnPreferenceValueChangedListener<Integer> listener =
            new OnPreferenceValueChangedListener<Integer>() {
                @Override
                public void onChanged(Integer newValue) {
                    value.set(newValue);
                }
            };
    
    uut.registerIntChangeListener(listener);
    uut.setInt(1);
    
    assertEquals(1, value.get());
}
 
源代码4 项目: StoreBox   文件: ChangesListenersTestCase.java
@UiThreadTest
@SmallTest
public void testIntUnregistered() {
    final AtomicBoolean called = new AtomicBoolean();
    final OnPreferenceValueChangedListener<Integer> listener =
            new OnPreferenceValueChangedListener<Integer>() {
                @Override
                public void onChanged(Integer newValue) {
                    called.set(true);
                }
            };

    uut.registerIntChangeListener(listener);
    uut.unregisterIntChangeListener(listener);
    uut.setInt(1);

    assertFalse(called.get());
}
 
源代码5 项目: StoreBox   文件: ChangesListenersTestCase.java
@UiThreadTest
@SmallTest
public void testCustomClassChanged() {
    final AtomicReference<CustomClass> value = new AtomicReference<>();
    final OnPreferenceValueChangedListener<CustomClass> listener =
            new OnPreferenceValueChangedListener<CustomClass>() {
                @Override
                public void onChanged(CustomClass newValue) {
                    value.set(newValue);
                }
            };
    
    uut.registerCustomClassChangeListener(listener);
    uut.setCustomClass(new CustomClass("a", "b"));
    
    assertEquals(new CustomClass("a", "b"), value.get());
}
 
源代码6 项目: StoreBox   文件: ChangesListenersTestCase.java
@UiThreadTest
@SmallTest
public void testCustomClassChangedNull() {
    final AtomicReference<CustomClass> value = new AtomicReference<>();
    final OnPreferenceValueChangedListener<CustomClass> listener =
            new OnPreferenceValueChangedListener<CustomClass>() {
                @Override
                public void onChanged(CustomClass newValue) {
                    value.set(newValue);
                }
            };
    
    uut.setCustomClass(new CustomClass("a", "b"));
    uut.registerCustomClassChangeListener(listener);
    uut.setCustomClass(null);
    
    assertNull(value.get());
}
 
源代码7 项目: StoreBox   文件: ChangesListenersTestCase.java
@UiThreadTest
@SmallTest
public void testCustomClassUnregistered() {
    final AtomicBoolean called = new AtomicBoolean();
    final OnPreferenceValueChangedListener<CustomClass> listener =
            new OnPreferenceValueChangedListener<CustomClass>() {
                @Override
                public void onChanged(CustomClass newValue) {
                    called.set(true);
                }
            };

    uut.registerCustomClassChangeListener(listener);
    uut.unregisterCustomClassChangeListener(listener);
    uut.setCustomClass(new CustomClass("a", "b"));

    assertFalse(called.get());
}
 
源代码8 项目: StoreBox   文件: ChangesListenersTestCase.java
@UiThreadTest
@SmallTest
public void testListenerGarbageCollected() throws Exception {
    final AtomicBoolean called = new AtomicBoolean();

    uut.registerIntChangeListener(new OnPreferenceValueChangedListener<Integer>() {
        @Override
        public void onChanged(Integer newValue) {
            called.set(true);
        }
    });
    // nasty, but it does force collection of soft references...
    // TODO is there a better way to do this?
    try {
        Object[] ignored = new Object[(int) Runtime.getRuntime().maxMemory()];
    } catch (OutOfMemoryError e) {
        // NOP
    }
    uut.setInt(1);

    assertFalse(called.get());
}
 
@UiThreadTest
public void testObserveNotGrantedThenGrantedPermissions() {

    TestSubscriber<Boolean> subscriber = new TestSubscriber<>();
    RxPermissionsUnderTest permissions = new RxPermissionsUnderTest(getContext(), false);

    Subscription subscription = permissions.observe(
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE)
            .subscribe(subscriber);

    subscriber.assertValues(false);

    permissions.setAllowed(Manifest.permission.READ_EXTERNAL_STORAGE);
    subscriber.assertValues(false, false);

    permissions.setAllowed(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    subscriber.assertValues(false, false, true);

    subscriber.assertNoErrors();
    subscriber.assertNotCompleted();

    subscription.unsubscribe();
}
 
源代码10 项目: rx-android-permissions   文件: RxPermissionsTest.java
@UiThreadTest
public void testRequestGrantedPermissions() {

    TestSubscriber<Boolean> subscriber = new TestSubscriber<>();
    RxPermissionsUnderTest permissions = new RxPermissionsUnderTest(getContext(), true);
    MockPermissionsRequester requester = new MockPermissionsRequester(true);

    Subscription subscription = permissions.request(requester,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE)
            .subscribe(subscriber);

    subscriber.assertValue(true);
    subscriber.assertNoErrors();
    subscriber.assertCompleted();

    assertTrue(subscription.isUnsubscribed());
}
 
源代码11 项目: android-discourse   文件: RequestQueueTest.java
@UiThreadTest
public void testAdd_requestProcessedInCorrectOrder() throws Exception {
    int requestsToMake = 100;

    OrderCheckingNetwork network = new OrderCheckingNetwork();
    RequestQueue queue = new RequestQueue(new NoCache(), network, 1, mDelivery);

    for (Request<?> request : makeRequests(requestsToMake)) {
        queue.add(request);
    }

    network.setExpectedRequests(requestsToMake);
    queue.start();
    network.waitUntilExpectedDone(2000); // 2 seconds
    queue.stop();
}
 
源代码12 项目: codeexamples-android   文件: SpinnerActivityTest.java
@UiThreadTest
public void testPauseShouldPreserveInstanceState() {
	Instrumentation mInstr = this.getInstrumentation();
	mActivity.setSpinnerPosition(TEST_STATE_PAUSE_POSITION);
	mActivity.setSpinnerSelection(TEST_STATE_PAUSE_SELECTION);

	//
	mInstr.callActivityOnPause(mActivity);
	mActivity.setSpinnerPosition(0);
	mActivity.setSpinnerSelection("");

	mInstr.callActivityOnResume(mActivity);
	int currentPosition = mActivity.getSpinnerPosition();
	String currentSelection = mActivity.getSpinnerSelection();

	assertEquals(TEST_STATE_PAUSE_POSITION, currentPosition);
	assertEquals(TEST_STATE_PAUSE_SELECTION, currentSelection);
}
 
源代码13 项目: roads-api-samples   文件: ApplicationTest.java
@UiThreadTest
public void testSampleFlow() throws Exception {
    MainActivity activity = getActivity();

    // Click "Load GPX data" button
    View gpxButton = activity.findViewById(R.id.load_gpx_data);
    activity.onGpxButtonClick(gpxButton);
    assertTrue(activity.mCapturedLocations.size() > 0);

    // Click "Send Snap to Roads requests" button
    View snapButton = activity.findViewById(R.id.snap_to_roads);
    activity.onSnapToRoadsButtonClick(snapButton);
    activity.mSnappedPoints = activity.mTaskSnapToRoads.get();
    assertTrue(activity.mSnappedPoints.size() > 0);

    // Click "Request speed limits" button
    View speedsButton = activity.findViewById(R.id.speed_limits);
    activity.onSpeedLimitButtonClick(speedsButton);
    activity.mPlaceSpeeds = activity.mTaskSpeedLimits.get();
    assertTrue(activity.mPlaceSpeeds.size() > 0);
}
 
源代码14 项目: Masaccio   文件: TestActivity.java
@UiThreadTest
public void testFaceDetection() throws InterruptedException {

    final MasaccioImageView view =
            (MasaccioImageView) getActivity().findViewById(R.id.masaccio_view);

    assertThat(view.getScaleType()).isEqualTo(ScaleType.MATRIX);

    final float[] coeffs = new float[9];
    view.getImageMatrix().getValues(coeffs);

    assertThat(coeffs[0]).isEqualTo(0.234375f, Offset.offset(0.01f));
    assertThat(coeffs[1]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[2]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[3]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[4]).isEqualTo(0.234375f, Offset.offset(0.01f));
    assertThat(coeffs[5]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[6]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[7]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[8]).isEqualTo(1.0f, Offset.offset(0.01f));
}
 
源代码15 项目: Masaccio   文件: TestActivity.java
@UiThreadTest
public void testFaceDetection2() throws InterruptedException {

    final MasaccioImageView view =
            (MasaccioImageView) getActivity().findViewById(R.id.masaccio_view);

    view.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.pan0));

    assertThat(view.getScaleType()).isEqualTo(ScaleType.MATRIX);

    final float[] coeffs = new float[9];
    view.getImageMatrix().getValues(coeffs);

    assertThat(coeffs[0]).isEqualTo(0.3125f, Offset.offset(0.01f));
    assertThat(coeffs[1]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[2]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[3]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[4]).isEqualTo(0.3125f, Offset.offset(0.01f));
    assertThat(coeffs[5]).isEqualTo(-10.175781f, Offset.offset(0.01f));
    assertThat(coeffs[6]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[7]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[8]).isEqualTo(1.0f, Offset.offset(0.01f));
}
 
源代码16 项目: Masaccio   文件: TestActivity.java
@UiThreadTest
public void testFaceDetection3() throws InterruptedException {

    final MasaccioImageView view =
            (MasaccioImageView) getActivity().findViewById(R.id.masaccio_view);

    view.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.pan1));

    assertThat(view.getScaleType()).isEqualTo(ScaleType.MATRIX);

    final float[] coeffs = new float[9];
    view.getImageMatrix().getValues(coeffs);

    assertThat(coeffs[0]).isEqualTo(0.8333333f, Offset.offset(0.01f));
    assertThat(coeffs[1]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[2]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[3]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[4]).isEqualTo(0.8333333f, Offset.offset(0.01f));
    assertThat(coeffs[5]).isEqualTo(-17.239578f, Offset.offset(0.01f));
    assertThat(coeffs[6]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[7]).isEqualTo(0.0f, Offset.offset(0.01f));
    assertThat(coeffs[8]).isEqualTo(1.0f, Offset.offset(0.01f));
}
 
源代码17 项目: ploggy   文件: ActivityMainTest.java
@UiThreadTest
public void testStateSaveRestore() {
    //
    // Destroy/Create
    //

    // Check that we're starting on the first tab
    assertEquals(mActionBar.getSelectedNavigationIndex(), 0);

    // Select the second tab
    mActionBar.setSelectedNavigationItem(1);

    // Destroy the activity, which should save the state
    mActivity.finish();

    // Recreate the activity...
    mActivity = this.getActivity();

    // ...which should cause it to restore state
    assertEquals(mActionBar.getSelectedNavigationIndex(), 1);
}
 
源代码18 项目: tinybus   文件: BackgroundProcessingTest.java
@UiThreadTest
public void testPostMainReceiveBackgroundWrongConstructor() {
	
	final CountDownLatch latch = new CountDownLatch(1);
	
	bus = new TinyBus();
	bus.register(new Object() {
		@Subscribe(mode=Mode.Background)
		public void onEvent(String event) {
			stringResult = event;
			latch.countDown();
		}
	});
	
	try {
		bus.post("event a");
		fail();
	} catch (IllegalStateException e) {
		// OK
	}
}
 
源代码19 项目: pretty   文件: SanityTest.java
@Test
@UiThreadTest
public void testWrapActivity() throws Exception {
    Intent intent = new Intent();
    intent.setComponent(new ComponentName("com.madisp.pretty", "TestActivity"));

    Activity act = instrumentation.newActivity(
            Activity.class,
            context,
            null,
            new MockApplication(),
            intent,
            new ActivityInfo(),
            "",
            null,
            null,
            null);
    Pretty.wrap(act);
}
 
源代码20 项目: tinybus   文件: BackgroundQueuesTest.java
@UiThreadTest
public void testPostSingleEventToSingleQueue() throws Exception {
	
	final TinyBus bus = TinyBus.from(getInstrumentation().getContext());
	final CountDownLatch latch = new CountDownLatch(1);
	bus.register(new Object() {
		@Subscribe(mode = Mode.Background)
		public void onEvent(String event) {
			collectEvent(event);
			latch.countDown();
		}
	});
	
	bus.post("event a");
	latch.await(TEST_TIMEOUT, TimeUnit.SECONDS);
	
	assertEventsNumber(1);
	assertResult(0, "event a", "tinybus-worker-");
}
 
源代码21 项目: tinybus   文件: BackgroundQueuesTest.java
@UiThreadTest
public void testPostMultipleEventsToSingleQueue() throws Exception {
	
	int numberOfEvents = 100;
	
	TinyBus bus = TinyBus.from(getInstrumentation().getContext());
	final CountDownLatch latch = new CountDownLatch(numberOfEvents);
	bus.register(new Object() {
		@Subscribe(mode = Mode.Background)
		public void onEvent(String event) {
			collectEvent(event);
			latch.countDown();
		}
	});
	
	for(int i=0; i<numberOfEvents; i++) {
		bus.post("event_" + i);
	}
	latch.await(TEST_TIMEOUT, TimeUnit.SECONDS);
	
	assertEventsNumber(numberOfEvents);
	for(int i=0; i<numberOfEvents; i++) {
		assertResult(i, "event_" + i, "tinybus-worker-0");
	}
}
 
源代码22 项目: PTVGlass   文件: SetTimerActivityTest.java
@UiThreadTest
public void testOnGestureTapSupported() {
    MockSetTimerActivity activity = startActivity(mActivityIntent, null, null);

    activity.onResume();
    activity.getView().setSelection(0);

    assertTrue(activity.onGesture(Gesture.TAP));
    assertEquals(1, activity.mPlayedSoundEffects.size());
    assertEquals(Sounds.TAP, activity.mPlayedSoundEffects.get(0).intValue());

    Intent startedIntent = getStartedActivityIntent();

    assertNotNull(startedIntent);
    assertEquals(
            SelectValueActivity.class.getName(), startedIntent.getComponent().getClassName());
    assertEquals(
            SetTimerScrollAdapter.TimeComponents.HOURS.getMaxValue(),
            startedIntent.getIntExtra(SelectValueActivity.EXTRA_COUNT, 0));
    assertEquals(
            0, startedIntent.getIntExtra(SelectValueActivity.EXTRA_INITIAL_VALUE, 0));
    assertEquals(SetTimerActivity.SELECT_VALUE, getStartedActivityRequest());
    assertFalse(isFinishCalled());
}
 
源代码23 项目: PTVGlass   文件: SetTimerActivityTest.java
@UiThreadTest
public void testOnGestureTapSupportedSelectValueForMinutes() {
    MockSetTimerActivity activity = startActivity(mActivityIntent, null, null);

    activity.onResume();
    activity.getView().setSelection(1);

    assertTrue(activity.onGesture(Gesture.TAP));
    assertEquals(1, activity.mPlayedSoundEffects.size());
    assertEquals(Sounds.TAP, activity.mPlayedSoundEffects.get(0).intValue());

    Intent startedIntent = getStartedActivityIntent();

    assertNotNull(startedIntent);
    assertEquals(
            SelectValueActivity.class.getName(), startedIntent.getComponent().getClassName());
    assertEquals(
            SetTimerScrollAdapter.TimeComponents.MINUTES.getMaxValue(),
            startedIntent.getIntExtra(SelectValueActivity.EXTRA_COUNT, 0));
    assertEquals(
            5, startedIntent.getIntExtra(SelectValueActivity.EXTRA_INITIAL_VALUE, 0));
    assertEquals(SetTimerActivity.SELECT_VALUE, getStartedActivityRequest());
    assertFalse(isFinishCalled());
}
 
源代码24 项目: PTVGlass   文件: SetTimerActivityTest.java
@UiThreadTest
public void testOnGestureSwipeDownSupported() {
    MockSetTimerActivity activity = startActivity(mActivityIntent, null, null);
    SetTimerScrollAdapter adapter = (SetTimerScrollAdapter) activity.getView().getAdapter();
    long expectedDuration = TimeUnit.SECONDS.toMillis(45);

    adapter.setDurationMillis(expectedDuration);
    assertTrue(activity.onGesture(Gesture.SWIPE_DOWN));
    assertEquals(1, activity.mPlayedSoundEffects.size());
    assertEquals(Sounds.DISMISSED, activity.mPlayedSoundEffects.get(0).intValue());

    assertTrue(isFinishCalled());
    assertEquals(Activity.RESULT_OK, activity.mResultCode);
    assertNotNull(activity.mResultIntent);
    assertEquals(
            expectedDuration,
            activity.mResultIntent.getLongExtra(SetTimerActivity.EXTRA_DURATION_MILLIS, 0));
}
 
源代码25 项目: PTVGlass   文件: SelectValueActivityTest.java
@UiThreadTest
public void testOnGestureTapSupported() {
    MockSelectValueActivity activity = startActivity(mActivityIntent, null, null);
    int expectedSelectedValue = 35;

    activity.onResume();
    activity.getView().setSelection(expectedSelectedValue);

    assertTrue(activity.onGesture(Gesture.TAP));
    assertEquals(1, activity.mPlayedSoundEffects.size());
    assertEquals(Sounds.TAP, activity.mPlayedSoundEffects.get(0).intValue());

    assertTrue(isFinishCalled());
    assertEquals(Activity.RESULT_OK, activity.mResultCode);
    assertNotNull(activity.mResultIntent);
    assertEquals(
            expectedSelectedValue,
            activity.mResultIntent.getIntExtra(SelectValueActivity.EXTRA_SELECTED_VALUE, 0));
}
 
源代码26 项目: nucleus   文件: FragmentStackTest.java
@UiThreadTest
public void testPushPop() throws Exception {
    FragmentManager manager = activity.getSupportFragmentManager();
    FragmentStack stack = new FragmentStack(activity, manager, CONTAINER_ID);

    TestFragment1 fragment = new TestFragment1();
    stack.push(fragment);
    assertTopFragment(manager, stack, fragment, 0);

    TestFragment2 fragment2 = new TestFragment2();
    stack.push(fragment2);
    assertFragment(manager, fragment, 0);
    assertTopFragment(manager, stack, fragment2, 1);

    assertFalse(fragment.isAdded());
    assertTrue(fragment2.isAdded());

    assertTrue(stack.pop());
    assertTopFragment(manager, stack, fragment, 0);

    assertNull(manager.findFragmentByTag("1"));

    assertFalse(stack.pop());
    assertTopFragment(manager, stack, fragment, 0);
}
 
源代码27 项目: nucleus   文件: FragmentStackTest.java
@UiThreadTest
public void testBack() throws Exception {
    FragmentManager manager = activity.getSupportFragmentManager();
    FragmentStack stack = new FragmentStack(activity, manager, CONTAINER_ID);

    assertFalse(stack.back());

    stack.push(new TestFragment1());
    assertEquals(1, stack.size());
    assertFalse(stack.back());

    stack.push(new TestFragment1());
    assertEquals(2, stack.size());
    assertTrue(stack.back());

    assertEquals(1, stack.size());
}
 
源代码28 项目: user-interface-samples   文件: SampleTests.java
/**
 * Verify that the UI flags actually changed when the toggle method is called.
 */
@UiThreadTest
public void testFlagsChanged() {
    int uiFlags = getActivity().getWindow().getDecorView().getSystemUiVisibility();
    mTestFragment.toggleHideyBar();
    int newUiFlags = getActivity().getWindow().getDecorView().getSystemUiVisibility();
    assertTrue("UI Flags didn't toggle.", uiFlags != newUiFlags);
}
 
源代码29 项目: user-interface-samples   文件: SampleTests.java
/**
 * Verify that the UI flags actually changed when the toggle method is called.
 */
@UiThreadTest
public void testFlagsChanged() {
    int uiFlags = getActivity().getWindow().getDecorView().getSystemUiVisibility();
    mTestFragment.mImmersiveModeCheckBox.setChecked(true);
    mTestFragment.mHideNavCheckbox.setChecked(true);
    mTestFragment.mHideStatusBarCheckBox.setChecked(true);
    mTestFragment.toggleUiFlags();
    int newUiFlags = getActivity().getWindow().getDecorView().getSystemUiVisibility();
    assertTrue("UI Flags didn't toggle.", uiFlags != newUiFlags);
}
 
/**
 * Verify that the UI flags actually changed when the toggle method is called.
 */
@UiThreadTest
public void testFlagsChanged() {
    int uiFlags = getActivity().getWindow().getDecorView().getSystemUiVisibility();
    mTestFragment.toggleHideyBar();
    int newUiFlags = getActivity().getWindow().getDecorView().getSystemUiVisibility();
    assertTrue("UI Flags didn't toggle.", uiFlags != newUiFlags);
}