android.support.test.InstrumentationRegistry Java Examples

The following examples show how to use android.support.test.InstrumentationRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: android-sdk   Author: sensorberg   File: SensorbergServiceInternalTests.java    License: MIT License 7 votes vote down vote up
@Before
public void setUp() throws Exception {
    ((TestComponent) SensorbergTestApplication.getComponent()).inject(this);

    tested = spy(new SensorbergService());
    tested.onCreate();
    tested.bluetoothPlatform = new TestBluetoothPlatform();
    fileManager = spy(fileManager);
    tested.fileManager = fileManager;
    tested.transport = Mockito.mock(Transport.class);

    Intent startIntent = SensorbergServiceIntents.getStartServiceIntent(InstrumentationRegistry.getContext(), TestConstants.API_TOKEN_DEFAULT);
    tested.onStartCommand(startIntent, -1, -1);

    TestGenericBroadcastReceiver.reset();
    TestGenericBroadcastReceiver2.reset();
}
 
Example #2
Source Project: XmlToJson   Author: smart-fun   File: ExampleInstrumentedTest.java    License: Apache License 2.0 7 votes vote down vote up
@Test
public void escapeSpecialCharsTest() throws Exception {
    Context context = InstrumentationRegistry.getTargetContext();
    AssetManager assetManager = context.getAssets();
    InputStream inputStream = assetManager.open("escape_chars.xml");

    XmlToJson xmlToJson = new XmlToJson.Builder(inputStream, null).build();
    inputStream.close();

    try {
        String formatted = xmlToJson.toFormattedString();
        new JSONObject(formatted);
    } catch (JSONException exception) {
        exception.printStackTrace();
        assertTrue("invalid JSON", false);
    }
}
 
Example #3
Source Project: android-PictureInPicture   Author: googlearchive   File: MediaSessionPlaybackActivityTest.java    License: Apache License 2.0 7 votes vote down vote up
@Test
public void fullscreen_disabledOnPortrait() throws Throwable {
    rule.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            rule.getActivity()
                    .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    rule.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            final View decorView = rule.getActivity().getWindow().getDecorView();
            assertThat(decorView.getSystemUiVisibility(),
                    not(hasFlag(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)));
        }
    });
}
 
Example #4
Source Project: android-sdk   Author: sensorberg   File: TheResolverWithMockApiShould.java    License: MIT License 7 votes vote down vote up
@Test
public void test_enter_exit_action() throws Exception {
    ResolveResponse resolveResponse = gson
            .fromJson(Utils.getRawResourceAsString(com.sensorberg.sdk.test.R.raw.resolve_response_enter_exit_action, InstrumentationRegistry
                    .getContext()), ResolveResponse.class);
    Mockito.when(mockRetrofitApiService.getBeacon(Mockito.anyString(), Mockito.anyString(), Matchers.<TreeMap<String, String>>any()))
            .thenReturn(Calls.response(resolveResponse));

    ResolverListener testListener = new ResolverListener() {
        @Override
        public void onResolutionFailed(Throwable cause, ScanEvent scanEvent) {
            Assert.fail(cause.getMessage());
        }

        @Override
        public void onResolutionsFinished(List<BeaconEvent> events) {
            Assertions.assertThat(events).hasSize(1);
        }
    };

    tested.setListener(testListener);
    tested.resolve(TestConstants.RESOLVABLE_ENTRY_EVENT_WITH_ID_3);
}
 
Example #5
Source Project: espresso-macchiato   Author: nenick   File: EspCameraStubTest.java    License: MIT License 7 votes vote down vote up
@Test
public void testCameraStubMultipleTimes() throws IOException {
    targetFile = new File(activity.getExternalCacheDir(), RESULT_JPG);
    assertFalse(targetFile.exists());

    Uri pictureUri = EspFilesTool.copyFileFromAssetsToExternalCacheDir(SAMPLE_JPG, RESULT_JPG);
    espCameraStub.register(pictureUri);

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
    activity.startForResult(intent, REQUEST_CODE);

    requestCodeTextView.assertTextIs(String.valueOf(REQUEST_CODE));

    InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            ((TextView) getActivity().findViewById(OnActivityResultActivity.requestCodeResource)).setText("");
        }
    });
    requestCodeTextView.assertTextIs("");

    activity.startForResult(intent, REQUEST_CODE);
    requestCodeTextView.assertTextIs(String.valueOf(REQUEST_CODE));
}
 
