1package com.xtremelabs.robolectric.shadows;
2
3import static org.hamcrest.CoreMatchers.equalTo;
4import static org.hamcrest.MatcherAssert.assertThat;
5import static org.junit.Assert.assertNotNull;
6
7import android.app.Activity;
8
9import com.xtremelabs.robolectric.Robolectric;
10import com.xtremelabs.robolectric.WithTestDefaultsRunner;
11
12import org.junit.Before;
13import org.junit.Test;
14import org.junit.runner.RunWith;
15
16@RunWith(WithTestDefaultsRunner.class)
17public class TypedArrayTest {
18    private android.content.res.TypedArray typedArray;
19
20    @Before
21    public void setUp() throws Exception {
22      typedArray = Robolectric.newInstanceOf(android.content.res.TypedArray.class);
23    }
24
25    @Test
26    public void getResources() throws Exception {
27        assertNotNull(new Activity().obtainStyledAttributes(null).getResources());
28    }
29
30    @Test
31    public void testBooleanDefaultValue() {
32        assertThat(typedArray.getBoolean(0, true), equalTo(true));
33        assertThat(typedArray.getBoolean(0, false), equalTo(false));
34    }
35
36    @Test
37    public void testIntDefaultValue() {
38        assertThat(typedArray.getInt(0, 15), equalTo(15));
39        assertThat(typedArray.getInteger(0, 24), equalTo(24));
40    }
41
42    @Test
43    public void testFloatDefaultValue() {
44        assertThat(typedArray.getFloat(0, 0.5f), equalTo(0.5f));
45    }
46
47    @Test
48    public void testDimensionDefaultValue() {
49        assertThat(typedArray.getDimension(0, 0.5f), equalTo(0.5f));
50    }
51
52    @Test
53    public void testDimensionPixelOffsetDefaultValue() {
54        assertThat(typedArray.getDimensionPixelOffset(0, 2), equalTo(2));
55    }
56
57    @Test
58    public void testDimensionPixelSizeDefaultValue() {
59        assertThat(typedArray.getDimensionPixelSize(0, 2), equalTo(2));
60    }
61
62    @Test
63    public void testLayoutDimensionDefaultValue() {
64        assertThat(typedArray.getLayoutDimension(0, 2), equalTo(2));
65    }
66
67    @Test
68    public void testResourceIdDefaultValue() {
69        assertThat(typedArray.getResourceId(0, 2), equalTo(2));
70    }
71}
72