summaryrefslogtreecommitdiff
path: root/library/test/src/com/android/setupwizardlib/TemplateLayoutTest.java
diff options
context:
space:
mode:
authorMaurice Lam <yukl@google.com>2016-12-19 11:46:55 -0800
committerMaurice Lam <yukl@google.com>2017-01-10 10:47:33 -0800
commit7514f1cee29b3feb4822ce16945c1c312057d24f (patch)
treed345c2b45f0b7641dae6301f2b2c50457c525474 /library/test/src/com/android/setupwizardlib/TemplateLayoutTest.java
parent035ba6bda68e78bbb49424300bdd3f0fb305b9e7 (diff)
downloadsetupwizard-7514f1cee29b3feb4822ce16945c1c312057d24f.tar.gz
Implement Mixins for Templates
Implement Mixin functionalities, which defines part of a template layout, making it reusable in different layouts. For example, the HeaderMixin allows setting and getting the header text via the mixin, which allows for clients which uses multiple different layuots to simplify their code via something like layout.getMixin(HeaderMixin.class).setText("Foobar"); Bug: 34163318 Test: ./gradlew connectedAndroidTest Change-Id: I4348c8bb5b8e640b49c2be0c79c70aa85cf0ebc0
Diffstat (limited to 'library/test/src/com/android/setupwizardlib/TemplateLayoutTest.java')
-rw-r--r--library/test/src/com/android/setupwizardlib/TemplateLayoutTest.java105
1 files changed, 105 insertions, 0 deletions
diff --git a/library/test/src/com/android/setupwizardlib/TemplateLayoutTest.java b/library/test/src/com/android/setupwizardlib/TemplateLayoutTest.java
new file mode 100644
index 0000000..ddce677
--- /dev/null
+++ b/library/test/src/com/android/setupwizardlib/TemplateLayoutTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.setupwizardlib;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import android.content.Context;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
+
+import com.android.setupwizardlib.template.HeaderMixin;
+import com.android.setupwizardlib.test.R;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class TemplateLayoutTest {
+
+ private Context mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ mContext = InstrumentationRegistry.getContext();
+ }
+
+ @Test
+ public void testAddView() {
+ TemplateLayout layout = new TemplateLayout(mContext, R.layout.test_template,
+ R.id.suw_layout_content);
+ TextView tv = new TextView(mContext);
+ tv.setId(R.id.test_view_id);
+ layout.addView(tv);
+ View view = layout.findViewById(R.id.test_view_id);
+ assertSame("The view added should be the same text view", tv, view);
+ }
+
+ @Test
+ public void testInflateFromXml() {
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ TemplateLayout layout =
+ (TemplateLayout) inflater.inflate(R.layout.test_template_layout, null);
+ View content = layout.findViewById(R.id.test_content);
+ assertTrue("@id/test_content should be a TextView", content instanceof TextView);
+ }
+
+ @Test
+ public void testTemplate() {
+ TemplateLayout layout = new TemplateLayout(mContext, R.layout.test_template,
+ R.id.suw_layout_content);
+ View templateView = layout.findViewById(R.id.test_template_view);
+ assertNotNull("@id/test_template_view should exist in template", templateView);
+
+ TextView tv = new TextView(mContext);
+ tv.setId(R.id.test_view_id);
+ layout.addView(tv);
+
+ templateView = layout.findViewById(R.id.test_template_view);
+ assertNotNull("@id/test_template_view should exist in template", templateView);
+ View contentView = layout.findViewById(R.id.test_view_id);
+ assertSame("The view added should be the same text view", tv, contentView);
+ }
+
+ @Test
+ public void testNoTemplate() {
+ try {
+ new TemplateLayout(mContext, 0, 0);
+ fail("Inflating TemplateLayout without template should throw exception");
+ } catch (IllegalArgumentException e) {
+ // Expected IllegalArgumentException
+ }
+ }
+
+ @Test
+ public void testGetMixin() {
+ TemplateLayout layout = new TemplateLayout(mContext, R.layout.test_template,
+ R.id.suw_layout_content);
+ final HeaderMixin mixin = layout.getMixin(HeaderMixin.class);
+ assertNull("getMixin for a mixin that doesn't exist should return null", mixin);
+ }
+}