Example #6
Source Project: twittererer   Author: zfoltin   File: TimelineActivityTest.java    License: Apache License 2.0 7 votes vote down vote up
@Override
protected void beforeActivityLaunched() {
    super.beforeActivityLaunched();

    App.BaseApplicationComponent component = DaggerMockApplicationComponent.builder()
            .mockApplicationModule(new MockApplicationModule((App) InstrumentationRegistry.getTargetContext().getApplicationContext()))
            .build();
    App.overrideComponent(component);

    User bobUser = new User("Bob", "bob", "http://assets.rollingstone.com/assets/images/list_item/bob-marley-20110420/square.jpg");
    when(component.twitterService().getMyDetails()).thenReturn(Observable.just(bobUser));

    timelineItems = new ArrayList<>();
    timelineItems.add(new TimelineItem("10m", "hello", bobUser));
    when(component.twitterService().getTimelineItems()).thenReturn(Observable.just(timelineItems));

    when(component.twitterService().getCurrentUser()).thenReturn(bobUser);
    when(component.twitterService().sendTweet(anyString())).thenReturn(Observable.just(true));
}
 
Example #7
Source Project: Building-Professional-Android-Applications   Author: PacktPublishing   File: ExampleInstrumentedTest.java    License: MIT License 6 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.packt.madev", appContext.getPackageName());
}
 
Example #8
Source Project: unity-ads-android   Author: Unity-Technologies   File: WebViewAppTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSendEventShouldFail () throws Exception {
	WebViewApp.setCurrentApp(null);
	final ConditionVariable cv = new ConditionVariable();

	Handler handler = new Handler(Looper.getMainLooper());
	handler.post(new Runnable() {
		@Override
		public void run() {
			WebViewApp.setCurrentApp(new WebViewApp());
			WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
			WebViewApp.getCurrentApp().setWebAppInitialized(true);
			cv.open();
		}
	});

	boolean cvsuccess = cv.block(10000);
	assertTrue("ConditionVariable was not opened successfully", cvsuccess);
	boolean success = WebViewApp.getCurrentApp().sendEvent(MockEventCategory.TEST_CATEGORY_1, MockEvent.TEST_EVENT_1);
	assertFalse("sendEvent -method should've returned false", success);
	assertFalse("WebView invokeJavascript should've not been invoked but was (webviewapp is not loaded so no call should have occured)", ((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_INVOKED);
	assertNull("The invoked JavaScript string should be null (webviewapp is not loaded so no call should have occured)", ((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
 
Example #9
Source Project: play-licensing   Author: google   File: ObfuscatedPreferencesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void initFixture() {
    final byte[] SALT = new byte[] {
        104, -12, 112, 82, -85, -10, -11, 61, 15, 54, 44, -66, -117, -89, -64, 110, -53, 123, 33
    };

    // Prepare PreferenceObfuscator instance
    Context ctx = InstrumentationRegistry.getTargetContext();
    sp = ctx.getSharedPreferences(filename, Context.MODE_PRIVATE);
    String deviceId = Settings.Secure.getString(
            ctx.getContentResolver(),
            Settings.Secure.ANDROID_ID);
    Obfuscator o = new AESObfuscator(SALT, ctx.getPackageName(), deviceId);
    op = new PreferenceObfuscator(sp, o);

    // Populate with test data
    op.putString("testString", "Hello world");
    op.commit();
}
 
Example #10
Source Project: WebRTCapp   Author: sergiopaniego   File: ExampleInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.sergiopaniegoblanco.webrtcexampleapp", appContext.getPackageName());
}
 
Example #11
Source Project: YzyAddPicView   Author: yzytmac   File: ExampleInstrumentedTest.java    License: MIT License 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.example.addpicview", appContext.getPackageName());
}
 
Example #12
Source Project: iMoney   Author: xinpengfei520   File: ExampleInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.anloq.http.test", appContext.getPackageName());
}
 
Example #13
Source Project: RichWebList   Author: 756718646   File: ExampleInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.yongzheng.com.richwebproject", appContext.getPackageName());
}
 
Example #14
Source Project: android-sdk   Author: optimizely   File: UserProfileCacheTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws JSONException {
    logger = mock(Logger.class);
    projectId = "1";
    cache = new Cache(InstrumentationRegistry.getTargetContext(), logger);
    diskCache = new UserProfileCache.DiskCache(cache, executor, logger, projectId);
    legacyDiskCache = new UserProfileCache.LegacyDiskCache(cache, executor, logger, projectId);
    memoryCache = new ConcurrentHashMap<>();
    userProfileCache = new UserProfileCache(diskCache, logger, memoryCache, legacyDiskCache);

    // Test data.
    userId1 = "user_1";
    Map<String, Map<String, String>> experimentBucketMap1 = new ConcurrentHashMap<>();
    Map<String, String> decisionMap1 = new ConcurrentHashMap<>();
    decisionMap1.put("variation_id", "var_1");
    experimentBucketMap1.put("exp_1", decisionMap1);
    Map<String, String> decisionMap2 = new ConcurrentHashMap<>();
    decisionMap2.put("variation_id", "var_2");
    experimentBucketMap1.put("exp_2", decisionMap2);
    userProfileMap1 = new ConcurrentHashMap<>();
    userProfileMap1.put("user_id", userId1);
    userProfileMap1.put("experiment_bucket_map", experimentBucketMap1);

    userId2 = "user_2";
    Map<String, Map<String, String>> experimentBucketMap2 = new ConcurrentHashMap<>();
    Map<String, String> decisionMap3 = new ConcurrentHashMap<>();
    decisionMap3.put("variation_id", "var_3");
    experimentBucketMap2.put("exp_1", decisionMap3);
    Map<String, String> decisionMap4 = new ConcurrentHashMap<>();
    decisionMap4.put("variation_id", "var_4");
    experimentBucketMap2.put("exp_2", decisionMap4);
    userProfileMap2 = new ConcurrentHashMap<>();
    userProfileMap2.put("user_id", userId2);
    userProfileMap2.put("experiment_bucket_map", experimentBucketMap2);
}
 
Example #15
Source Project: secure-quick-reliable-login   Author: kalaspuffar   File: AccessibilityInstrumentedTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testIntroductionActivityAccessibility() throws Exception {
    Context targetContext = InstrumentationRegistry.getInstrumentation()
            .getTargetContext();
    Intent intent = new Intent(targetContext, IntroductionActivity.class);
    IntroductionActivity a = introductionActivityRule.launchActivity(intent);
    unlockScreen(a);

    onView(withId(R.id.introductionActivityView)).perform(click());
}
 
Example #16
Source Project: android-things-electricity-monitor   Author: riggaroo   File: ExampleInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("za.co.riggaroo.electricitymonitor", appContext.getPackageName());
}
 
Example #17
Source Project: HotFixDemo   Author: GitLqr   File: ExampleInstrumentedTest.java    License: MIT License 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.lqr.tinker_local", appContext.getPackageName());
}
 
