Adrian Roos | 154b9ee | 2016-10-20 15:34:23 -0700 | [diff] [blame] | 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 | |
| 17 | package com.android.keyguard; |
| 18 | |
| 19 | import com.android.systemui.SysuiTestCase; |
| 20 | |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.junit.runner.RunWith; |
| 24 | |
| 25 | import android.content.Context; |
| 26 | import android.os.Handler; |
| 27 | import android.os.Looper; |
| 28 | import android.support.test.InstrumentationRegistry; |
| 29 | import android.support.test.runner.AndroidJUnit4; |
| 30 | import android.test.suitebuilder.annotation.SmallTest; |
| 31 | |
| 32 | import static junit.framework.Assert.*; |
| 33 | import static org.mockito.Mockito.mock; |
| 34 | |
| 35 | @SmallTest |
| 36 | @RunWith(AndroidJUnit4.class) |
| 37 | public class KeyguardMessageAreaTest extends SysuiTestCase { |
| 38 | private Context mContext = InstrumentationRegistry.getTargetContext(); |
| 39 | private Handler mHandler = new Handler(Looper.getMainLooper()); |
| 40 | private KeyguardMessageArea mMessageArea; |
| 41 | |
| 42 | @Before |
| 43 | public void setUp() throws Exception { |
| 44 | KeyguardUpdateMonitor monitor = mock(KeyguardUpdateMonitor.class); |
| 45 | mHandler.post(()-> mMessageArea = new KeyguardMessageArea(mContext, null, monitor)); |
| 46 | waitForIdleSync(); |
| 47 | } |
| 48 | |
| 49 | @Test |
| 50 | public void clearFollowedByMessage_keepsMessage() { |
| 51 | mHandler.post(()-> { |
| 52 | mMessageArea.setMessage(""); |
| 53 | mMessageArea.setMessage("test"); |
| 54 | }); |
| 55 | |
| 56 | waitForIdleSync(); |
| 57 | |
| 58 | CharSequence[] messageText = new CharSequence[1]; |
| 59 | mHandler.post(()-> { |
| 60 | messageText[0] = mMessageArea.getText(); |
| 61 | }); |
| 62 | |
| 63 | waitForIdleSync(); |
| 64 | |
| 65 | assertEquals("test", messageText[0]); |
| 66 | } |
| 67 | |
| 68 | } |