org.robolectric.annotation.Config Java Examples

The following examples show how to use org.robolectric.annotation.Config. 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: KeychainModuleTests.java    From react-native-keychain with MIT License 6 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.P)
public void testGetSecurityLevel_NoBiometry_api28() throws Exception {
  // GIVE:
  final ReactApplicationContext context = getRNContext();
  final KeychainModule module = new KeychainModule(context);
  final Promise mockPromise = mock(Promise.class);

  // WHEN:
  final JavaOnlyMap options = new JavaOnlyMap();
  options.putString(Maps.ACCESS_CONTROL, AccessControl.DEVICE_PASSCODE);

  module.getSecurityLevel(options, mockPromise);

  // THEN:
  verify(mockPromise).resolve(SecurityLevel.SECURE_HARDWARE.name());
}
 
Example #2
Source File: JobSchedulerTest.java    From JobSchedulerCompat with MIT License 6 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.N, shadows = {ShadowGoogleApiAvailability.class})
public void testSchedulerInApi24() {
    JobInfo api21Job = JobCreator.create(application).setRequiresCharging(true).build();
    JobInfo api24Job = JobCreator.create(application).setPeriodic(15 * 60 * 1000L, 5 * 60 * 1000L).build();
    JobInfo api26Job = JobCreator.create(application).setRequiresBatteryNotLow(true).build();

    ShadowGoogleApiAvailability.setIsGooglePlayServicesAvailable(ConnectionResult.SERVICE_MISSING);

    assertThat(jobScheduler.getSchedulerForJob(application, api21Job), instanceOf(JobSchedulerSchedulerV24.class));
    assertThat(jobScheduler.getSchedulerForJob(application, api24Job), instanceOf(JobSchedulerSchedulerV24.class));
    assertThat(jobScheduler.getSchedulerForJob(application, api26Job), instanceOf(AlarmScheduler.class));

    ShadowGoogleApiAvailability.setIsGooglePlayServicesAvailable(ConnectionResult.SUCCESS);

    assertThat(jobScheduler.getSchedulerForJob(application, api21Job), instanceOf(JobSchedulerSchedulerV24.class));
    assertThat(jobScheduler.getSchedulerForJob(application, api24Job), instanceOf(JobSchedulerSchedulerV24.class));
    assertThat(jobScheduler.getSchedulerForJob(application, api26Job), instanceOf(AlarmScheduler.class));
}
 
Example #3
Source File: CipherStorageKeystoreRsaEcbTests.java    From react-native-keychain with MIT License 6 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.P)
public void testVerifySecureHardwareAvailability_api28() throws Exception {
  ReactApplicationContext context = getRNContext();

  // for api24+ system feature should be enabled
  shadowOf(context.getPackageManager()).setSystemFeature(PackageManager.FEATURE_FINGERPRINT, true);

  // set that hardware is available and fingerprints configured
  final FingerprintManager fm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
  shadowOf(fm).setIsHardwareDetected(true);
  shadowOf(fm).setDefaultFingerprints(5); // 5 fingerprints are available

  int result = BiometricManager.from(context).canAuthenticate();
  assertThat(result, is(BiometricManager.BIOMETRIC_SUCCESS));

  final CipherStorage storage = new CipherStorageKeystoreAesCbc();;

  // expected RsaEcb with fingerprint
  assertThat(storage.supportsSecureHardware(), is(true));
}
 
