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 File: MediaSessionPlaybackActivityTest.java    From android-PictureInPicture with 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 #2
Source File: TheResolverWithMockApiShould.java    From android-sdk with 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 #3
Source File: ExampleInstrumentedTest.java    From XmlToJson with 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 #4
Source File: SensorbergServiceInternalTests.java    From android-sdk with 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 #5
Source File: EspCameraStubTest.java    From espresso-macchiato with 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 File: TimelineActivityTest.java    From twittererer with 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 File: ExampleInstrumentedTest.java    From Building-Professional-Android-Applications with 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 File: WebViewAppTest.java    From unity-ads-android with 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 File: ObfuscatedPreferencesTest.java    From play-licensing with 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 File: ExampleInstrumentedTest.java    From YViewPagerDemo with 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("cn.youngkaaa.yviewpager.test", appContext.getPackageName());
}
 
Example #11
Source File: ExampleInstrumentedTest.java    From LogCollector with 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("cn.ljuns.logcollector", appContext.getPackageName());
}
 
Example #12
Source File: ExampleInstrumentedTest.java    From ApplicationHelper with 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.lzw.applicationhelper", appContext.getPackageName());
}
 
Example #13
Source File: ExampleInstrumentedTest.java    From CombineBitmap with 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.othershe.combinebitmaptest", appContext.getPackageName());
}
 
Example #14
Source File: ExampleInstrumentedTest.java    From Android-MVP with 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("cn.com.jerry.mvplib.test", appContext.getPackageName());
}
 
Example #15
Source File: ExampleInstrumentedTest.java    From RxAndroid-Examples with 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("me.shuza.rxdatabinding", appContext.getPackageName());
}
 
Example #16
Source File: ExampleInstrumentedTest.java    From CardViewShadowColor with 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.zyp.cardview", appContext.getPackageName());
}
 
Example #17
Source File: ExampleInstrumentedTest.java    From RairDemo with 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.rair.wifidemo", appContext.getPackageName());
}
 
Example #18
Source File: ApplicationTest.java    From Travel-Mate with MIT License 5 votes vote down vote up
@Test
public void useAppContext() {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("io.github.project_travel_mate", appContext.getPackageName());
}
 
Example #19
Source File: ExampleInstrumentedTest.java    From EasySettings with 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.hotmail.or_dvir.easysettings_dialogs.test", appContext.getPackageName());
}
 
Example #20
Source File: ExampleInstrumentedTest.java    From TabRadioButton with 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.zaaach.tabradiobuttongithub", appContext.getPackageName());
}
 
Example #21
Source File: ExampleInstrumentedTest.java    From ChannelView with 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.cheng.channelview.test", appContext.getPackageName());
}
 
Example #22
Source File: ExampleInstrumentedTest.java    From Socket.io-FLSocketIM-Android with 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.foxpower.flchatofandroid", appContext.getPackageName());
}
 
Example #23
Source File: ExampleInstrumentedTest.java    From ImagePicker with 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.lancewu.imagepickerdemo", appContext.getPackageName());
}
 
Example #24
Source File: ExampleInstrumentedTest.java    From Flora with MIT License 5 votes vote down vote up
@Test
public void useAppContext() {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.jascal.tensor", appContext.getPackageName());
}
 
Example #25
Source File: ExampleInstrumentedTest.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void useAppContext() {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("me.mahakagg.ordernavigation", appContext.getPackageName());
}
 
Example #26
Source File: ExampleInstrumentedTest.java    From PoyntSamples with 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.sampleloyaltyapp", appContext.getPackageName());
}
 
Example #27
Source File: AccessibilityInstrumentedTest.java    From secure-quick-reliable-login with MIT License 5 votes vote down vote up
@Test
public void testLoginActivityAccessibility() throws Exception {
    Context targetContext = InstrumentationRegistry.getInstrumentation()
            .getTargetContext();
    Intent intent = new Intent(targetContext, LoginActivity.class);
    intent.putExtra("RUNNING_TEST", true);
    LoginActivity a = loginActivityRule.launchActivity(intent);
    unlockScreen(a);

    onView(withId(R.id.loginActivityView)).perform(click());
}
 
Example #28
Source File: ExampleInstrumentedTest.java    From RxSharedPreferences with 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("florent37.github.com.rxsharedpreferences", appContext.getPackageName());
}
 
Example #29
Source File: ExampleInstrumentedTest.java    From AndroidProgramming3e with 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.sunset", appContext.getPackageName());
}
 
Example #30
Source File: ExampleInstrumentedTest.java    From Stark with 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.ximsfei.stark.core.test", appContext.getPackageName());
}