blob: bc2cc292fde6b3d017f117c27c29200c5660dd2b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
package com.android.volley.toolbox;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView.ScaleType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.*;
@RunWith(RobolectricTestRunner.class)
public class NetworkImageViewTest {
private NetworkImageView mNIV;
private MockImageLoader mMockImageLoader;
@Before public void setUp() throws Exception {
mMockImageLoader = new MockImageLoader();
mNIV = new NetworkImageView(Robolectric.application);
}
@Test public void setImageUrl_requestsImage() {
mNIV.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
mNIV.setImageUrl("http://foo", mMockImageLoader);
assertEquals("http://foo", mMockImageLoader.lastRequestUrl);
assertEquals(0, mMockImageLoader.lastMaxWidth);
assertEquals(0, mMockImageLoader.lastMaxHeight);
}
// public void testSetImageUrl_setsMaxSize() {
// // TODO: Not sure how to make getWidth() return something from an
// // instrumentation test. Write this test once it's figured out.
// }
private class MockImageLoader extends ImageLoader {
public MockImageLoader() {
super(null, null);
}
public String lastRequestUrl;
public int lastMaxWidth;
public int lastMaxHeight;
public ImageContainer get(String requestUrl, ImageListener imageListener, int maxWidth,
int maxHeight, ScaleType scaleType) {
lastRequestUrl = requestUrl;
lastMaxWidth = maxWidth;
lastMaxHeight = maxHeight;
return null;
}
}
}
|