1c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam/* 2c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam * Copyright (C) 2017 The Android Open Source Project 3c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam * 4c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam * Licensed under the Apache License, Version 2.0 (the "License"); 5c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam * you may not use this file except in compliance with the License. 6c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam * You may obtain a copy of the License at 7c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam * 8c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam * http://www.apache.org/licenses/LICENSE-2.0 9c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam * 10c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam * Unless required by applicable law or agreed to in writing, software 11c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam * distributed under the License is distributed on an "AS IS" BASIS, 12c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam * See the License for the specific language governing permissions and 14c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam * limitations under the License. 15c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam */ 16c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam 17c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lampackage com.android.setupwizardlib.test; 18c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam 19c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lamimport static org.junit.Assert.assertEquals; 20c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam 21c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lamimport android.content.Context; 22c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lamimport android.content.res.Resources; 23c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lamimport android.support.annotation.NonNull; 24c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lamimport android.support.test.InstrumentationRegistry; 25c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lamimport android.support.test.filters.SmallTest; 26c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lamimport android.support.test.runner.AndroidJUnit4; 27c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lamimport android.util.AttributeSet; 28c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam 29c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lamimport com.android.setupwizardlib.items.SimpleInflater; 30c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam 31c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lamimport org.junit.Test; 32c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lamimport org.junit.runner.RunWith; 33c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam 34c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam@SmallTest 35c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam@RunWith(AndroidJUnit4.class) 36c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lampublic class SimpleInflaterTest { 37c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam 38c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam @Test 39c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam public void testInflateXml() { 40c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam final Context context = InstrumentationRegistry.getContext(); 41c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam TestInflater inflater = new TestInflater(context.getResources()); 42c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam final StringBuilder result = inflater.inflate(R.xml.simple_inflater_test); 43c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam 44c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam assertEquals("Parent[null] > Child[foobar]", result.toString()); 45c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam } 46c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam 47c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam private static class TestInflater extends SimpleInflater<StringBuilder> { 48c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam 49c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam protected TestInflater(@NonNull Resources resources) { 50c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam super(resources); 51c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam } 52c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam 53c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam @Override 54c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam protected StringBuilder onCreateItem(String tagName, AttributeSet attrs) { 55c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam final String attribute = attrs.getAttributeValue(null, "myattribute"); 56c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam return new StringBuilder(tagName).append("[").append(attribute).append("]"); 57c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam } 58c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam 59c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam @Override 60c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam protected void onAddChildItem(StringBuilder parent, StringBuilder child) { 61c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam parent.append(" > ").append(child); 62c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam } 63c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam } 64c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lam} 65