BracketTest.java revision e0d5ed7613cb72192430cd2ed8e4159618ca308e
1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *      http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
12 */
13
14package android.databinding.testapp;
15
16import android.databinding.testapp.databinding.BracketTestBinding;
17
18import android.test.UiThreadTest;
19import android.util.LongSparseArray;
20import android.util.SparseArray;
21import android.util.SparseBooleanArray;
22import android.util.SparseIntArray;
23import android.util.SparseLongArray;
24
25public class BracketTest extends BaseDataBinderTest<BracketTestBinding> {
26    private String[] mArray = {
27            "Hello World"
28    };
29
30    private SparseArray<String> mSparseArray = new SparseArray<>();
31    private SparseIntArray mSparseIntArray = new SparseIntArray();
32    private SparseBooleanArray mSparseBooleanArray = new SparseBooleanArray();
33    private SparseLongArray mSparseLongArray = new SparseLongArray();
34    private LongSparseArray<String> mLongSparseArray = new LongSparseArray<>();
35
36    public BracketTest() {
37        super(BracketTestBinding.class);
38        mSparseArray.put(0, "Hello");
39        mLongSparseArray.put(0, "World");
40        mSparseIntArray.put(0, 100);
41        mSparseBooleanArray.put(0, true);
42        mSparseLongArray.put(0, 5);
43    }
44
45    @Override
46    protected void setUp() throws Exception {
47        super.setUp();
48        initBinder(new Runnable() {
49            @Override
50            public void run() {
51                mBinder.setArray(mArray);
52                mBinder.setSparseArray(mSparseArray);
53                mBinder.setSparseIntArray(mSparseIntArray);
54                mBinder.setSparseBooleanArray(mSparseBooleanArray);
55                mBinder.setSparseLongArray(mSparseLongArray);
56                mBinder.setLongSparseArray(mLongSparseArray);
57
58                mBinder.executePendingBindings();
59            }
60        });
61    }
62
63    @UiThreadTest
64    public void testBrackets() {
65        assertEquals("Hello World", mBinder.arrayText.getText().toString());
66        assertEquals("Hello", mBinder.sparseArrayText.getText().toString());
67        assertEquals("World", mBinder.longSparseArrayText.getText().toString());
68        assertEquals("100", mBinder.sparseIntArrayText.getText().toString());
69        assertEquals("true", mBinder.sparseBooleanArrayText.getText().toString());
70        assertEquals("5", mBinder.sparseLongArrayText.getText().toString());
71    }
72
73    @UiThreadTest
74    public void testBracketObj() {
75        assertEquals("", mBinder.bracketMap.getText().toString());
76    }
77}
78