Example #4
Source File: JobSchedulerTest.java    From JobSchedulerCompat with MIT License 6 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.LOLLIPOP, shadows = {ShadowGoogleApiAvailability.class})
public void testSchedulerInApi21() {
    JobInfo api21Job = JobCreator.create(application).setRequiresCharging(true).build();
    JobInfo api24Job = JobCreator.create(application).setPeriodic(15 * 60 * 1000L, 5 * 60 * 1000L).build();
    JobInfo api26Job = JobCreator.create(application).setRequiresBatteryNotLow(true).build();

    ShadowGoogleApiAvailability.setIsGooglePlayServicesAvailable(ConnectionResult.SERVICE_MISSING);

    assertThat(jobScheduler.getSchedulerForJob(application, api21Job), instanceOf(JobSchedulerSchedulerV21.class));
    assertThat(jobScheduler.getSchedulerForJob(application, api24Job), instanceOf(AlarmScheduler.class));
    assertThat(jobScheduler.getSchedulerForJob(application, api26Job), instanceOf(AlarmScheduler.class));

    ShadowGoogleApiAvailability.setIsGooglePlayServicesAvailable(ConnectionResult.SUCCESS);

    assertThat(jobScheduler.getSchedulerForJob(application, api21Job), instanceOf(JobSchedulerSchedulerV21.class));
    assertThat(jobScheduler.getSchedulerForJob(application, api24Job), instanceOf(GcmScheduler.class));
    assertThat(jobScheduler.getSchedulerForJob(application, api26Job), instanceOf(AlarmScheduler.class));
}
 
Example #5
Source File: JobProxyTest.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Test
@Config(sdk = 21)
public void verifyNoRecoverWithAlarmManager() throws Exception {
    Context context = BaseJobManagerTest.createMockContext();
    Context applicationContext = context.getApplicationContext();

    AlarmManager alarmManager = getAlarmManager(applicationContext);

    when(applicationContext.getSystemService(Context.ALARM_SERVICE)).thenReturn(null);
    when(applicationContext.getSystemService(Context.JOB_SCHEDULER_SERVICE)).thenReturn(null);

    JobManager.create(context);

    new JobRequest.Builder("tag")
            .setExecutionWindow(200_000, 300_000)
            .build()
            .schedule();

    verifyAlarmCount(alarmManager, 0);
}
 
Example #6
Source File: JobSchedulerTest.java    From JobSchedulerCompat with MIT License 6 votes vote down vote up
@Test
@Config(sdk = {Build.VERSION_CODES.O, Build.VERSION_CODES.P}, shadows = {ShadowGoogleApiAvailability.class})
public void testSchedulerInApi26() {
    JobInfo api21Job = JobCreator.create(application).setRequiresCharging(true).build();
    JobInfo api24Job = JobCreator.create(application).setPeriodic(15 * 60 * 1000L, 5 * 60 * 1000L).build();
    JobInfo api26Job = JobCreator.create(application).setRequiresBatteryNotLow(true).build();

    ShadowGoogleApiAvailability.setIsGooglePlayServicesAvailable(ConnectionResult.SERVICE_MISSING);

    assertThat(jobScheduler.getSchedulerForJob(application, api21Job), instanceOf(JobSchedulerSchedulerV26.class));
    assertThat(jobScheduler.getSchedulerForJob(application, api24Job), instanceOf(JobSchedulerSchedulerV26.class));
    assertThat(jobScheduler.getSchedulerForJob(application, api26Job), instanceOf(JobSchedulerSchedulerV26.class));

    ShadowGoogleApiAvailability.setIsGooglePlayServicesAvailable(ConnectionResult.SUCCESS);

    assertThat(jobScheduler.getSchedulerForJob(application, api21Job), instanceOf(JobSchedulerSchedulerV26.class));
    assertThat(jobScheduler.getSchedulerForJob(application, api24Job), instanceOf(JobSchedulerSchedulerV26.class));
    assertThat(jobScheduler.getSchedulerForJob(application, api26Job), instanceOf(JobSchedulerSchedulerV26.class));
}
 
