@Test public void testSetLoadedFromResourceId() throws Exception { Drawable drawable = new TestDrawable(); ShadowDrawable shadowDrawable = shadowOf(drawable); shadowDrawable.setLoadedFromResourceId(99); assertThat(shadowDrawable.getLoadedFromResourceId()).isEqualTo(99); }
@Test public void reset__shouldClearStaticState() throws Exception { String src = "source1"; ShadowDrawable.addCorruptStreamSource(src); assertTrue(ShadowDrawable.corruptStreamSources.contains(src)); ShadowDrawable.reset(); assertFalse(ShadowDrawable.corruptStreamSources.contains(src)); }
@Test public void testWasSelfInvalidated() throws Exception { Drawable drawable = ShadowDrawable.createFromResourceId(34758); ShadowDrawable shadowDrawable = shadowOf(drawable); assertThat(shadowDrawable.wasInvalidated()).isFalse(); drawable.invalidateSelf(); assertThat(shadowDrawable.wasInvalidated()).isTrue(); }
@Test public void createFromStream__shouldReturnNullWhenAskedToCreateADrawableFromACorruptedSourceStream() throws Exception { String corruptedStreamSource = "http://foo.com/image.jpg"; ShadowDrawable.addCorruptStreamSource(corruptedStreamSource); assertNull( ShadowDrawable.createFromStream( new ByteArrayInputStream(new byte[0]), corruptedStreamSource)); }
@Test public void createFromStream__shouldReturnDrawableWithSpecificSource() throws Exception { Drawable drawable = ShadowDrawable.createFromStream(new ByteArrayInputStream(new byte[0]), "my_source"); assertNotNull(drawable); assertEquals("my_source", ((ShadowBitmapDrawable) shadowOf(drawable)).getSource()); }
@Test public void copyBoundsToReturnedRect() { Drawable drawable = ShadowDrawable.createFromStream(new ByteArrayInputStream(new byte[0]), "my_source"); drawable.setBounds(1, 2, 3, 4); Rect r = drawable.copyBounds(); assertThat(r.left).isEqualTo(1); assertThat(r.top).isEqualTo(2); assertThat(r.right).isEqualTo(3); assertThat(r.bottom).isEqualTo(4); }
@Test public void createFromPath__shouldReturnDrawableWithSpecificPath() throws Exception { Drawable drawable = ShadowDrawable.createFromPath("/foo"); assertNotNull(drawable); assertEquals("/foo", ((ShadowBitmapDrawable) shadowOf(drawable)).getPath()); }
@Test public void testCreateFromResourceId_shouldSetTheId() throws Exception { Drawable drawable = ShadowDrawable.createFromResourceId(34758); ShadowDrawable shadowDrawable = shadowOf(drawable); assertThat(shadowDrawable.getLoadedFromResourceId()).isEqualTo(34758); }