當前位置: 首頁>>代碼示例>>Java>>正文


Java UiThreadTest類代碼示例

本文整理匯總了Java中android.test.UiThreadTest的典型用法代碼示例。如果您正苦於以下問題:Java UiThreadTest類的具體用法?Java UiThreadTest怎麽用?Java UiThreadTest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UiThreadTest類屬於android.test包,在下文中一共展示了UiThreadTest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBack

import android.test.UiThreadTest; //導入依賴的package包/類
@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());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:FragmentStackTest.java

示例2: testConnectivityManagerDelegateDoesNotCrash

import android.test.UiThreadTest; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:27,代碼來源:NetworkChangeNotifierTest.java

示例3: testPushPop

import android.test.UiThreadTest; //導入依賴的package包/類
@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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:FragmentStackTest.java

示例4: testPushReplace

import android.test.UiThreadTest; //導入依賴的package包/類
@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"));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:FragmentStackTest.java

示例5: testNetworkChangeNotifierIsOnline

import android.test.UiThreadTest; //導入依賴的package包/類
@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());
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:17,代碼來源:NetworkChangeNotifierTest.java

示例6: testAdd_requestProcessedInCorrectOrder

import android.test.UiThreadTest; //導入依賴的package包/類
@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();
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:17,代碼來源:RequestQueueTest.java

示例7: testLogChannelViewStop

import android.test.UiThreadTest; //導入依賴的package包/類
@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);
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:18,代碼來源:WatchedHistoryManagerTest.java

示例8: testCircularHistoryQueue

import android.test.UiThreadTest; //導入依賴的package包/類
@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));
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:25,代碼來源:WatchedHistoryManagerTest.java

示例9: testDefaultLocaleAndAcceptLanguageAgree

import android.test.UiThreadTest; //導入依賴的package包/類
/** 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();
}
 
開發者ID:gnosygnu,項目名稱:xowa_android,代碼行數:25,代碼來源:LanguageVariantTests.java

示例10: testSignup

import android.test.UiThreadTest; //導入依賴的package包/類
@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();
    }
}
 
開發者ID:CMPUT301W16T15,項目名稱:Shareo,代碼行數:17,代碼來源:LoginTest.java

示例11: testSignupAndLogin

import android.test.UiThreadTest; //導入依賴的package包/類
@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();
    }
}
 
開發者ID:CMPUT301W16T15,項目名稱:Shareo,代碼行數:18,代碼來源:LoginTest.java

示例12: testTheSequence

import android.test.UiThreadTest; //導入依賴的package包/類
/**
 * 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");
    }
}
 
開發者ID:worker8,項目名稱:TourGuide,代碼行數:29,代碼來源:SequenceTest.java

示例13: testNewSettingSave

import android.test.UiThreadTest; //導入依賴的package包/類
/**
 * 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());
}
 
開發者ID:souliss,項目名稱:soulissapp,代碼行數:21,代碼來源:TaskerEditActivityTest.java

示例14: testIntChanged

import android.test.UiThreadTest; //導入依賴的package包/類
@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());
}
 
開發者ID:martino2k6,項目名稱:StoreBox,代碼行數:18,代碼來源:ChangesListenersTestCase.java

示例15: testIntUnregistered

import android.test.UiThreadTest; //導入依賴的package包/類
@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());
}
 
開發者ID:martino2k6,項目名稱:StoreBox,代碼行數:19,代碼來源:ChangesListenersTestCase.java


注:本文中的android.test.UiThreadTest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。