Example #7
Source File: CryptoUtilTest.java    From Auth0.Android with MIT License 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.P)
@Test
@Config(sdk = 28)
public void shouldUseExistingRSAKeyPairRebuildingTheEntryOnAPI28AndUp() throws Exception {
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 28);
    KeyStore.PrivateKeyEntry entry = PowerMockito.mock(KeyStore.PrivateKeyEntry.class);
    PrivateKey privateKey = PowerMockito.mock(PrivateKey.class);
    Certificate certificate = PowerMockito.mock(Certificate.class);

    ArgumentCaptor<Object> varargsCaptor = ArgumentCaptor.forClass(Object.class);
    PowerMockito.when(keyStore.containsAlias(KEY_ALIAS)).thenReturn(true);
    PowerMockito.when(keyStore.getKey(KEY_ALIAS, null)).thenReturn(privateKey);
    PowerMockito.when(keyStore.getCertificate(KEY_ALIAS)).thenReturn(certificate);
    PowerMockito.whenNew(KeyStore.PrivateKeyEntry.class).withAnyArguments().thenReturn(entry);

    KeyStore.PrivateKeyEntry rsaEntry = cryptoUtil.getRSAKeyEntry();
    PowerMockito.verifyNew(KeyStore.PrivateKeyEntry.class).withArguments(varargsCaptor.capture());
    assertThat(rsaEntry, is(notNullValue()));
    assertThat(rsaEntry, is(entry));
    assertThat(varargsCaptor.getAllValues(), is(notNullValue()));
    PrivateKey capturedPrivateKey = (PrivateKey) varargsCaptor.getAllValues().get(0);
    Certificate[] capturedCertificatesArray = (Certificate[]) varargsCaptor.getAllValues().get(1);
    assertThat(capturedPrivateKey, is(privateKey));
    assertThat(capturedCertificatesArray[0], is(certificate));
    assertThat(capturedCertificatesArray.length, is(1));
}
 
Example #8
Source File: CustomRobolectricTestRunner.java    From Freezer with Apache License 2.0 6 votes vote down vote up
@Override
protected AndroidManifest getAppManifest(Config config) {
    String path = PATH_MANIFEST;

    // android studio has a different execution root for tests than pure gradle
    // so we avoid here manual effort to get them running inside android studio
    if (!new File(path).exists()) {
        path = PATH_PREFIX + path;
    }

    config = overwriteConfig(config, CONFIG_MANIFEST, path);
    config = overwriteConfig(config, CONFIG_ASSET_DIR, PATH_ASSET);
    config = overwriteConfig(config, CONFIG_RESOURCE_DIR, PATH_RESOURCE);
    config = overwriteConfig(config, CONFIG_PACKAGE_NAME, PACKAGE_NAME);

    return super.getAppManifest(config);
}
 
Example #9
Source File: CctTransportBackendTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@Config(shadows = {OfflineConnectivityManagerShadow.class})
public void decorate_whenOffline_shouldProperlyPopulateNetworkInfo() {
  CctTransportBackend backend =
      new CctTransportBackend(RuntimeEnvironment.application, wallClock, uptimeClock, 300);

  EventInternal result =
      backend.decorate(
          EventInternal.builder()
              .setEventMillis(INITIAL_WALL_TIME)
              .setUptimeMillis(INITIAL_UPTIME)
              .setTransportName("3")
              .setEncodedPayload(new EncodedPayload(PROTOBUF_ENCODING, PAYLOAD.toByteArray()))
              .build());

  assertThat(result.get(CctTransportBackend.KEY_NETWORK_TYPE))
      .isEqualTo(String.valueOf(NetworkConnectionInfo.NetworkType.NONE.getValue()));
  assertThat(result.get(CctTransportBackend.KEY_MOBILE_SUBTYPE))
      .isEqualTo(
          String.valueOf(NetworkConnectionInfo.MobileSubtype.UNKNOWN_MOBILE_SUBTYPE.getValue()));
}
 
Example #10
Source File: JobSchedulerSchedulerTest.java    From JobSchedulerCompat with MIT License 6 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.P)
public void testScheduleJobWithPieOption() {
    JobInfo.Builder builder = createJob(1);
    builder.setRequiredNetwork(
            new NetworkRequest.Builder()
                    .addCapability(NET_CAPABILITY_INTERNET)
                    .addCapability(NET_CAPABILITY_VALIDATED)
                    .removeCapability(NET_CAPABILITY_NOT_VPN)
                    .addCapability(NET_CAPABILITY_NOT_ROAMING)
                    .build());
    builder.setEstimatedNetworkBytes(1024, 128);
    builder.setImportantWhileForeground(true);
    builder.setPrefetch(true);
    JobInfo job = builder.build();

    scheduler.schedule(job);

    android.app.job.JobInfo nativeJob = getPendingJob(job.getId());
    assertNotNull(nativeJob);
    assertNativeJobInfoMatchesJobInfo(nativeJob, job);
}
 
