Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.27] Fix TestPowerManagementService Tests #12369

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@

package com.nextcloud.client.device

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.BatteryManager
import android.os.Build
import android.os.PowerManager
import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.utils.extensions.registerBroadcastReceiver
import com.owncloud.android.datamodel.ReceiverFlag
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
Expand Down Expand Up @@ -128,6 +127,7 @@ class TestPowerManagementService {
}
}

@SuppressLint("UnspecifiedRegisterReceiverFlag")
class Battery : Base() {

companion object {
Expand All @@ -139,7 +139,7 @@ class TestPowerManagementService {

@Before
fun setUp() {
whenever(context.registerBroadcastReceiver(anyOrNull(), anyOrNull(), ReceiverFlag.NotExported)).thenReturn(
whenever(context.registerReceiver(anyOrNull(), anyOrNull())).thenReturn(
intent
)
}
Expand Down Expand Up @@ -197,14 +197,14 @@ class TestPowerManagementService {
// device has API level P or below
// battery status sticky intent is NOT available
whenever(deviceInfo.apiLevel).thenReturn(Build.VERSION_CODES.P)
whenever(context.registerBroadcastReceiver(anyOrNull(), anyOrNull(), ReceiverFlag.NotExported)).thenReturn(
whenever(context.registerReceiver(anyOrNull(), anyOrNull())).thenReturn(
null
)

// THEN
// charging flag is false
assertFalse(powerManagementService.battery.isCharging)
verify(context).registerBroadcastReceiver(anyOrNull(), any(), ReceiverFlag.NotExported)
verify(context).registerReceiver(anyOrNull(), any())
}

@Test
Expand Down
Loading