1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package android.databinding.testapp; 17 18import android.databinding.testapp.databinding.BasicBindingBinding; 19 20import android.util.ArrayMap; 21 22import java.lang.reflect.Field; 23import java.lang.reflect.Modifier; 24import java.util.HashSet; 25import android.databinding.testapp.BR; 26public class ProcessBindableTest extends BaseDataBinderTest<BasicBindingBinding> { 27 private static String[] EXPECTED_BINDING_NAMES = { 28 "bindableField1", 29 "bindableField2", 30 "bindableField3", 31 "bindableField4", 32 "mbindableField5", 33 "bindableField6", 34 "bindableField7", 35 "bindableField8", 36 }; 37 38 public ProcessBindableTest() { 39 super(BasicBindingBinding.class); 40 } 41 42 public void testFieldsGenerated() throws IllegalAccessException { 43 Field[] fields = BR.class.getFields(); 44 45 ArrayMap<String, Integer> fieldValues = new ArrayMap<>(); 46 int modifiers = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL; 47 for (Field field: fields) { 48 assertTrue(field.getModifiers() == modifiers); 49 String name = field.getName(); 50 fieldValues.put(name, field.getInt(null)); 51 } 52 53 assertTrue(fieldValues.containsKey("_all")); 54 assertEquals(0, (int) fieldValues.get("_all")); 55 HashSet<Integer> values = new HashSet<>(); 56 values.add(0); 57 58 for (String fieldName : EXPECTED_BINDING_NAMES) { 59 assertTrue("missing field: " + fieldName, fieldValues.containsKey(fieldName)); 60 assertFalse(values.contains(fieldValues.get(fieldName))); 61 values.add(fieldValues.get(fieldName)); 62 } 63 } 64} 65