Example #11
Source File: RobolectricGradleTestRunner.java    From android-alltest-gradle-sample with GNU General Public License v2.0 6 votes vote down vote up
@Override
 protected AndroidManifest getAppManifest(Config config) {
   //String appRoot = "D:\\TmpCodingProjects\\TripComputer\\app\\src\\main\\";
   String appRoot = "../app/src/main/";
   String manifestPath = appRoot + "AndroidManifest.xml";
   String resDir = appRoot + "res";
   String assetsDir = appRoot + "assets";
   AndroidManifest manifest = createAppManifest(Fs.fileFromPath(manifestPath),
     Fs.fileFromPath(resDir),
     Fs.fileFromPath(assetsDir));

// If you change the package - don't forget to change the build.gradle and the AndroidManifest.xml
   manifest.setPackageName("com.soagrowers.android");
   // Robolectric is already going to look in the  'app' dir ...
   // so no need to add to package name
   return manifest;
 }
 
Example #12
Source File: JobProxyTest.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Test
@Config(sdk = 21)
public void verifyMaxExecutionDelayIsNotSetInJobScheduler() {
    Context context = BaseJobManagerTest.createMockContext();
    Context applicationContext = context.getApplicationContext();

    JobScheduler scheduler = getJobScheduler(applicationContext);
    when(applicationContext.getSystemService(Context.JOB_SCHEDULER_SERVICE)).thenReturn(scheduler);

    JobManager.create(context);

    new JobRequest.Builder("tag")
            .setExecutionWindow(3_000L, 4_000L)
            .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED)
            .setRequirementsEnforced(true)
            .build()
            .schedule();

    List<JobInfo> allPendingJobs = scheduler.getAllPendingJobs();
    assertThat(allPendingJobs).hasSize(1);

    JobInfo jobInfo = allPendingJobs.get(0);
    assertThat(jobInfo.getMinLatencyMillis()).isEqualTo(3_000L);
    assertThat(jobInfo.getMaxExecutionDelayMillis()).isGreaterThan(4_000L);
}
 
Example #13
Source File: CircularRevealHelperTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@Config(sdk = VERSION_CODES.JELLY_BEAN)
public void jbDrawsScrim() {
  helper = new CircularRevealHelper(delegate);
  helper.setCircularRevealScrimColor(Color.RED);

  helper.setRevealInfo(smallRevealInfo);

  helper.buildCircularRevealCache();
  helper.draw(canvas);
  helper.destroyCircularRevealCache();

  // Once for the BitmapShader, once for the scrim.
  verify(canvas, times(2))
      .drawCircle(
          eq(smallRevealInfo.centerX),
          eq(smallRevealInfo.centerY),
          eq(smallRevealInfo.radius),
          ArgumentMatchers.<Paint>any());
}
 
Example #14
Source File: CrossbowImageTest.java    From CrossBow with Apache License 2.0 6 votes vote down vote up
@Test
public void testImageFadeDrawable() {
    ColorDrawable defaultDrawable = new ColorDrawable(Color.BLUE);

    CrossbowImage.Builder builder = new CrossbowImage.Builder(RuntimeEnvironment.application, null, null);
    builder.placeholder(defaultDrawable);
    builder.scale(ImageView.ScaleType.CENTER);
    builder.fade(200);
    CrossbowImage crossbowImage = builder.into(imageView).load();

    Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ALPHA_8);
    crossbowImage.setBitmap(bitmap, false);

    TransitionDrawable drawable = (TransitionDrawable) imageView.getDrawable();
    assertTrue(drawable.getNumberOfLayers() == 2);
}
 
