DataBindingMapperTest.java revision d3dc1b70aa71e8343dbf5e05a2feeb72bb29b6ec
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;
15
16
17import android.test.AndroidTestCase;
18import android.view.View;
19
20public class DataBindingMapperTest extends AndroidTestCase {
21    public void testNotDataBindingId() {
22        View view = new View(getContext());
23        view.setTag("layout/unexpected");
24        android.databinding.DataBinderMapper mapper = new android.databinding.DataBinderMapper();
25        ViewDataBinding binding = mapper.getDataBinder(null, view, 1);
26        assertNull(binding);
27    }
28    public void testInvalidView() {
29        View view = new View(getContext());
30        view.setTag("layout/unexpected");
31        android.databinding.DataBinderMapper mapper = new android.databinding.DataBinderMapper();
32        Throwable error = null;
33        try {
34            mapper.getDataBinder(null, view, android.databinding.testapp.R.layout.multi_res_layout);
35        } catch (Throwable t) {
36            error = t;
37        }
38        assertNotNull(error);
39        assertEquals("The tag for multi_res_layout is invalid. Received: layout/unexpected",
40                error.getMessage());
41
42    }
43}
44