Skip to content

Commit

Permalink
fix remote image view tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mttkay committed May 7, 2012
1 parent 4e290ab commit 1286c06
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Expand Up @@ -224,7 +224,11 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
}
}

private void setupViewSwitcher() {
/**
* This is called automatically from onLayout, so do not call manually unless you know what
* you're doing!
*/
public void setupViewSwitcher() {
// "migrate" this view's LPs to the new parent
switcher.setLayoutParams(getLayoutParams());

Expand Down
Expand Up @@ -16,7 +16,6 @@
import com.github.ignition.samples.core.R;
import com.github.ignition.samples.core.RemoteImageViewActivity;
import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.shadows.ShadowImageView;

@RunWith(IgnitionCoreTestRunner.class)
public class RemoteImageViewTest {
Expand All @@ -37,6 +36,8 @@ public void before() {
public void testCorrectAttributeInflationAndDefaulting() {
RemoteImageView imageView = (RemoteImageView) activity.findViewById(R.id.image1);

imageView.setupViewSwitcher();

// default values for unsupplied attributes
assertTrue(imageView.isAutoLoad());

Expand All @@ -60,13 +61,17 @@ public void canCustomizeTheErrorDrawable() {
assertEquals(expectedErrorDrawable, imageView.getErrorDrawable());
}

@Test
public void canUseImageViewSpecificAttributes() {
RemoteImageView riv = (RemoteImageView) activity.findViewById(R.id.image5);
ShadowImageView shadow = Robolectric.shadowOf(riv);
shadow.applyAttributes();
System.out.println("IN TEST: " + riv.getScaleType());
}
// TODO: doesn't work because Robolectric doesn't implement obtainStyledAttributes...
// @Test
// public void canCustomizeTheProgressDrawable() {
// RemoteImageView imageView = (RemoteImageView) activity.findViewById(R.id.image2);
//
// imageView.setupViewSwitcher();
//
// Drawable expectedProgressDrawable = Robolectric.application.getResources().getDrawable(
// android.R.drawable.progress_indeterminate_horizontal);
// assertEquals(expectedProgressDrawable, imageView.getProgressDrawable());
// }

@Test
public void testAutoLoadingOfImages() {
Expand All @@ -76,6 +81,12 @@ public void testAutoLoadingOfImages() {
RemoteImageView view4 = (RemoteImageView) activity.findViewById(R.id.image4);
RemoteImageView view5 = (RemoteImageView) activity.findViewById(R.id.image5);

view1.setupViewSwitcher();
view2.setupViewSwitcher();
view3.setupViewSwitcher();
view4.setupViewSwitcher();
view5.setupViewSwitcher();

assertTrue(view1.isAutoLoad());
assertTrue(imageLoader.isLoadImageCalled(view1));

Expand All @@ -94,5 +105,4 @@ public void testAutoLoadingOfImages() {
Robolectric.clickOn(activity.findViewById(R.id.load_image_button));
assertTrue(imageLoader.isLoadImageCalled(view5));
}

}

0 comments on commit 1286c06

Please sign in to comment.