1 /* 2 * Copyright (C) 2023 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.ui.view.layout 18 19 import androidx.test.ext.junit.runners.AndroidJUnit4 20 import androidx.test.filters.SmallTest 21 import com.android.systemui.SysuiTestCase 22 import com.android.systemui.keyguard.data.repository.KeyguardBlueprintRepository 23 import com.android.systemui.keyguard.domain.interactor.KeyguardBlueprintInteractor 24 import com.android.systemui.statusbar.commandline.Command 25 import com.android.systemui.statusbar.commandline.CommandRegistry 26 import com.android.systemui.util.mockito.eq 27 import com.android.systemui.util.mockito.withArgCaptor 28 import java.io.PrintWriter 29 import org.junit.Before 30 import org.junit.Test 31 import org.junit.runner.RunWith 32 import org.mockito.ArgumentMatchers.anyString 33 import org.mockito.Mock 34 import org.mockito.Mockito.atLeastOnce 35 import org.mockito.Mockito.never 36 import org.mockito.Mockito.verify 37 import org.mockito.MockitoAnnotations 38 39 @RunWith(AndroidJUnit4::class) 40 @SmallTest 41 class KeyguardBlueprintCommandListenerTest : SysuiTestCase() { 42 private lateinit var keyguardBlueprintCommandListener: KeyguardBlueprintCommandListener 43 @Mock private lateinit var commandRegistry: CommandRegistry 44 @Mock private lateinit var keyguardBlueprintRepository: KeyguardBlueprintRepository 45 @Mock private lateinit var keyguardBlueprintInteractor: KeyguardBlueprintInteractor 46 @Mock private lateinit var pw: PrintWriter 47 private lateinit var command: () -> Command 48 49 @Before setupnull50 fun setup() { 51 MockitoAnnotations.initMocks(this) 52 keyguardBlueprintCommandListener = 53 KeyguardBlueprintCommandListener( 54 commandRegistry, 55 keyguardBlueprintRepository, 56 keyguardBlueprintInteractor, 57 ) 58 keyguardBlueprintCommandListener.start() 59 command = 60 withArgCaptor<() -> Command> { 61 verify(commandRegistry).registerCommand(eq("blueprint"), capture()) 62 } 63 } 64 65 @Test testHelpnull66 fun testHelp() { 67 command().execute(pw, listOf("help")) 68 verify(pw, atLeastOnce()).println(anyString()) 69 verify(keyguardBlueprintInteractor, never()).transitionOrRefreshBlueprint(anyString()) 70 } 71 72 @Test testBlanknull73 fun testBlank() { 74 command().execute(pw, listOf()) 75 verify(pw, atLeastOnce()).println(anyString()) 76 verify(keyguardBlueprintInteractor, never()).transitionOrRefreshBlueprint(anyString()) 77 } 78 79 @Test testValidArgnull80 fun testValidArg() { 81 command().execute(pw, listOf("fake")) 82 verify(keyguardBlueprintInteractor).transitionOrRefreshBlueprint("fake") 83 } 84 } 85