Example #15
Source File: ForageRoboelectricIntegrationTestRunner.java    From Forage with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public Config getConfig(@NonNull Method method) {
    final Config defaultConfig = super.getConfig(method);
    return new Config.Implementation(
            new int[]{SDK_EMULATE_LEVEL},
            defaultConfig.manifest(),
            defaultConfig.qualifiers(),
            defaultConfig.packageName(),
            defaultConfig.abiSplit(),
            defaultConfig.resourceDir(),
            defaultConfig.assetDir(),
            defaultConfig.buildDir(),
            defaultConfig.shadows(),
            defaultConfig.instrumentedPackages(),
            ForageUnitTestApplication.class,
            defaultConfig.libraries(),
            defaultConfig.constants() == Void.class ? BuildConfig.class : defaultConfig.constants()
    );
}
 
Example #16
Source File: LolipopLEScannerTest.java    From neatle with MIT License 6 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.LOLLIPOP)
public void startScanWithUuidsOnLollipop() {
    BluetoothAdapter testAdapter = Mockito.mock(BluetoothAdapter.class);
    Mockito.when(testAdapter.startLeScan(Mockito.<UUID[]>any(),
            Mockito.<BluetoothAdapter.LeScanCallback>any())).thenReturn(true);

    LolipopLEScanner scanner = new LolipopLEScanner(TEST_CONFIGURATION);

    scanner.onStart(testAdapter, 0);

    Mockito.verify(testAdapter, Mockito.only()).startLeScan(Mockito.argThat(new ArgumentMatcher<UUID[]>() {
        @Override
        public boolean matches(UUID[] uuids) {
            return uuids.length == 1 && TEST_UUID.equals(uuids[0]);
        }
    }), Mockito.<BluetoothAdapter.LeScanCallback>any());
}
 
Example #17
Source File: JobExecutionTest.java    From android-job with Apache License 2.0 5 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.M)
public void verifyNotFoundJobCanceledPeriodicFlexSupport() {
    final String tag = "something";
    final int jobId = new JobRequest.Builder(tag)
            .setPeriodic(TimeUnit.HOURS.toMillis(4))
            .build()
            .schedule();

    assertThat(manager().getAllJobRequestsForTag(tag)).hasSize(1);
    executeJob(jobId, Job.Result.FAILURE);
    assertThat(manager().getAllJobRequestsForTag(tag)).isEmpty();
}
 
Example #18
Source File: CipherStorageKeystoreRsaEcbTests.java    From react-native-keychain with MIT License 5 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.M)
public void testGetSecurityLevel_api23() throws Exception {
  final CipherStorageKeystoreAesCbc instance = new CipherStorageKeystoreAesCbc();
  final Key mock = Mockito.mock(SecretKey.class);

  final SecurityLevel level = instance.getSecurityLevel(mock);

  assertThat(level, is(SecurityLevel.SECURE_HARDWARE));
}
 
Example #19
Source File: AndroidVersionUtilsTest.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Config(sdk = Build.VERSION_CODES.N)
@Test
public void testAgainstNougat() {
  assertFalse(AndroidVersionUtils.isApiLevelAtLeastOreo());
  assertTrue(AndroidVersionUtils.isApiLevelAtLeastNougat());
  assertTrue(AndroidVersionUtils.isApiLevelAtLeastMarshmallow());
}
 
Example #20
Source File: AndroidVersionUtilsTest.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Config(sdk = Build.VERSION_CODES.M)
@Test
public void testAgainstMarshmallow() {
  assertFalse(AndroidVersionUtils.isApiLevelAtLeastOreo());
  assertFalse(AndroidVersionUtils.isApiLevelAtLeastNougat());
  assertTrue(AndroidVersionUtils.isApiLevelAtLeastMarshmallow());
}
 
