private void assertNotCountedDown(CountDownLatch countDownLatch) throws InterruptedException { // We are asserting that another thread does not count down the latch. We therefore sleep some // time to give the other thread the chance to fail this test. Thread.sleep(50); assertThat(countDownLatch.getCount()).isGreaterThan(0L); }
@Before public void setUp() throws Exception { database = SQLiteDatabase.create(null); database.execSQL("create table " + TABLE_NAME + " (" + COL_VALUE + " TEXT, " + COL_GROUP + " INTEGER" + ")"); ContentValues values = new ContentValues(); values.put(COL_VALUE, "record1"); values.put(COL_GROUP, 1); firstRecordId = database.insert(TABLE_NAME, null, values); assertThat(firstRecordId).isGreaterThan(0L); values.clear(); values.put(COL_VALUE, "record2"); values.put(COL_GROUP, 1); long secondRecordId = database.insert(TABLE_NAME, null, values); assertThat(secondRecordId).isGreaterThan(0L); assertThat(secondRecordId).isNotEqualTo(firstRecordId); values.clear(); values.put(COL_VALUE, "won't be selected"); values.put(COL_GROUP, 2); database.insert(TABLE_NAME, null, values); builder = new SQLiteQueryBuilder(); builder.setTables(TABLE_NAME); builder.appendWhere(COL_VALUE + " <> "); builder.appendWhereEscapeString("won't be selected"); }
@Test public void testWriteOnClose() throws Exception { Path path = Paths.get(URI.create("gs://greenbean/adipose")); try (SeekableByteChannel chan = Files.newByteChannel(path, WRITE)) { // writing lots of contents to defeat channel-internal buffering. for (int i = 0; i < 9999; i++) { for (String s : FILE_CONTENTS) { chan.write(ByteBuffer.wrap(s.getBytes(UTF_8))); } } try { Files.size(path); // we shouldn't make it to this line. Not using thrown.expect because // I still want to run a few lines after the exception. assertThat(false).isTrue(); } catch (NoSuchFileException nsf) { // that's what we wanted, we're good. } } // channel now closed, the file should be there and with the new contents. assertThat(Files.exists(path)).isTrue(); assertThat(Files.size(path)).isGreaterThan(100L); }
@Test public void defaultInitialBitrateEstimate_forWifi_isGreaterThanEstimateFor2G() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeterWifi = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateWifi = bandwidthMeterWifi.getBitrateEstimate(); setActiveNetworkInfo(networkInfo2g); DefaultBandwidthMeter bandwidthMeter2g = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); assertThat(initialEstimateWifi).isGreaterThan(initialEstimate2g); }
@Test public void defaultInitialBitrateEstimate_for4G_isGreaterThanEstimateFor3G() { setActiveNetworkInfo(networkInfo4g); DefaultBandwidthMeter bandwidthMeter4g = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate(); setActiveNetworkInfo(networkInfo3g); DefaultBandwidthMeter bandwidthMeter3g = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); assertThat(initialEstimate4g).isGreaterThan(initialEstimate3g); }
@Test public void defaultInitialBitrateEstimate_forWifi_isGreaterThanEstimateFor3G() { setActiveNetworkInfo(networkInfoWifi); DefaultBandwidthMeter bandwidthMeterWifi = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateWifi = bandwidthMeterWifi.getBitrateEstimate(); setActiveNetworkInfo(networkInfo3g); DefaultBandwidthMeter bandwidthMeter3g = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); assertThat(initialEstimateWifi).isGreaterThan(initialEstimate3g); }
@Test public void defaultInitialBitrateEstimate_forEthernet_isGreaterThanEstimateFor3G() { setActiveNetworkInfo(networkInfoEthernet); DefaultBandwidthMeter bandwidthMeterEthernet = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateEthernet = bandwidthMeterEthernet.getBitrateEstimate(); setActiveNetworkInfo(networkInfo3g); DefaultBandwidthMeter bandwidthMeter3g = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate3g); }
@Test public void defaultInitialBitrateEstimate_for4G_isGreaterThanEstimateFor2G() { setActiveNetworkInfo(networkInfo4g); DefaultBandwidthMeter bandwidthMeter4g = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimate4g = bandwidthMeter4g.getBitrateEstimate(); setActiveNetworkInfo(networkInfo2g); DefaultBandwidthMeter bandwidthMeter2g = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); assertThat(initialEstimate4g).isGreaterThan(initialEstimate2g); }
@Test public void defaultInitialBitrateEstimate_for3G_isGreaterThanEstimateFor2G() { setActiveNetworkInfo(networkInfo3g); DefaultBandwidthMeter bandwidthMeter3g = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimate3g = bandwidthMeter3g.getBitrateEstimate(); setActiveNetworkInfo(networkInfo2g); DefaultBandwidthMeter bandwidthMeter2g = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); assertThat(initialEstimate3g).isGreaterThan(initialEstimate2g); }
@Test public void defaultInitialBitrateEstimate_forEthernet_isGreaterThanEstimateFor2G() { setActiveNetworkInfo(networkInfoEthernet); DefaultBandwidthMeter bandwidthMeterEthernet = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateEthernet = bandwidthMeterEthernet.getBitrateEstimate(); setActiveNetworkInfo(networkInfo2g); DefaultBandwidthMeter bandwidthMeter2g = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimate2g = bandwidthMeter2g.getBitrateEstimate(); assertThat(initialEstimateEthernet).isGreaterThan(initialEstimate2g); }
assertThat(actionFile.length()).isGreaterThan(0L); assertCacheEmpty(cache);
@Test public void defaultInitialBitrateEstimate_forWifi_forFastCountry_isGreaterThanEstimateForSlowCountry() { setActiveNetworkInfo(networkInfoWifi); setNetworkCountryIso(FAST_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterFast = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); setNetworkCountryIso(SLOW_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterSlow = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); }
@Test public void defaultInitialBitrateEstimate_forEthernet_forFastCountry_isGreaterThanEstimateForSlowCountry() { setActiveNetworkInfo(networkInfoEthernet); setNetworkCountryIso(FAST_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterFast = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); setNetworkCountryIso(SLOW_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterSlow = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); }
@Test public void defaultInitialBitrateEstimate_for2G_forFastCountry_isGreaterThanEstimateForSlowCountry() { setActiveNetworkInfo(networkInfo2g); setNetworkCountryIso(FAST_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterFast = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); setNetworkCountryIso(SLOW_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterSlow = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); }
@Test public void defaultInitialBitrateEstimate_for4g_forFastCountry_isGreaterThanEstimateForSlowCountry() { setActiveNetworkInfo(networkInfo4g); setNetworkCountryIso(FAST_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterFast = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); setNetworkCountryIso(SLOW_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterSlow = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); }
@Test public void defaultInitialBitrateEstimate_for3G_forFastCountry_isGreaterThanEstimateForSlowCountry() { setActiveNetworkInfo(networkInfo3g); setNetworkCountryIso(FAST_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterFast = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateFast = bandwidthMeterFast.getBitrateEstimate(); setNetworkCountryIso(SLOW_COUNTRY_ISO); DefaultBandwidthMeter bandwidthMeterSlow = new DefaultBandwidthMeter.Builder(RuntimeEnvironment.application).build(); long initialEstimateSlow = bandwidthMeterSlow.getBitrateEstimate(); assertThat(initialEstimateFast).isGreaterThan(initialEstimateSlow); }
@Test public void test() throws InterruptedException, ExecutionException, TimeoutException { BigtableDataClient client = testEnvRule.env().getDataClient(); // Create some data so that sample row keys has something to show List<ApiFuture<?>> futures = Lists.newArrayList(); for (int i = 0; i < 10; i++) { ApiFuture<Void> future = client.mutateRowAsync( RowMutation.create( testEnvRule.env().getTableId(), testEnvRule.env().getRowPrefix() + "-" + i) .setCell(testEnvRule.env().getFamilyId(), "", "value")); futures.add(future); } ApiFutures.allAsList(futures).get(1, TimeUnit.MINUTES); ApiFuture<List<KeyOffset>> future = client.sampleRowKeysAsync(testEnvRule.env().getTableId()); List<KeyOffset> results = future.get(1, TimeUnit.MINUTES); assertThat(results).isNotEmpty(); assertThat(results.get(results.size() - 1).getOffsetBytes()).isGreaterThan(0L); } }
@Test public void overwriteSet() throws Exception { createAndStoreBundle(bundlePath); Files.createFile(outputFilePath); BuildApksCommand command = BuildApksCommand.builder() .setBundlePath(bundlePath) .setOutputFile(outputFilePath) .setOverwriteOutput(true) .setAapt2Command(aapt2Command) .build(); assertThat(execute(command).toFile().length()).isGreaterThan(0L); }
private Intent assertAlarmScheduled(String ofExpectedType) { AlarmManager alarmManager = (AlarmManager) RuntimeEnvironment.application.getSystemService(Context.ALARM_SERVICE); ShadowAlarmManager shadow = shadowOf(alarmManager); ShadowAlarmManager.ScheduledAlarm nextScheduledAlarm = shadow.getNextScheduledAlarm(); assertThat(nextScheduledAlarm.type).isEqualTo(AlarmManager.RTC_WAKEUP); assertThat(nextScheduledAlarm.triggerAtTime).isGreaterThan(0L); PendingIntent pendingIntent = nextScheduledAlarm.operation; ShadowPendingIntent shadowPendingIntent = shadowOf(pendingIntent); ComponentName component = shadowPendingIntent.getSavedIntent().getComponent(); assertThat(component.getPackageName()).isEqualTo("com.zegoggles.smssync"); assertThat(component.getClassName()).isEqualTo("com.zegoggles.smssync.service.SmsBackupService"); assertThat(shadowPendingIntent.getFlags()).isEqualTo(FLAG_UPDATE_CURRENT); assertThat(shadowPendingIntent.getSavedIntent().getAction()).isNotEmpty(); assertThat(shadowPendingIntent.getSavedIntent().getAction()) .isEqualTo(ofExpectedType); return shadowPendingIntent.getSavedIntent(); }
@Test public void overwriteSet_overwritesFile() throws Exception { DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(480), abis("x86"), locales("en-US")); Path outputPath = tmp.getRoot().toPath().resolve("device.json"); Files.createFile(outputPath); GetDeviceSpecCommand.builder() .setAdbPath(adbPath) .setAdbServer(fakeServerOneDevice(deviceSpec)) .setOutputPath(outputPath) .setOverwriteOutput(true) .build() .execute(); assertThat(outputPath.toFile().length()).isGreaterThan(0L); }