1/* 2 * Copyright (C) 2016 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 */ 16 17package com.android.setupwizardlib.test; 18 19import android.content.Context; 20import android.content.ContextWrapper; 21import android.test.AndroidTestCase; 22import android.test.suitebuilder.annotation.SmallTest; 23import android.widget.TextView; 24 25import com.android.setupwizardlib.span.LinkSpan; 26 27public class LinkSpanTest extends AndroidTestCase { 28 29 @SmallTest 30 public void testOnClick() { 31 final TestContext context = new TestContext(getContext()); 32 final TextView textView = new TextView(context); 33 final LinkSpan linkSpan = new LinkSpan("test_id"); 34 35 linkSpan.onClick(textView); 36 37 assertSame("Clicked LinkSpan should be passed to setup", linkSpan, context.clickedSpan); 38 } 39 40 @SmallTest 41 public void testNonImplementingContext() { 42 final Context context = getContext(); 43 final TextView textView = new TextView(context); 44 final LinkSpan linkSpan = new LinkSpan("test_id"); 45 46 linkSpan.onClick(textView); 47 48 // This would be no-op, because the context doesn't implement LinkSpan.OnClickListener. 49 // Just check that no uncaught exception here. 50 } 51 52 private static class TestContext extends ContextWrapper implements LinkSpan.OnClickListener { 53 54 public LinkSpan clickedSpan = null; 55 56 public TestContext(Context base) { 57 super(base); 58 } 59 60 @Override 61 public void onClick(LinkSpan span) { 62 clickedSpan = span; 63 } 64 } 65} 66