Example #21
Source File: AndroidVersionUtilsTest.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Config(sdk = Build.VERSION_CODES.LOLLIPOP)
@Test
public void testAgainstLollipop() {
  assertFalse(AndroidVersionUtils.isApiLevelAtLeastOreo());
  assertFalse(AndroidVersionUtils.isApiLevelAtLeastNougat());
  assertFalse(AndroidVersionUtils.isApiLevelAtLeastMarshmallow());
}
 
Example #22
Source File: KeychainModuleTests.java    From react-native-keychain with MIT License 5 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.LOLLIPOP)
public void testGetSecurityLevel_Unspecified_api21() throws Exception {
  // GIVE:
  final ReactApplicationContext context = getRNContext();
  final KeychainModule module = new KeychainModule(context);
  final Promise mockPromise = mock(Promise.class);

  // WHEN:
  module.getSecurityLevel(null, mockPromise);

  // THEN:
  verify(mockPromise).resolve(SecurityLevel.ANY.name());
}
 
Example #23
Source File: WidgetProviderTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Config(sdk = 21)
@Test
public void testJobAfterReboot() {
    // rebooting should update widget again via update broadcast
    widgetProvider.onReceive(RuntimeEnvironment.application,
            new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE)
                    .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]{appWidgetId}));
    assertThat(((ShadowJobScheduler.ShadowJobSchedulerImpl) shadowOf(jobScheduler))
            .getAllPendingJobs()).isNotEmpty();
}
 
Example #24
Source File: AppSizeUtilTest.java    From AndroidGodEye with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 5000)
@Config(sdk = Build.VERSION_CODES.LOLLIPOP)
public void getAppSizeLowerO() {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    final AppSizeInfo[] appSizeInfo = new AppSizeInfo[1];
    AppSizeUtil.getAppSize(ApplicationProvider.getApplicationContext(), new AppSizeUtil.OnGetSizeListener() {
        @Override
        public void onGetSize(AppSizeInfo ctAppSizeInfo) {
            countDownLatch.countDown();
            appSizeInfo[0] = ctAppSizeInfo;
        }

        @Override
        public void onError(Throwable t) {
            countDownLatch.countDown();
        }
    });
    try {
        countDownLatch.await(3, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        Assert.fail();
    }
    Log4Test.d(String.valueOf(appSizeInfo[0]));
    Assert.assertTrue(appSizeInfo[0].dataSize >= 0);
    Assert.assertTrue(appSizeInfo[0].codeSize >= 0);
    Assert.assertTrue(appSizeInfo[0].cacheSize >= 0);
}
 
Example #25
Source File: NotifierTest.java    From AndroidGodEye with Apache License 2.0 5 votes vote down vote up
private void notice() {
    Notification notification = Notifier.create(ApplicationProvider.getApplicationContext(), new Notifier.Config("AndroidGodEye-Title", "AndroidGodEye-Message"));
    int id = Notifier.notice(ApplicationProvider.getApplicationContext(), Notifier.createNoticeId(), notification);
    ThreadHelper.sleep(10);
    Notifier.cancelNotice(ApplicationProvider.getApplicationContext(), id);

    int id2 = Notifier.notice(ApplicationProvider.getApplicationContext(), new Notifier.Config("AndroidGodEye-Title", "AndroidGodEye-Message"));
    ThreadHelper.sleep(10);
    Notifier.cancelNotice(ApplicationProvider.getApplicationContext(), id2);
}
 
Example #26
Source File: FavoriteActivityTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Config(shadows = {ShadowRecyclerView.class, ShadowItemTouchHelper.class})
@Test
public void testSwipeToRefresh() {
    RecyclerView.ViewHolder holder = shadowAdapter.getViewHolder(0);
    customShadowOf(recyclerView).getItemTouchHelperCallback()
            .onSwiped(holder, ItemTouchHelper.RIGHT);
    verify(syncScheduler).scheduleSync(any(), any());
}
 
Example #27
Source File: RippleUtilsTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
@Config(sdk = VERSION_CODES.P)
public void testValidateColor_transparentDefaultColor_returnsSelf_pie_noWarning() {
  ColorStateList rippleColor = createTransparentDefaultColor();
  assertThat(RippleUtils.sanitizeRippleDrawableColor(rippleColor)).isEqualTo(rippleColor);
  ShadowLog.getLogsForTag(RippleUtils.LOG_TAG).isEmpty();
}
 
Example #28
Source File: RateThisAppTest.java    From Android-RateThisApp with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRateDialogIfNeeded_LaunchTimeIsCorrect() {
    Context context = RuntimeEnvironment.application.getApplicationContext();

    RateThisApp.init(new RateThisApp.Config(1, 3));

    RateThisApp.onStart(context);
    Assert.assertFalse(RateThisApp.shouldShowRateDialog());
    RateThisApp.onStart(context);
    Assert.assertFalse(RateThisApp.shouldShowRateDialog());
    RateThisApp.onStart(context);
    Assert.assertTrue(RateThisApp.shouldShowRateDialog());
    RateThisApp.onStart(context);
    Assert.assertTrue(RateThisApp.shouldShowRateDialog());
}
 
Example #29
Source File: LolipopLEScannerTest.java    From neatle with MIT License 5 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.KITKAT)
public void startScanWithUuidsOnKitkat() {
    BluetoothAdapter testAdapter = Mockito.mock(BluetoothAdapter.class);
    Mockito.when(testAdapter.startLeScan(Mockito.<BluetoothAdapter.LeScanCallback>any())).thenReturn(true);
    LolipopLEScanner scanner = new LolipopLEScanner(TEST_CONFIGURATION);

    scanner.onStart(testAdapter, 0);

    Mockito.verify(testAdapter, Mockito.only()).startLeScan(Mockito.<BluetoothAdapter.LeScanCallback>any());
}
 
