1 /* 2 * Copyright (C) 2021 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 com.android.systemui.keyguard; 18 19 import static android.graphics.Color.WHITE; 20 21 import static org.junit.Assert.assertEquals; 22 23 import android.content.res.ColorStateList; 24 import android.graphics.Canvas; 25 import android.graphics.ColorFilter; 26 import android.graphics.drawable.Drawable; 27 import android.testing.AndroidTestingRunner; 28 29 import androidx.annotation.NonNull; 30 import androidx.annotation.Nullable; 31 import androidx.test.filters.SmallTest; 32 33 import com.android.systemui.SysuiTestCase; 34 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 38 @RunWith(AndroidTestingRunner.class) 39 @SmallTest 40 public class KeyguardIndicationTest extends SysuiTestCase { 41 42 @Test(expected = IllegalStateException.class) testCannotCreateIndicationWithoutMessageOrIcon()43 public void testCannotCreateIndicationWithoutMessageOrIcon() { 44 new KeyguardIndication.Builder() 45 .setTextColor(ColorStateList.valueOf(WHITE)) 46 .build(); 47 } 48 49 @Test(expected = IllegalStateException.class) testCannotCreateIndicationWithoutColor()50 public void testCannotCreateIndicationWithoutColor() { 51 new KeyguardIndication.Builder() 52 .setMessage("message") 53 .build(); 54 } 55 56 @Test(expected = IllegalStateException.class) testCannotCreateIndicationWithEmptyMessage()57 public void testCannotCreateIndicationWithEmptyMessage() { 58 new KeyguardIndication.Builder() 59 .setMessage("") 60 .setTextColor(ColorStateList.valueOf(WHITE)) 61 .build(); 62 } 63 64 @Test testCreateIndicationWithMessage()65 public void testCreateIndicationWithMessage() { 66 final String text = "regular indication"; 67 final KeyguardIndication indication = new KeyguardIndication.Builder() 68 .setMessage(text) 69 .setTextColor(ColorStateList.valueOf(WHITE)) 70 .build(); 71 assertEquals(text, indication.getMessage()); 72 } 73 74 @Test testCreateIndicationWithIcon()75 public void testCreateIndicationWithIcon() { 76 final KeyguardIndication indication = new KeyguardIndication.Builder() 77 .setIcon(mDrawable) 78 .setTextColor(ColorStateList.valueOf(WHITE)) 79 .build(); 80 assertEquals(mDrawable, indication.getIcon()); 81 } 82 83 @Test testCreateIndicationWithMessageAndIcon()84 public void testCreateIndicationWithMessageAndIcon() { 85 final String text = "indication with msg and icon"; 86 final KeyguardIndication indication = new KeyguardIndication.Builder() 87 .setMessage(text) 88 .setIcon(mDrawable) 89 .setTextColor(ColorStateList.valueOf(WHITE)) 90 .build(); 91 assertEquals(text, indication.getMessage()); 92 assertEquals(mDrawable, indication.getIcon()); 93 } 94 95 final Drawable mDrawable = new Drawable() { 96 @Override 97 public void draw(@NonNull Canvas canvas) { } 98 99 @Override 100 public void setAlpha(int alpha) { } 101 102 @Override 103 public void setColorFilter(@Nullable ColorFilter colorFilter) { } 104 105 @Override 106 public int getOpacity() { 107 return 0; 108 } 109 }; 110 } 111