Merge "Fixes @Nullable issues SystemUI-tests" into udc-qpr-dev

This commit is contained in:
Colin Cross
2023-08-14 17:50:53 +00:00
committed by Android (Google) Code Review
24 changed files with 50 additions and 56 deletions

View File

@@ -409,6 +409,7 @@ android_library {
"mockito-target-extended-minus-junit4",
"androidx.test.ext.junit",
"androidx.test.ext.truth",
"kotlin-test",
],
libs: [
"android.test.runner",

View File

@@ -543,7 +543,8 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
@Nullable
@Override
public Animator createAnimator(ViewGroup sceneRoot, @Nullable TransitionValues startValues,
public Animator createAnimator(@NonNull ViewGroup sceneRoot,
@Nullable TransitionValues startValues,
@Nullable TransitionValues endValues) {
if (startValues == null || endValues == null) {
return null;

View File

@@ -150,7 +150,7 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() {
private fun getPatternTopGuideline(): Float {
val cs = ConstraintSet()
val container =
mKeyguardPatternView.findViewById(R.id.pattern_container) as ConstraintLayout
mKeyguardPatternView.requireViewById(R.id.pattern_container) as ConstraintLayout
cs.clone(container)
return cs.getConstraint(R.id.pattern_top_guideline).layout.guidePercent
}

View File

@@ -114,7 +114,7 @@ class KeyguardPinViewControllerTest : SysuiTestCase() {
objectKeyguardPINView =
View.inflate(mContext, R.layout.keyguard_pin_view, null)
.findViewById(R.id.keyguard_pin_view) as KeyguardPINView
.requireViewById(R.id.keyguard_pin_view) as KeyguardPINView
}
private fun constructPinViewController(
@@ -175,7 +175,7 @@ class KeyguardPinViewControllerTest : SysuiTestCase() {
private fun getPinTopGuideline(): Float {
val cs = ConstraintSet()
val container = objectKeyguardPINView.findViewById(R.id.pin_container) as ConstraintLayout
val container = objectKeyguardPINView.requireViewById(R.id.pin_container) as ConstraintLayout
cs.clone(container)
return cs.getConstraint(R.id.pin_pad_top_guideline).layout.guidePercent
}

View File

@@ -21,9 +21,9 @@ class KeyguardStatusViewTest : SysuiTestCase() {
private lateinit var keyguardStatusView: KeyguardStatusView
private val mediaView: View
get() = keyguardStatusView.findViewById(R.id.status_view_media_container)
get() = keyguardStatusView.requireViewById(R.id.status_view_media_container)
private val statusViewContainer: ViewGroup
get() = keyguardStatusView.findViewById(R.id.status_view_container)
get() = keyguardStatusView.requireViewById(R.id.status_view_container)
private val childrenExcludingMedia
get() = statusViewContainer.children.filter { it != mediaView }

View File

@@ -19,9 +19,11 @@ import android.animation.Animator
import android.testing.AndroidTestingRunner
import android.transition.TransitionValues
import android.view.View
import android.view.ViewGroup
import androidx.test.filters.SmallTest
import com.android.keyguard.KeyguardStatusViewController.SplitShadeTransitionAdapter
import com.android.systemui.SysuiTestCase
import com.android.systemui.util.mockito.mock
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
@@ -84,5 +86,5 @@ private fun SplitShadeTransitionAdapter.createAnimator(
startValues: TransitionValues?,
endValues: TransitionValues?
): Animator? {
return createAnimator(/* sceneRoot= */ null, startValues, endValues)
return createAnimator(/* sceneRoot= */ mock(), startValues, endValues)
}

View File

@@ -70,7 +70,7 @@ class DialogLaunchAnimatorTest : SysuiTestCase() {
assertTrue(dialog.isShowing)
// The dialog is now fullscreen.
val window = dialog.window
val window = checkNotNull(dialog.window)
val decorView = window.decorView as DecorView
assertEquals(MATCH_PARENT, window.attributes.width)
assertEquals(MATCH_PARENT, window.attributes.height)
@@ -172,14 +172,15 @@ class DialogLaunchAnimatorTest : SysuiTestCase() {
// Important: the power menu animation relies on this behavior to know when to animate (see
// http://ag/16774605).
val dialog = runOnMainThreadAndWaitForIdleSync { TestDialog(context) }
dialog.window.setWindowAnimations(0)
assertEquals(0, dialog.window.attributes.windowAnimations)
val window = checkNotNull(dialog.window)
window.setWindowAnimations(0)
assertEquals(0, window.attributes.windowAnimations)
val touchSurface = createTouchSurface()
runOnMainThreadAndWaitForIdleSync {
dialogLaunchAnimator.showFromView(dialog, touchSurface)
}
assertNotEquals(0, dialog.window.attributes.windowAnimations)
assertNotEquals(0, window.attributes.windowAnimations)
}
@Test
@@ -351,13 +352,14 @@ class DialogLaunchAnimatorTest : SysuiTestCase() {
init {
// We need to set the window type for dialogs shown by SysUI, otherwise WM will throw.
window.setType(WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL)
checkNotNull(window).setType(WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(contentView)
val window = checkNotNull(window)
window.setLayout(DIALOG_WIDTH, DIALOG_HEIGHT)
window.setBackgroundDrawable(windowBackground)
}

View File

@@ -211,7 +211,7 @@ class WiredChargingRippleControllerTest : SysuiTestCase() {
context.resources.getFloat(R.dimen.physical_charger_port_location_normalized_y)
val expectedCenterX: Float
val expectedCenterY: Float
when (context.display.rotation) {
when (checkNotNull(context.display).rotation) {
Surface.ROTATION_90 -> {
expectedCenterX = width * normalizedPortPosY
expectedCenterY = height * (1 - normalizedPortPosX)

View File

@@ -125,7 +125,7 @@ class ControlViewHolderTest : SysuiTestCase() {
control
)
cvh.bindData(cws, false)
val chevronIcon = baseLayout.findViewById<View>(R.id.chevron_icon)
val chevronIcon = baseLayout.requireViewById<View>(R.id.chevron_icon)
assertThat(chevronIcon.visibility).isEqualTo(View.VISIBLE)
}
@@ -138,4 +138,4 @@ private const val TINT_COLOR = 0x00ff00 // Should be different from [COLOR]
private val DRAWABLE = GradientDrawable()
private val COLOR = ColorStateList.valueOf(0xffff00)
private val DEFAULT_CONTROL = Control.StatelessBuilder(
CONTROL_ID, mock(PendingIntent::class.java)).build()
CONTROL_ID, mock(PendingIntent::class.java)).build()

View File

@@ -365,7 +365,8 @@ class ControlsUiControllerImplTest : SysuiTestCase() {
val selectedItems =
listOf(
SelectedItem.StructureItem(
StructureInfo(ComponentName.unflattenFromString("pkg/.cls1"), "a", ArrayList())
StructureInfo(checkNotNull(ComponentName.unflattenFromString("pkg/.cls1")),
"a", ArrayList())
),
)
preferredPanelRepository.setSelectedComponent(

View File

@@ -332,9 +332,6 @@ class DeviceEntryFaceAuthRepositoryTest : SysuiTestCase() {
)
.isFalse()
whenever(faceManager.sensorPropertiesInternal).thenReturn(null)
assertThat(createDeviceEntryFaceAuthRepositoryImpl().isDetectionSupported).isFalse()
whenever(faceManager.sensorPropertiesInternal).thenReturn(listOf())
assertThat(createDeviceEntryFaceAuthRepositoryImpl().isDetectionSupported).isFalse()

View File

@@ -132,7 +132,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
@Before
fun setup() {
MockitoAnnotations.initMocks(this)
context.resources.configuration.locales = LocaleList(Locale.US, Locale.UK)
context.resources.configuration.setLocales(LocaleList(Locale.US, Locale.UK))
transitionRepository = FakeKeyguardTransitionRepository()
mediaCarouselController =
MediaCarouselController(
@@ -730,13 +730,13 @@ class MediaCarouselControllerTest : SysuiTestCase() {
@Test
fun testOnLocaleListChanged_playersAreAddedBack() {
context.resources.configuration.locales = LocaleList(Locale.US, Locale.UK, Locale.CANADA)
context.resources.configuration.setLocales(LocaleList(Locale.US, Locale.UK, Locale.CANADA))
testConfigurationChange(configListener.value::onLocaleListChanged)
verify(pageIndicator, never()).tintList =
ColorStateList.valueOf(context.getColor(R.color.media_paging_indicator))
context.resources.configuration.locales = LocaleList(Locale.UK, Locale.US, Locale.CANADA)
context.resources.configuration.setLocales(LocaleList(Locale.UK, Locale.US, Locale.CANADA))
testConfigurationChange(configListener.value::onLocaleListChanged)
verify(pageIndicator).tintList =

View File

@@ -123,7 +123,7 @@ class TaskPreviewSizeProviderTest : SysuiTestCase() {
private fun givenDisplay(width: Int, height: Int, isTablet: Boolean = false) {
val bounds = Rect(0, 0, width, height)
val windowMetrics = WindowMetrics(bounds, null)
val windowMetrics = WindowMetrics(bounds, { null }, 1.0f)
whenever(windowManager.maximumWindowMetrics).thenReturn(windowMetrics)
whenever(windowManager.currentWindowMetrics).thenReturn(windowMetrics)

View File

@@ -107,20 +107,6 @@ class MediaProjectionManagerRepositoryTest : SysuiTestCase() {
assertThat(state).isEqualTo(MediaProjectionState.EntireScreen)
}
@Test
fun mediaProjectionState_onSessionSet_tokenNull_emitsEntireScreen() =
testScope.runTest {
val state by collectLastValue(repo.mediaProjectionState)
runCurrent()
fakeMediaProjectionManager.dispatchOnSessionSet(
session =
ContentRecordingSession.createTaskSession(/* taskWindowContainerToken= */ null)
)
assertThat(state).isEqualTo(MediaProjectionState.EntireScreen)
}
@Test
fun mediaProjectionState_sessionSet_taskWithToken_noMatchingRunningTask_emitsEntireScreen() =
testScope.runTest {

View File

@@ -73,7 +73,7 @@ class BackPanelControllerTest : SysuiTestCase() {
context,
windowManager,
ViewConfiguration.get(context),
Handler.createAsync(Looper.myLooper()),
Handler.createAsync(checkNotNull(Looper.myLooper())),
vibratorHelper,
configurationController,
latencyTracker,

View File

@@ -69,6 +69,7 @@ import com.android.wm.shell.bubbles.Bubble
import com.android.wm.shell.bubbles.Bubbles
import com.google.common.truth.Truth.assertThat
import java.util.Optional
import kotlin.test.assertNotNull
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
@@ -672,7 +673,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() {
extras().bool(EXTRA_USE_STYLUS_MODE).isTrue()
}
iconCaptor.value?.let { icon ->
assertThat(icon).isNotNull()
assertNotNull(icon)
assertThat(icon.resId).isEqualTo(R.drawable.ic_note_task_shortcut_widget)
}
}
@@ -755,7 +756,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() {
assertThat(shortLabel).isEqualTo(NOTE_TASK_SHORT_LABEL)
assertThat(longLabel).isEqualTo(NOTE_TASK_LONG_LABEL)
assertThat(isLongLived).isEqualTo(true)
assertThat(icon.resId).isEqualTo(R.drawable.ic_note_task_shortcut_widget)
assertThat(icon?.resId).isEqualTo(R.drawable.ic_note_task_shortcut_widget)
assertThat(extras?.getString(EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE))
.isEqualTo(NOTE_TASK_PACKAGE_NAME)
}

View File

@@ -126,6 +126,7 @@ class ScreenRecordPermissionDialogTest : SysuiTestCase() {
private fun onSpinnerItemSelected(position: Int) {
val spinner = dialog.requireViewById<Spinner>(R.id.screen_share_mode_spinner)
spinner.onItemSelectedListener.onItemSelected(spinner, mock(), position, /* id= */ 0)
checkNotNull(spinner.onItemSelectedListener)
.onItemSelected(spinner, mock(), position, /* id= */ 0)
}
}

View File

@@ -584,7 +584,7 @@ class NotificationsQSContainerControllerLegacyTest : SysuiTestCase() {
private fun emptyInsets() = mock(WindowInsets::class.java)
private fun WindowInsets.withCutout(): WindowInsets {
whenever(displayCutout.safeInsetBottom).thenReturn(CUTOUT_HEIGHT)
whenever(checkNotNull(displayCutout).safeInsetBottom).thenReturn(CUTOUT_HEIGHT)
return this
}

View File

@@ -567,7 +567,7 @@ class NotificationsQSContainerControllerTest : SysuiTestCase() {
private fun emptyInsets() = mock(WindowInsets::class.java)
private fun WindowInsets.withCutout(): WindowInsets {
whenever(displayCutout.safeInsetBottom).thenReturn(CUTOUT_HEIGHT)
whenever(checkNotNull(displayCutout).safeInsetBottom).thenReturn(CUTOUT_HEIGHT)
return this
}

View File

@@ -236,7 +236,8 @@ class DreamSmartspaceControllerTest : SysuiTestCase() {
`when`(precondition.conditionsMet()).thenReturn(true)
// Given a session is created
val weatherView = controller.buildAndConnectWeatherView(fakeParent, customView)
val weatherView =
checkNotNull(controller.buildAndConnectWeatherView(fakeParent, customView))
controller.stateChangeListener.onViewAttachedToWindow(weatherView)
verify(smartspaceManager).createSmartspaceSession(any())
@@ -258,7 +259,8 @@ class DreamSmartspaceControllerTest : SysuiTestCase() {
// Given a session is created
val customView = Mockito.mock(TestView::class.java)
val weatherView = controller.buildAndConnectWeatherView(fakeParent, customView)
val weatherView =
checkNotNull(controller.buildAndConnectWeatherView(fakeParent, customView))
controller.stateChangeListener.onViewAttachedToWindow(weatherView)
verify(smartspaceManager).createSmartspaceSession(any())

View File

@@ -47,7 +47,7 @@ class MediaArtworkProcessorTest : SysuiTestCase() {
processor = MediaArtworkProcessor()
val point = Point()
context.display.getSize(point)
checkNotNull(context.display).getSize(point)
screenWidth = point.x
screenHeight = point.y
}
@@ -106,4 +106,4 @@ class MediaArtworkProcessorTest : SysuiTestCase() {
// THEN the processed bitmap is null
assertThat(background).isNull()
}
}
}

View File

@@ -278,7 +278,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
`when`(deviceProvisionedController.isCurrentUserSetup).thenReturn(false)
// WHEN a connection attempt is made and view is attached
val view = controller.buildAndConnectView(fakeParent)
val view = controller.buildAndConnectView(fakeParent)!!
controller.stateChangeListener.onViewAttachedToWindow(view)
// THEN no session is created

View File

@@ -212,13 +212,13 @@ class ConfigurationControllerImplTest : SysuiTestCase() {
@Test
fun localeListChanged_listenerNotified() {
val config = mContext.resources.configuration
config.locales = LocaleList(Locale.CANADA, Locale.GERMANY)
config.setLocales(LocaleList(Locale.CANADA, Locale.GERMANY))
mConfigurationController.onConfigurationChanged(config)
val listener = createAndAddListener()
// WHEN the locales are updated
config.locales = LocaleList(Locale.FRANCE, Locale.JAPAN, Locale.CHINESE)
config.setLocales(LocaleList(Locale.FRANCE, Locale.JAPAN, Locale.CHINESE))
mConfigurationController.onConfigurationChanged(config)
// THEN the listener is notified

View File

@@ -463,10 +463,10 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
val provider = StatusBarContentInsetsProvider(contextMock, configurationController,
mock(DumpManager::class.java))
configuration.windowConfiguration.maxBounds = Rect(0, 0, 1080, 2160)
configuration.windowConfiguration.setMaxBounds(Rect(0, 0, 1080, 2160))
val firstDisplayInsets = provider.getStatusBarContentAreaForRotation(ROTATION_NONE)
configuration.windowConfiguration.maxBounds = Rect(0, 0, 800, 600)
configuration.windowConfiguration.setMaxBounds(Rect(0, 0, 800, 600))
// WHEN: get insets on the second display
val secondDisplayInsets = provider.getStatusBarContentAreaForRotation(ROTATION_NONE)
@@ -482,14 +482,14 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
val provider = StatusBarContentInsetsProvider(contextMock, configurationController,
mock(DumpManager::class.java))
configuration.windowConfiguration.maxBounds = Rect(0, 0, 1080, 2160)
configuration.windowConfiguration.setMaxBounds(Rect(0, 0, 1080, 2160))
val firstDisplayInsetsFirstCall = provider
.getStatusBarContentAreaForRotation(ROTATION_NONE)
configuration.windowConfiguration.maxBounds = Rect(0, 0, 800, 600)
configuration.windowConfiguration.setMaxBounds(Rect(0, 0, 800, 600))
provider.getStatusBarContentAreaForRotation(ROTATION_NONE)
configuration.windowConfiguration.maxBounds = Rect(0, 0, 1080, 2160)
configuration.windowConfiguration.setMaxBounds(Rect(0, 0, 1080, 2160))
// WHEN: get insets on the first display again
val firstDisplayInsetsSecondCall = provider
@@ -577,4 +577,4 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
" expected=$expected actual=$actual",
expected.equals(actual))
}
}
}