Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21478 rajender 1
package com.android.volley.toolbox;
2
 
3
import android.content.Context;
4
import android.util.AttributeSet;
5
import android.view.ViewGroup.LayoutParams;
6
import android.widget.ImageView.ScaleType;
7
 
8
import org.junit.Before;
9
import org.junit.Test;
10
import org.junit.runner.RunWith;
11
import org.robolectric.RobolectricTestRunner;
12
import org.robolectric.RuntimeEnvironment;
13
 
14
import static org.junit.Assert.assertEquals;
15
import static org.junit.Assert.assertNotNull;
16
 
17
@RunWith(RobolectricTestRunner.class)
18
public class NetworkImageViewTest {
19
    private NetworkImageView mNIV;
20
    private MockImageLoader mMockImageLoader;
21
 
22
    @Before public void setUp() throws Exception {
23
        mMockImageLoader = new MockImageLoader();
24
        mNIV = new NetworkImageView(RuntimeEnvironment.application);
25
    }
26
 
27
    @Test public void setImageUrl_requestsImage() {
28
        mNIV.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
29
        mNIV.setImageUrl("http://foo", mMockImageLoader);
30
        assertEquals("http://foo", mMockImageLoader.lastRequestUrl);
31
        assertEquals(0, mMockImageLoader.lastMaxWidth);
32
        assertEquals(0, mMockImageLoader.lastMaxHeight);
33
    }
34
 
35
    // public void testSetImageUrl_setsMaxSize() {
36
    // // TODO: Not sure how to make getWidth() return something from an
37
    // // instrumentation test. Write this test once it's figured out.
38
    // }
39
 
40
    private class MockImageLoader extends ImageLoader {
41
        public MockImageLoader() {
42
            super(null, null);
43
        }
44
 
45
        public String lastRequestUrl;
46
        public int lastMaxWidth;
47
        public int lastMaxHeight;
48
 
49
        public ImageContainer get(String requestUrl, ImageListener imageListener, int maxWidth,
50
                int maxHeight, ScaleType scaleType) {
51
            lastRequestUrl = requestUrl;
52
            lastMaxWidth = maxWidth;
53
            lastMaxHeight = maxHeight;
54
            return null;
55
        }
56
    }
57
 
58
    @Test
59
    public void publicMethods() throws Exception {
60
        // Catch-all test to find API-breaking changes.
61
        assertNotNull(NetworkImageView.class.getConstructor(Context.class));
62
        assertNotNull(NetworkImageView.class.getConstructor(Context.class, AttributeSet.class));
63
        assertNotNull(NetworkImageView.class.getConstructor(Context.class, AttributeSet.class,
64
                int.class));
65
 
66
        assertNotNull(NetworkImageView.class.getMethod("setImageUrl", String.class, ImageLoader.class));
67
        assertNotNull(NetworkImageView.class.getMethod("setDefaultImageResId", int.class));
68
        assertNotNull(NetworkImageView.class.getMethod("setErrorImageResId", int.class));
69
    }
70
}