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); }
private void assertUninterruptibleDrained(BlockingQueue<Object> q) { assertEquals(0, Queues.drainUninterruptibly(q, ImmutableList.of(), 0, 10, MILLISECONDS)); // but does the wait actually occurs? @SuppressWarnings("unused") // go/futurereturn-lsc Future<?> possiblyIgnoredError = threadPool.submit(new Interrupter(currentThread())); Stopwatch timer = Stopwatch.createStarted(); Queues.drainUninterruptibly(q, newArrayList(), 1, 10, MILLISECONDS); assertThat(timer.elapsed(MILLISECONDS)).isAtLeast(10L); // wait for interrupted status and clear it while (!Thread.interrupted()) { Thread.yield(); } }
/** * Asserts that {@link BloomFilter#approximateElementCount} is within 1 percent of the expected * value. */ private static void assertApproximateElementCountGuess(BloomFilter<?> bf, int sizeGuess) { assertThat(bf.approximateElementCount()).isAtLeast((long) (sizeGuess * 0.99)); assertThat(bf.approximateElementCount()).isAtMost((long) (sizeGuess * 1.01)); }
@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 @Config public void shouldAddEntry() throws Exception { ArgumentCaptor<Uri> uri = ArgumentCaptor.forClass(Uri.class); ArgumentCaptor<ContentValues> values = ArgumentCaptor.forClass(ContentValues.class); Date when = new Date(); accessor.addEntry( 12, when, 100, "Title", "Desc"); verify(resolver).insert(uri.capture(), values.capture()); assertThat(uri.getValue().toString()).isEqualTo("content://com.android.calendar/events"); ContentValues cv = values.getValue(); assertThat(cv.getAsString(Events.TITLE)).isEqualTo("Title"); assertThat(cv.getAsString(Events.DESCRIPTION)).isEqualTo("Desc"); assertThat(cv.getAsLong(Events.DTSTART)).isEqualTo(when.getTime()); assertThat(cv.getAsLong(Events.DTEND)).isGreaterThan(when.getTime()); assertThat(cv.getAsInteger(Events.ACCESS_LEVEL)).isEqualTo(CalendarContract.Events.ACCESS_DEFAULT); assertThat(cv.getAsInteger(Events.STATUS)).isEqualTo(CalendarContract.Events.STATUS_CONFIRMED); assertThat(cv.getAsLong(Events.CALENDAR_ID)).isEqualTo(12L); assertThat(cv.getAsString(Events.EVENT_TIMEZONE)).isEqualTo(Time.getCurrentTimezone()); }
public void testRunWithTimeout_goodRunnableWithEnoughTime() throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); service.runWithTimeout(GOOD_RUNNABLE, ENOUGH_MS, MILLISECONDS); assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(DELAY_MS, ENOUGH_MS)); }
.getMinSizeConfigurationMap() .get(SizeConfiguration.getDefaultInstance())) .isLessThan(compressedApkSize); assertThat(configurationSizes.getMaxSizeConfigurationMap().keySet()) .containsExactly(SizeConfiguration.getDefaultInstance()); .getMaxSizeConfigurationMap() .get(SizeConfiguration.getDefaultInstance())) .isGreaterThan(compressedApkSize);
assertThat(apkOneSize).isGreaterThan(20L); assertThat(apkTwoSize).isGreaterThan(20L); assertThat(apkOneSize).isEqualTo(apkTwoSize);
public void testRunUninterruptiblyWithTimeout_goodRunnableWithEnoughTime() throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); service.runUninterruptiblyWithTimeout(GOOD_RUNNABLE, ENOUGH_MS, MILLISECONDS); assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(DELAY_MS, ENOUGH_MS)); }
public void testCount() { assertThat(emptyAccumulator.count()).isEqualTo(0); assertThat(emptyAccumulatorByAddAllEmptyPairedStats.count()).isEqualTo(0); assertThat(oneValueAccumulator.count()).isEqualTo(1); assertThat(oneValueAccumulatorByAddAllEmptyPairedStats.count()).isEqualTo(1); assertThat(twoValuesAccumulator.count()).isEqualTo(2); assertThat(twoValuesAccumulatorByAddAllPartitionedPairedStats.count()).isEqualTo(2); assertThat(manyValuesAccumulator.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(manyValuesAccumulatorByAddAllPartitionedPairedStats.count()) .isEqualTo(MANY_VALUES_COUNT); }
.getMinSizeConfigurationMap() .get(SizeConfiguration.getDefaultInstance())) .isEqualTo(2 * compressedApkSize); // base+x86 assertThat(configurationSizes.getMaxSizeConfigurationMap().keySet()) .containsExactly(SizeConfiguration.getDefaultInstance()); .getMaxSizeConfigurationMap() .get(SizeConfiguration.getDefaultInstance())) .isGreaterThan(2 * compressedApkSize); // base+x86_64
@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); }
private void testDrainTimesOut(BlockingQueue<Object> q) throws Exception { for (boolean interruptibly : new boolean[] {true, false}) { assertEquals(0, Queues.drain(q, ImmutableList.of(), 1, 10, MILLISECONDS)); Producer producer = new Producer(q, 1); // producing one, will ask for two Future<?> producerThread = threadPool.submit(producer); producer.beganProducing.await(); // make sure we time out Stopwatch timer = Stopwatch.createStarted(); int drained = drain(q, newArrayList(), 2, 10, MILLISECONDS, interruptibly); assertThat(drained).isAtMost(1); assertThat(timer.elapsed(MILLISECONDS)).isAtLeast(10L); // If even the first one wasn't there, clean up so that the next test doesn't see an element. producerThread.cancel(true); producer.doneProducing.await(); if (drained == 0) { q.poll(); // not necessarily there if producer was interrupted } } }
public void testCallUninterruptiblyWithTimeout_goodCallableWithEnoughTime() throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); String result = service.callUninterruptiblyWithTimeout(GOOD_CALLABLE, ENOUGH_MS, MILLISECONDS); assertThat(result).isEqualTo(GOOD_CALLABLE_RESULT); assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(DELAY_MS, ENOUGH_MS)); }
public void testCount() { assertThat(EMPTY_STATS_VARARGS.count()).isEqualTo(0); assertThat(EMPTY_STATS_ITERABLE.count()).isEqualTo(0); assertThat(ONE_VALUE_STATS.count()).isEqualTo(1); assertThat(TWO_VALUES_STATS.count()).isEqualTo(2); assertThat(MANY_VALUES_STATS_VARARGS.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_ITERABLE.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_ITERATOR.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_SNAPSHOT.count()).isEqualTo(MANY_VALUES_COUNT); assertThat(INTEGER_MANY_VALUES_STATS_VARARGS.count()).isEqualTo(INTEGER_MANY_VALUES_COUNT); assertThat(INTEGER_MANY_VALUES_STATS_ITERABLE.count()).isEqualTo(INTEGER_MANY_VALUES_COUNT); assertThat(LONG_MANY_VALUES_STATS_ITERATOR.count()).isEqualTo(LONG_MANY_VALUES_COUNT); assertThat(LONG_MANY_VALUES_STATS_SNAPSHOT.count()).isEqualTo(LONG_MANY_VALUES_COUNT); }
@Test public void testInitValues() { assertThat(context.requestStartTime).isGreaterThan(0L); assertThat(context.sentMessageSize.longValue()).isEqualTo(0L); assertThat(context.receiveMessageSize.longValue()).isEqualTo(0L); } }
@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 initNoCrash() { assertThat(Debug.getNativeHeapAllocatedSize()).isAtLeast(0L); }