1 /* 2 * Copyright (C) 2017 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 17 package androidx.emoji.widget; 18 19 import static org.junit.Assert.assertNull; 20 import static org.junit.Assert.assertSame; 21 import static org.mockito.Mockito.mock; 22 23 import android.support.test.InstrumentationRegistry; 24 import android.support.test.filters.SdkSuppress; 25 import android.support.test.filters.SmallTest; 26 import android.support.test.runner.AndroidJUnit4; 27 import android.text.InputFilter; 28 import android.text.method.TransformationMethod; 29 import android.widget.TextView; 30 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 35 @SmallTest 36 @RunWith(AndroidJUnit4.class) 37 @SdkSuppress(maxSdkVersion = 18) 38 public class EmojiTextViewHelperPre19Test { 39 EmojiTextViewHelper mTextViewHelper; 40 TextView mTextView; 41 42 @Before 43 public void setup() { 44 mTextView = new TextView(InstrumentationRegistry.getTargetContext()); 45 mTextViewHelper = new EmojiTextViewHelper(mTextView); 46 } 47 48 @Test 49 public void testUpdateTransformationMethod_doesNotUpdateTransformationMethod() { 50 final TransformationMethod tm = mock(TransformationMethod.class); 51 mTextView.setTransformationMethod(tm); 52 53 mTextViewHelper.updateTransformationMethod(); 54 55 assertSame(tm, mTextView.getTransformationMethod()); 56 } 57 58 @Test 59 public void testGetFilters_returnsSameFilters() { 60 final InputFilter existingFilter = mock(InputFilter.class); 61 final InputFilter[] filters = new InputFilter[]{existingFilter}; 62 63 final InputFilter[] newFilters = mTextViewHelper.getFilters(filters); 64 65 assertSame(filters, newFilters); 66 } 67 68 @Test 69 public void testGetTransformationMethod_returnSameTransformationMethod() { 70 assertNull(mTextViewHelper.wrapTransformationMethod(null)); 71 72 final TransformationMethod tm = mock(TransformationMethod.class); 73 assertSame(tm, mTextViewHelper.wrapTransformationMethod(tm)); 74 } 75 76 @Test 77 public void testSetAllCaps_doesNotUpdateTransformationMethod() { 78 final TransformationMethod tm = mock(TransformationMethod.class); 79 mTextView.setTransformationMethod(tm); 80 mTextViewHelper.setAllCaps(true); 81 assertSame(tm, mTextView.getTransformationMethod()); 82 83 mTextViewHelper.setAllCaps(false); 84 assertSame(tm, mTextView.getTransformationMethod()); 85 } 86 } 87