Java 类android.test.UiThreadTest 实例源码

项目:GitHub    文件: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());
}
项目:GitHub    文件: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);
}
项目:GitHub    文件:FragmentStackTest.java   
@UiThreadTest
public void testPushReplace() throws Exception {

    FragmentManager manager = activity.getSupportFragmentManager();
    FragmentStack stack = new FragmentStack(activity, manager, CONTAINER_ID);

    TestFragment1 fragment = new TestFragment1();
    stack.push(fragment);
    TestFragment2 fragment2 = new TestFragment2();
    stack.push(fragment2);

    TestFragment1 fragment3 = new TestFragment1();
    stack.replace(fragment3);
    assertTopFragment(manager, stack, fragment3, 0);

    assertNull(manager.findFragmentByTag("1"));
}
项目:GitHub    文件: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());
}
项目:GitHub    文件: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);
}
项目:GitHub    文件:FragmentStackTest.java   
@UiThreadTest
public void testPushReplace() throws Exception {

    FragmentManager manager = activity.getSupportFragmentManager();
    FragmentStack stack = new FragmentStack(activity, manager, CONTAINER_ID);

    TestFragment1 fragment = new TestFragment1();
    stack.push(fragment);
    TestFragment2 fragment2 = new TestFragment2();
    stack.push(fragment2);

    TestFragment1 fragment3 = new TestFragment1();
    stack.replace(fragment3);
    assertTopFragment(manager, stack, fragment3, 0);

    assertNull(manager.findFragmentByTag("1"));
}
项目:chromium-net-for-android    文件:NetworkChangeNotifierTest.java   
@UiThreadTest
@MediumTest
@Feature({"Android-AppBase"})
public void testConnectivityManagerDelegateDoesNotCrash() {
    ConnectivityManagerDelegate delegate =
            new ConnectivityManagerDelegate(getInstrumentation().getTargetContext());
    delegate.getNetworkState();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // getNetworkState(Network) doesn't crash upon invalid Network argument.
        Network invalidNetwork = netIdToNetwork(NetId.INVALID);
        NetworkState invalidNetworkState = delegate.getNetworkState(invalidNetwork);
        assertFalse(invalidNetworkState.isConnected());
        assertEquals(-1, invalidNetworkState.getNetworkType());
        assertEquals(-1, invalidNetworkState.getNetworkSubType());

        Network[] networks = delegate.getAllNetworksUnfiltered();
        if (networks.length >= 1) {
            delegate.getNetworkState(networks[0]);
        }
        delegate.getDefaultNetId();
        NetworkCallback networkCallback = new NetworkCallback();
        NetworkRequest networkRequest = new NetworkRequest.Builder().build();
        delegate.registerNetworkCallback(networkRequest, networkCallback);
        delegate.unregisterNetworkCallback(networkCallback);
    }
}
项目:chromium-net-for-android    文件:NetworkChangeNotifierTest.java   
@UiThreadTest
@MediumTest
@Feature({"Android-AppBase"})
public void testNetworkChangeNotifierIsOnline() throws InterruptedException {
    Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
    // For any connection type it should return true.
    for (int i = ConnectivityManager.TYPE_MOBILE; i < ConnectivityManager.TYPE_VPN; i++) {
        mConnectivityDelegate.setActiveNetworkExists(true);
        mConnectivityDelegate.setNetworkType(i);
        mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
        assertTrue(NetworkChangeNotifier.isOnline());
    }
    mConnectivityDelegate.setActiveNetworkExists(false);
    mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
    assertFalse(NetworkChangeNotifier.isOnline());
}
项目:iosched-reader    文件: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();
}
项目:smconf-android    文件: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();
}
项目:android_packages_apps_tv    文件:WatchedHistoryManagerTest.java   
@UiThreadTest
public void testLogChannelViewStop() throws Exception {
    startAndWaitForComplete();
    long fakeId = 100000000;
    long time = System.currentTimeMillis();
    long duration = TimeUnit.MINUTES.toMillis(10);
    Channel channel = new Channel.Builder().setId(fakeId).build();
    mWatchedHistoryManager.logChannelViewStop(channel, time, duration);

    WatchedRecord record = mWatchedHistoryManager.getRecord(0);
    WatchedRecord recordFromSharedPreferences =
            mWatchedHistoryManager.getRecordFromSharedPreferences(0);
    assertEquals(record.channelId, fakeId);
    assertEquals(record.watchedStartTime, time - duration);
    assertEquals(record.duration, duration);
    assertEquals(record, recordFromSharedPreferences);
}
项目:android_packages_apps_tv    文件:WatchedHistoryManagerTest.java   
@UiThreadTest
public void testCircularHistoryQueue() throws Exception {
    startAndWaitForComplete();
    final long startChannelId = 100000000;
    long time = System.currentTimeMillis();
    long duration = TimeUnit.MINUTES.toMillis(10);

    int size = MAX_HISTORY_SIZE * 2;
    for (int i = 0; i < size; ++i) {
        Channel channel = new Channel.Builder().setId(startChannelId + i).build();
        mWatchedHistoryManager.logChannelViewStop(channel, time + duration * i, duration);
    }
    for (int i = 0; i < MAX_HISTORY_SIZE; ++i) {
        WatchedRecord record = mWatchedHistoryManager.getRecord(i);
        WatchedRecord recordFromSharedPreferences =
                mWatchedHistoryManager.getRecordFromSharedPreferences(i);
        assertEquals(record, recordFromSharedPreferences);
        assertEquals(record.channelId, startChannelId + size - 1 - i);
    }
    // Since the WatchedHistory is a circular queue, the value for 0 and maxHistorySize
    // are same.
    assertEquals(mWatchedHistoryManager.getRecordFromSharedPreferences(0),
            mWatchedHistoryManager.getRecordFromSharedPreferences(MAX_HISTORY_SIZE));
}
项目:xowa_android    文件:LanguageVariantTests.java   
/** Ensure that the more specific dialect is first in the list. */
@UiThreadTest
public void testDefaultLocaleAndAcceptLanguageAgree() throws Throwable {
    preserveAppState();

    testDefaultLocaleAndAcceptLanguageAgree("zh,zh-hant;q=0.8", "zh",
            Locale.TRADITIONAL_CHINESE);
    testDefaultLocaleAndAcceptLanguageAgree("zh,zh-hans;q=0.8", "zh",
            Locale.SIMPLIFIED_CHINESE);
    testDefaultLocaleAndAcceptLanguageAgree("zh,en;q=0.8", "zh", Locale.US);
    testDefaultLocaleAndAcceptLanguageAgree("zh,en;q=0.8", "zh", Locale.ENGLISH);
    testDefaultLocaleAndAcceptLanguageAgree("en,zh-hans;q=0.8", "en",
            Locale.SIMPLIFIED_CHINESE);
    testDefaultLocaleAndAcceptLanguageAgree("test,zh-hans;q=0.8", "test",
            Locale.SIMPLIFIED_CHINESE);
    testDefaultLocaleAndAcceptLanguageAgree("es,zh-hans;q=0.9,zh-hant;q=0.8",
            AppLanguageLookUpTable.SIMPLIFIED_CHINESE_LANGUAGE_CODE,
            Locale.TRADITIONAL_CHINESE, Site.forLanguage("es"));
    testDefaultLocaleAndAcceptLanguageAgree("zh-hant",
            AppLanguageLookUpTable.TRADITIONAL_CHINESE_LANGUAGE_CODE,
            Locale.TRADITIONAL_CHINESE);

    restoreAppState();
}
项目:2015-Google-I-O-app    文件: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();
}
项目:Shareo    文件:LoginTest.java   
@UiThreadTest
public void testSignup() {
    try {
        signUp(name1, username1, email1, motto1);
        assertEquals(username1, AppUserSingleton.getInstance().getUser().getJestID());
        assertEquals(motto1, AppUserSingleton.getInstance().getUser().getMotto());
        assertEquals(email1, AppUserSingleton.getInstance().getUser().getEmailAddress());
        assertEquals(name1, AppUserSingleton.getInstance().getUser().getFullName());

        User dave = ShareoData.getInstance().getUser(username1);
        dave.new Deleter().useMainThread().delete();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:Shareo    文件:LoginTest.java   
@UiThreadTest
public void testSignupAndLogin() {
    try {
        signUp(name2, username2, email2, motto2);
        assertEquals(username2, AppUserSingleton.getInstance().getUser().getJestID());
        assertEquals(motto2, AppUserSingleton.getInstance().getUser().getMotto());
        assertEquals(email2, AppUserSingleton.getInstance().getUser().getEmailAddress());
        assertEquals(name2, AppUserSingleton.getInstance().getUser().getFullName());

        testLogin(username2);
        User user = ShareoData.getInstance().getUser(username2);
        user.new Deleter().useMainThread().delete();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目: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();
}
项目:FMTech    文件: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();
}
项目:TourGuide    文件:SequenceTest.java   
/**
 * To verify if it proceeds to the next tourGuide
 */
@UiThreadTest
public void testTheSequence(){
    int size = mActivity.mSequence.getTourGuideArray().length;
    int currentSequence = 0;

    try {
        assertEquals(getActualSequence(), currentSequence); //to make sure it proceeds to the next sequence
        Thread.sleep(1500);
        button.performClick();
        currentSequence += 1;

        assertEquals(getActualSequence(), currentSequence); //to make sure it proceeds to the next sequence
        button2.performClick();
        currentSequence += 1;
        Thread.sleep(1500);

        assertEquals(getActualSequence(), currentSequence);//to make sure it proceeds to the next sequence
        button3.performClick();

        assertEquals(mActivity.mSequence.mCurrentSequence, size); //to check if it reaches to the end of tourguide
    }
    catch (InterruptedException e){
        Log.d(TAG, "InterruptedException occur in testTheSequence");
    }
}
项目:soulissapp    文件:TaskerEditActivityTest.java   
/**
 * Tests creation of a new setting, that the UI is initialized to the right state, and that changes are
 * properly saved
 */
@MediumTest
@UiThreadTest
public void testNewSettingSave() throws Throwable {
    final Activity activity = getActivity();

    assertTitle();

    assertMessageAutoSync(""); //$NON-NLS-1$
    assertHintAutoSync(mTargetContext.getString(R.string.manual_cmd_hint));

    setMessageAutoSync(getName());

    activity.finish();

    assertActivityResultAutoSync(getName());
}
项目:saarang-iosched    文件: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();
}
项目:AppDevFestSudeste2015    文件: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();
}
项目:JJCamera    文件: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();
}
项目: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());
}
项目: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());
}
项目: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());
}
项目: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());
}
项目: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());
}
项目: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());
}
项目:SpotifyStreamer    文件:ArtistApiImplTest.java   
@UiThreadTest
public void testFindByName_ValidArtistName() throws Exception {
    final CountDownLatch signal = new CountDownLatch(1);
    artistApi = new ArtistApiImpl();
    artistApi.setApiResultListener(new ApiResultListener<List<Artist>>() {

        @Override
        public void onResult(List<Artist> artistList) {
            assertNotNull("Artist list is null", artistList);
            assertTrue("Any artist found!", artistList.size() > 0);
            signal.countDown();
        }

        @Override
        public void onException(Exception exception) {
            fail(exception.getMessage());
            signal.countDown();
        }
    });

    artistApi.findByName("Dave Matthews Band");
    signal.await();
}
项目:SpotifyStreamer    文件:ArtistApiImplTest.java   
@UiThreadTest
public void testFindByName_InvalidArtistName() throws Exception {
    final CountDownLatch signal = new CountDownLatch(1);
    artistApi = new ArtistApiImpl();
    artistApi.setApiResultListener(new ApiResultListener<List<Artist>>() {

        @Override
        public void onResult(List<Artist> artistList) {
            assertNotNull("Artist list is null", artistList);
            assertTrue("There should not be an item in this list!", artistList.size() == 0 );
            signal.countDown();
        }

        @Override
        public void onException(Exception exception) {
            fail(exception.getMessage());
            signal.countDown();
        }
    });

    artistApi.findByName("##.*");
    signal.await();
}
项目:proxypref    文件:TestActivityTest.java   
@UiThreadTest
public void testPreferences() throws Exception {
    SharedPreferences shared = getActivity().getSharedPreferences("1", 0);
    shared.edit().clear().apply();
    MyPreferences pref = ProxyPreferences.build(MyPreferences.class, shared);

    assertNull(pref.getTestString());
    pref.setTestString("123");
    assertEquals("123", pref.getTestString());
    assertEquals("123", shared.getString("testString", null));

    assertEquals(null, pref.testInteger());
    pref.testInteger(123);
    assertEquals((Integer)123, pref.testInteger());
    assertEquals(123, shared.getInt("testInteger", 1));
}
项目:rx-android-permissions    文件:RxPermissionsTest.java   
@UiThreadTest
public void testObserveGrantedPermissions() {

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

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

    assertEquals(2, permissions.requestedPermissions.size());
    assertEquals(Manifest.permission.READ_EXTERNAL_STORAGE,
            permissions.requestedPermissions.get(0));
    assertEquals(Manifest.permission.WRITE_EXTERNAL_STORAGE,
            permissions.requestedPermissions.get(1));

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

    subscription.unsubscribe();
}
项目:rx-android-permissions    文件:RxPermissionsTest.java   
@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();
}
项目: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());
}
项目: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();
}
项目:Todo.txt-gDrive    文件:MainActivityTest.java   
@MediumTest
@UiThreadTest
public void testListViewClick() throws Exception
{
    assertNotNull(mainActivity);
    assertNotNull(fab);
    assertNotNull(lv);
    assertNotNull(mainActivity.model);
    mainActivity.model.getAdapter().add(new Task("Test 1"));
    mainActivity.model.getAdapter().add(new Task("Test 2"));
    mainActivity.model.getAdapter().add(new Task("Test 3"));
    mainActivity.model.getAdapter().add(new Task("Test 4"));
    assertEquals(4, lv.getAdapter().getCount());
    for (int i = 800; i < 1000; i+=1)
    {
        clickXY(350, i);
    }
    assertEquals(4, lv.getAdapter().getCount());
}
项目: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);
}
项目:iosched    文件: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();
}
项目:Team09Project    文件:QuestionThreadActivityTest.java   
@UiThreadTest
// Use Case #3 : View replies
public void testDisplayReplies() {
    Post question = new Post(new User(context), "Question 1");
    Reply reply = new Reply(new User(context), "reply");
    PostController pc = new PostController(question);
    pc.addReply(reply);
    thread = new QuestionThread(question);

    Intent intent = new Intent();
    intent.putExtra("Selected Thread", thread);

    setActivityIntent(intent);

    ta = getActivity();

    assertEquals(2, ta.getAdapter().getGroupCount());
    assertEquals(1, ta.getAdapter().getChildrenCount(0));

    ((CheckBox) ta.findViewById(com.team09.qanda.R.id.repliesButton)).performClick();


    ViewAsserts.assertOnScreen(ta.getWindow().getDecorView(), ta.findViewById(com.team09.qanda.R.id.replyAuthor));
    ViewAsserts.assertOnScreen(ta.getWindow().getDecorView(), ta.findViewById(com.team09.qanda.R.id.reply));
    //ViewAsserts.assertGroupContains((ViewGroup) ta.findViewById(com.team09.qanda.R.id.ThreadPostsView), ta.findViewById(com.team09.qanda.R.id.postText));
}