Inject mocks in RemoteVolumeControllerTest via constructor

This fix avoids the test wrongfully initializing real components before
the tests can modify mockable fields, which causes NPEs.

Bug: 318078730
Test: atest RemoteVolumeGroupControllerTest
Change-Id: I350e3e2e45eadb0f9737ba5d4b45c9f80e3355fb
This commit is contained in:
Iván Budnik
2023-12-29 17:05:05 +00:00
parent 946f52b2a1
commit b02f9f38e4
2 changed files with 20 additions and 3 deletions

View File

@@ -103,9 +103,9 @@ public class RemoteVolumeGroupControllerTest {
mContext = spy(RuntimeEnvironment.application);
doReturn(mMediaSessionManager).when(mContext).getSystemService(
Context.MEDIA_SESSION_SERVICE);
mController = new RemoteVolumeGroupController(mContext, KEY_REMOTE_VOLUME_GROUP);
mController.mLocalMediaManager = mLocalMediaManager;
mController.mRouterManager = mRouterManager;
mController =
new RemoteVolumeGroupController(
mContext, KEY_REMOTE_VOLUME_GROUP, mLocalMediaManager, mRouterManager);
mPreferenceCategory = spy(new PreferenceCategory(mContext));
mPreferenceCategory.setKey(mController.getPreferenceKey());