Example #18
Source Project: journaldev   Author: journaldev   File: ExampleInstrumentedTest.java    License: MIT License 5 votes vote down vote up
@Test
public void useAppContext() {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.journaldev.dagger2retrofitrecyclerview", appContext.getPackageName());
}
 
Example #19
Source Project: JsDroidEditor   Author: coolwho   File: ExampleInstrumentedTest.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void useAppContext() {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.jsdroid.editor", appContext.getPackageName());
}
 
Example #20
Source Project: peppy-calendarview   Author: snollidea   File: ExampleInstrumentedTest.java    License: MIT License 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.snollidea.peppycalendarview.test", appContext.getPackageName());
}
 
Example #21
Source Project: Netty_Demo   Author: zhangYanGitHub   File: ExampleInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.zhang.netty_demo", appContext.getPackageName());
}
 
Example #22
Source Project: WeekCalendar   Author: loonggg   File: ExampleInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.loonggg.weekcalendar.test", appContext.getPackageName());
}
 
Example #23
Source Project: CheckHelper   Author: gminibird   File: ExampleInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.luwei.checkhelper.test", appContext.getPackageName());
}
 
Example #24
Source Project: AndroidProgramming3e   Author: rsippl   File: ExampleInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.bignerdranch.android.photogallery", appContext.getPackageName());
}
 
Example #25
Source Project: EasyBle   Author: Ficat   File: ExampleInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.ficat.sample", appContext.getPackageName());
}
 
Example #26
Source Project: TinyPinyin   Author: promeG   File: ExampleInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.github.promeg.tinypinyin.android.asset.lexicons.test",
            appContext.getPackageName());
}
 
Example #27
Source Project: android_viewtracker   Author: alibaba   File: ExampleInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.tmall.wireless.viewtracker", appContext.getPackageName());
}
 
Example #28
Source Project: RangeSeekBar   Author: sephiroth74   File: ExampleInstrumentedTest.java    License: MIT License 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("it.sephiroth.android.library.rangeseekbar.test", appContext.getPackageName());
}
 
Example #29
Source Project: codeexamples-android   Author: vogellacompany   File: ExampleInstrumentedTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.example.android.rssreader", appContext.getPackageName());
}
 
Example #30
Source Project: AAVT   Author: aiyaapp   File: ExampleInstrumentedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.wuwang.aavt", appContext.getPackageName());
}