Example #30
Source File: DownloaderTest.java    From external-resources with Apache License 2.0 5 votes vote down vote up
@Config(sdk = LOLLIPOP) @Test public void testBuildUrlOnLollipop() throws Exception {
  setDefaultConfiguration();
  DefaultUrl url = new DefaultUrl(BASE_URL);
  Downloader downloader = new Downloader(context, converter, url, options);

  downloader.buildUrl();
  String urlString = url.build();

  assertThat("Contains orientation", urlString, containsString("orientation=" + ORIENTATION));
  assertThat("Contains keyboard", urlString, containsString("keyboard=" + KEYBOARD));
  assertThat("Contains touch_screen", urlString, containsString("touch_screen=" + TOUCH_SCREEN));
  assertThat("Contains font_scale", urlString, containsString("font_scale=" + FONT_SCALE));
  assertThat("Contains mcc", urlString, containsString("mcc=" + MCC));
  assertThat("Contains navigation_hidden", urlString,
      containsString("navigation_hidden=" + NAVIGATION_HIDDEN));
  assertThat("Contains locale", urlString, containsString("locale=" + LOCALE));
  assertThat("Contains smallest_screen_width_dp", urlString,
      containsString("smallest_screen_width_dp=" + SMALLEST_SCREEN_WIDTH_DP));
  assertThat("Contains keyboard_hidden", urlString,
      containsString("keyboard_hidden=" + KEYBOARD_HIDDEN));
  assertThat("Contains navigation", urlString, containsString("navigation=" + NAVIGATION));
  assertThat("Contains screen_layout", urlString,
      containsString("screen_layout=" + SCREEN_LAYOUT));
  assertThat("Contains screen_height_dp", urlString,
      containsString("screen_height_dp=" + SCREEN_HEIGHT_DP));
  assertThat("Contains mnc", urlString, containsString("mnc=" + MNC));
  assertThat("Contains ui_mode", urlString, containsString("ui_mode=" + UI_MODE));
  assertThat("Contains hard_keyboard_hidden", urlString,
      containsString("hard_keyboard_hidden=" + HARD_KEYBOARD_HIDDEN));
  assertThat("Contains density_dpi", urlString, containsString("density_dpi=" + DENSITY_DPI));
}