@Test public void testPartialReads() throws IOException { byte[] buffer = new byte[18]; DataSpec dataSpec = buildDataSpec("data:,012345678901234567"); assertThat(schemeDataDataSource.open(dataSpec)).isEqualTo(18); assertThat(schemeDataDataSource.read(buffer, 0, 9)).isEqualTo(9); assertThat(schemeDataDataSource.read(buffer, 3, 0)).isEqualTo(0); assertThat(schemeDataDataSource.read(buffer, 9, 15)).isEqualTo(9); assertThat(schemeDataDataSource.read(buffer, 1, 0)).isEqualTo(0); assertThat(schemeDataDataSource.read(buffer, 1, 1)).isEqualTo(RESULT_END_OF_INPUT); assertThat(Util.fromUtf8Bytes(buffer, 0, 18)).isEqualTo("012345678901234567"); }
private void checkStackTrace(ExecutionException e) { // Our call site for get() should be in the trace. int index = findStackFrame(e, getClass().getName(), "getExpectingExecutionException"); assertThat(index).isNotEqualTo(0); // Above our method should be the call to get(). Don't assert on the class // because it could be some superclass. assertThat(e.getStackTrace()[index - 1].getMethodName()).isEqualTo("get"); }
@Test public void testReturnsByte_whenReadsUpToMarkLimit_withNoMoreBytesAvailable() throws IOException { MarkEnforcingInputStream is = new MarkEnforcingInputStream(new ByteArrayInputStream(new byte[MARK_LIMIT])); for (int i = 0; i < MARK_LIMIT; i++) { assertThat(is.read()).isAtLeast(0); } }
public void testHashCodeImpl() { List<Integer> base = createList(Integer.class, 1, 2, 2); List<Integer> copy = createList(Integer.class, 1, 2, 2); List<Integer> outOfOrder = createList(Integer.class, 2, 2, 1); List<Integer> diffValue = createList(Integer.class, 1, 2, 4); List<Integer> diffLength = createList(Integer.class, 1, 2); List<Integer> empty = createList(Integer.class); assertThat(Lists.hashCodeImpl(base)).isEqualTo(Lists.hashCodeImpl(copy)); assertThat(Lists.hashCodeImpl(base)).isNotEqualTo(Lists.hashCodeImpl(outOfOrder)); assertThat(Lists.hashCodeImpl(base)).isNotEqualTo(Lists.hashCodeImpl(diffValue)); assertThat(Lists.hashCodeImpl(base)).isNotEqualTo(Lists.hashCodeImpl(diffLength)); assertThat(Lists.hashCodeImpl(base)).isNotEqualTo(Lists.hashCodeImpl(empty)); }
public void testIndexOf_specialValues() { ImmutableDoubleArray iia = ImmutableDoubleArray.of(-0.0, 0.0, Double.MAX_VALUE, Double.POSITIVE_INFINITY, Double.NaN); assertThat(iia.indexOf(-0.0)).isEqualTo(0); assertThat(iia.indexOf(0.0)).isEqualTo(1); assertThat(iia.indexOf(Double.MAX_VALUE)).isEqualTo(2); assertThat(iia.indexOf(Double.POSITIVE_INFINITY)).isEqualTo(3); assertThat(iia.indexOf(Double.NaN)).isEqualTo(4); }
@Test public void centerCropWithGravityHorizontalRight() { Bitmap source = Bitmap.createBitmap(20, 10, ARGB_8888); Request data = new Request.Builder(URI_1).resize(40, 40).centerCrop(Gravity.RIGHT).build(); Bitmap result = transformResult(data, source, 0); ShadowBitmap shadowBitmap = shadowOf(result); assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source); assertThat(shadowBitmap.getCreatedFromX()).isEqualTo(10); assertThat(shadowBitmap.getCreatedFromY()).isEqualTo(0); assertThat(shadowBitmap.getCreatedFromWidth()).isEqualTo(10); assertThat(shadowBitmap.getCreatedFromHeight()).isEqualTo(10); Matrix matrix = shadowBitmap.getCreatedFromMatrix(); ShadowMatrix shadowMatrix = shadowOf(matrix); assertThat(shadowMatrix.getPreOperations()).containsExactly("scale 4.0 4.0"); }
public void testForEachPair_parallel() { Stream<String> streamA = IntStream.range(0, 100000).mapToObj(String::valueOf).parallel(); Stream<Integer> streamB = IntStream.range(0, 100000).mapToObj(i -> i).parallel(); AtomicInteger count = new AtomicInteger(0); Streams.forEachPair( streamA, streamB, (a, b) -> { count.incrementAndGet(); Truth.assertThat(a.equals(String.valueOf(b))).isTrue(); }); Truth.assertThat(count.get()).isEqualTo(100000); // of course, this test doesn't prove that anything actually happened in parallel... }
@Test public void testReadAllEscaping() { ParsableNalUnitBitArray array = new ParsableNalUnitBitArray(ALL_ESCAPING_TEST_DATA, 0, ALL_ESCAPING_TEST_DATA.length); assertThat(array.canReadBits(48)).isTrue(); assertThat(array.canReadBits(49)).isFalse(); assertThat(array.readBits(15)).isEqualTo(0); assertThat(array.readBit()).isFalse(); assertThat(array.readBits(17)).isEqualTo(0); assertThat(array.readBits(15)).isEqualTo(0); }
@Test public void testChainStyle() { style.chain(createAncestorStyle()); assertWithMessage("id must not be inherited").that(style.getId()).isNull(); assertThat(style.isUnderline()).isTrue(); assertThat(style.isLinethrough()).isTrue(); assertThat(style.getStyle()).isEqualTo(STYLE_BOLD_ITALIC); assertThat(style.getFontFamily()).isEqualTo(FONT_FAMILY); assertThat(style.getFontColor()).isEqualTo(FOREGROUND_COLOR); // do inherit backgroundColor when chaining assertWithMessage("do not inherit backgroundColor when chaining") .that(style.getBackgroundColor()).isEqualTo(BACKGROUND_COLOR); }
@Test public void testPlaylistWithClosedCaption() throws IOException { HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, PLAYLIST_WITH_CC); assertThat(playlist.muxedCaptionFormats).hasSize(1); Format closedCaptionFormat = playlist.muxedCaptionFormats.get(0); assertThat(closedCaptionFormat.sampleMimeType).isEqualTo(MimeTypes.APPLICATION_CEA708); assertThat(closedCaptionFormat.accessibilityChannel).isEqualTo(4); assertThat(closedCaptionFormat.language).isEqualTo("es"); }
@Test public void shouldMakeTextCorrectly() throws Exception { Toast toast = Toast.makeText(context, "short toast", Toast.LENGTH_SHORT); assertThat(toast).isNotNull(); assertThat(toast.getDuration()).isEqualTo(Toast.LENGTH_SHORT); toast.show(); assertThat(ShadowToast.getLatestToast()).isSameAs(toast); assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo("short toast"); assertThat(ShadowToast.showedToast("short toast")).isTrue(); }
@Test public void setDefaultFingerprints() { assertThat(shadowOf(manager).getEnrolledFingerprints()).isEmpty(); shadowOf(manager).setDefaultFingerprints(1); assertThat(manager.getEnrolledFingerprints().get(0).getName().toString()) .isEqualTo("Fingerprint 0"); assertThat(shadowOf(manager).getFingerprintId(0)).isEqualTo(0); assertThat(manager.hasEnrolledFingerprints()).isTrue(); shadowOf(manager).setDefaultFingerprints(0); assertThat(manager.getEnrolledFingerprints()).isEmpty(); assertThat(manager.hasEnrolledFingerprints()).isFalse(); }
@Test public void huntDecodesWhenNotInCache() throws Exception { Action action = mockAction(URI_KEY_1, URI_1, mockImageViewTarget()); TestableBitmapHunter hunter = new TestableBitmapHunter(picasso, dispatcher, cache, stats, action, bitmap); RequestHandler.Result result = hunter.hunt(); assertThat(cache.missCount()).isEqualTo(1); Request request = action.request; verify(hunter.requestHandler) .load(eq(picasso), eq(request), any(RequestHandler.Callback.class)); assertThat(result.getBitmap()).isEqualTo(bitmap); }
@Test public void intercept_elderOnLinkedHashMapHandler_shouldReturnEldestMemberOfLinkedHashMap() throws Throwable { LinkedHashMap<Integer, String> map = new LinkedHashMap<>(2); map.put(1, "one"); map.put(2, "two"); Map.Entry<Integer, String> result = (Map.Entry<Integer, String>) shadowWrangler.intercept("java/util/LinkedHashMap/eldest()Ljava/lang/Object;", map, null, getClass()); Map.Entry<Integer, String> eldestMember = map.entrySet().iterator().next(); assertThat(result).isEqualTo(eldestMember); assertThat(result.getKey()).isEqualTo(1); assertThat(result.getValue()).isEqualTo("one"); }
private static void assertSuccessful(AbstractFuture<Integer> future, Integer expectedResult) throws InterruptedException, TimeoutException, ExecutionException { assertDone(future); assertThat(future.isCancelled()).isFalse(); assertThat(getDone(future)).isEqualTo(expectedResult); assertThat(getDoneFromTimeoutOverload(future)).isEqualTo(expectedResult); }
@Test public void testAssignIdForKeyAndGetKeyForId() { final String key1 = "key1"; final String key2 = "key2"; int id1 = index.assignIdForKey(key1); int id2 = index.assignIdForKey(key2); assertThat(index.getKeyForId(id1)).isEqualTo(key1); assertThat(index.getKeyForId(id2)).isEqualTo(key2); assertThat(id1 != id2).isTrue(); assertThat(index.assignIdForKey(key1)).isEqualTo(id1); assertThat(index.assignIdForKey(key2)).isEqualTo(id2); }
@Test public void load_withShapeDrawableResourceId_asBitmap_withValidSize_returnsNonNullBitmap() throws ExecutionException, InterruptedException { Bitmap bitmap = Glide.with(context) .asBitmap() .load(ResourceIds.drawable.shape_drawable) .submit(100, 200) .get(); assertThat(bitmap).isNotNull(); assertThat(bitmap.getWidth()).isEqualTo(100); assertThat(bitmap.getHeight()).isEqualTo(200); }
private static void assertAction(DownloadAction action, String type, int version, byte[] data) { assertThat(action).isInstanceOf(FakeDownloadAction.class); assertThat(action.type).isEqualTo(type); assertThat(((FakeDownloadAction) action).version).isEqualTo(version); assertThat(((FakeDownloadAction) action).data).isEqualTo(data); }
private static void testDecoding(byte[] data) { Projection projection = ProjectionDecoder.decode(data, C.STEREO_MODE_MONO); assertThat(projection).isNotNull(); assertThat(projection.stereoMode).isEqualTo(C.STEREO_MODE_MONO); assertThat(projection.leftMesh).isNotNull(); assertThat(projection.rightMesh).isNotNull(); assertThat(projection.singleMesh).isTrue(); testSubMesh(projection.leftMesh); }
@Test public void equalsHashCode() throws Exception { ShadowMap a = baseShadowMap.newBuilder().addShadowClass(A, B, true, false).build(); ShadowMap b = baseShadowMap.newBuilder().addShadowClass(A, B, true, false).build(); assertThat(a).isEqualTo(b); assertThat(a.hashCode()).isEqualTo(b.hashCode()); ShadowMap c = b.newBuilder().build(); assertThat(c).isEqualTo(b); assertThat(c.hashCode()).isEqualTo(b.hashCode()); ShadowMap d = baseShadowMap.newBuilder().addShadowClass(A, X, true, false).build(); assertThat(d).isNotEqualTo(a); assertThat(d.hashCode()).isNotEqualTo(b.hashCode()); }