/* * Copyright (C) 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.privatespace.filetransfer import android.content.Context import android.multiuser.Flags import android.platform.test.annotations.RequiresFlagsEnabled import android.platform.test.flag.junit.CheckFlagsRule import android.platform.test.flag.junit.DeviceFlagsValueProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.test.runTest import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations import org.mockito.kotlin.whenever @RequiresFlagsEnabled(Flags.FLAG_ENABLE_MOVING_CONTENT_INTO_PRIVATE_SPACE) @RunWith(AndroidJUnit4::class) class FileTransferStateCheckerTest { @get:Rule val checkFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule() private lateinit var fileTransferStateChecker: FileTransferStateChecker @Mock private lateinit var notificationsHelper: NotificationsHelper @Mock private lateinit var fileTransferStateRepository: FakeFileTransferStateRepository @Mock private lateinit var context: Context private var closeable: AutoCloseable? = null @Before fun setUp() { closeable = MockitoAnnotations.openMocks(this) fileTransferStateChecker = FileTransferStateChecker(fileTransferStateRepository, notificationsHelper) } @After fun tearDown() { closeable?.close() } @Test fun testCheckTransferState_shouldNotifyUser() = runTest { val testState = TransferState(keepOriginal = true, transferInProgress = true) whenever(fileTransferStateRepository.getTransferState(context)).thenReturn(testState) fileTransferStateChecker.postBootTransferStateCheck(context) verify(notificationsHelper).displayInterruptedTransferNotification(testState.keepOriginal) verify(fileTransferStateRepository) .saveState(context, testState.keepOriginal, transferInProgress = false) } @Test fun testCheckTransferState_shouldNotNotifyUser() = runTest { val testState = TransferState(keepOriginal = true, transferInProgress = false) whenever(fileTransferStateRepository.getTransferState(context)).thenReturn(testState) fileTransferStateChecker.postBootTransferStateCheck(context) verify(notificationsHelper, never()).createNotificationChannel() verify(notificationsHelper, never()) .displayInterruptedTransferNotification(testState.keepOriginal) verify(fileTransferStateRepository, never()) .saveState(context, testState.keepOriginal, transferInProgress = false) } }