diff options
| author | 2022-09-22 10:59:21 +0900 | |
|---|---|---|
| committer | 2022-09-22 12:33:25 +0900 | |
| commit | e364c22dcba7de0e1df681b99f9f0d77ec8c1269 (patch) | |
| tree | 02e1a17099c75c87ff6a37ca2363bff3eeed1918 | |
| parent | 82bd3a2026692c656bce8be0e1f1aaba0f3e05df (diff) | |
Prevent NPE in CoreSettingsObserverTest
The constructor of AppBatteryTracker#AppBatteryPolicy updated in a
commit [1] and now that the test need to be changed, similar to another
previous commit [2].
[1] Iffa7ff2b7fb8f14f1a54359d72d936c721d27904
[2] I2f808828eba79147fea3a88279effffb7b5b20a4
Bug: 245454635
Test: CoreSettingsObserverTest
Change-Id: I1e890e93868b605fe9c413a8749c694d6f59c1c3
| -rw-r--r-- | services/tests/servicestests/src/com/android/server/am/CoreSettingsObserverTest.java | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/services/tests/servicestests/src/com/android/server/am/CoreSettingsObserverTest.java b/services/tests/servicestests/src/com/android/server/am/CoreSettingsObserverTest.java index 693bc7dc4a42..574aaf00e460 100644 --- a/services/tests/servicestests/src/com/android/server/am/CoreSettingsObserverTest.java +++ b/services/tests/servicestests/src/com/android/server/am/CoreSettingsObserverTest.java @@ -24,10 +24,12 @@ import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.anyInt; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.content.Context; import android.content.res.Resources; +import android.content.res.TypedArray; import android.os.Bundle; import android.os.Handler; import android.provider.Settings; @@ -99,6 +101,9 @@ public class CoreSettingsObserverTest { // To prevent NullPointerException at the constructor of ActivityManagerConstants. when(mResources.getStringArray(anyInt())).thenReturn(new String[0]); when(mResources.getIntArray(anyInt())).thenReturn(new int[0]); + final TypedArray mockTypedArray = mock(TypedArray.class); + when(mockTypedArray.length()).thenReturn(1); + when(mResources.obtainTypedArray(anyInt())).thenReturn(mockTypedArray); mAms = new ActivityManagerService(new TestInjector(mContext), mServiceThreadRule.getThread()); |