use of android.test.mock.MockResources in project android-UniversalMusicPlayer by googlesamples.
the class MusicProviderTest method testGetChildren.
@Test
public void testGetChildren() throws Exception {
MockResources resources = new MockResources() {
@NonNull
@Override
public String getString(int id) throws NotFoundException {
return "";
}
@NonNull
@Override
public String getString(int id, Object... formatArgs) throws NotFoundException {
return "";
}
};
// test an invalid root
List<MediaBrowserCompat.MediaItem> invalid = provider.getChildren("INVALID_MEDIA_ID", resources);
assertEquals(0, invalid.size());
// test level 1 (list of category types - only "by genre" for now)
List<MediaBrowserCompat.MediaItem> level1 = provider.getChildren(MediaIDHelper.MEDIA_ID_ROOT, resources);
assertEquals(1, level1.size());
// test level 2 (list of genres)
int genreCount = 0;
for (String ignored : provider.getGenres()) {
genreCount++;
}
List<MediaBrowserCompat.MediaItem> level2 = provider.getChildren(level1.get(0).getMediaId(), resources);
assertEquals(genreCount, level2.size());
// test level 3 (list of music for a given genre)
List<MediaBrowserCompat.MediaItem> level3 = provider.getChildren(level2.get(0).getMediaId(), resources);
String genre = MediaIDHelper.extractBrowseCategoryValueFromMediaID(level2.get(0).getMediaId());
for (MediaBrowserCompat.MediaItem mediaItem : level3) {
assertTrue(mediaItem.isPlayable());
assertFalse(mediaItem.isBrowsable());
MediaMetadataCompat metadata = provider.getMusic(MediaIDHelper.extractMusicIDFromMediaID(mediaItem.getMediaId()));
assertEquals(genre, metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE));
}
// test an invalid level 4
List<MediaBrowserCompat.MediaItem> invalidLevel4 = provider.getChildren(level3.get(0).getMediaId(), resources);
assertTrue(invalidLevel4.isEmpty());
}
use of android.test.mock.MockResources in project android-UniversalMusicPlayer by googlesamples.
the class PlaybackManagerTest method setUpMusicProvider.
@Before
public void setUpMusicProvider() throws Exception {
SimpleMusicProviderSource source = new SimpleMusicProviderSource();
populateMusicSource(source);
musicProvider = TestSetupHelper.setupMusicProvider(source);
resources = new MockResources() {
@NonNull
@Override
public String getString(int id) throws NotFoundException {
return "";
}
@NonNull
@Override
public String getString(int id, Object... formatArgs) throws NotFoundException {
return "";
}
};
}
use of android.test.mock.MockResources in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class TetherServiceTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
MockitoAnnotations.initMocks(this);
mResources = new MockResources();
mContext = new TestContextWrapper(getContext());
setContext(mContext);
mResultReceiver = new Receiver(this);
mLastReceiverResultCode = BOGUS_RECEIVER_RESULT;
mProvisionResponse = Activity.RESULT_OK;
mProvisionReceiver = new ProvisionReceiver();
IntentFilter filter = new IntentFilter(TEST_NO_UI_ACTION);
filter.addCategory(Intent.CATEGORY_DEFAULT);
mContext.registerReceiver(mProvisionReceiver, filter);
final String CURRENT_TYPES = "currentTethers";
when(mPrefs.getString(CURRENT_TYPES, "")).thenReturn("");
when(mPrefs.edit()).thenReturn(mPrefEditor);
when(mPrefEditor.putString(eq(CURRENT_TYPES), mStoredTypes.capture())).thenReturn(mPrefEditor);
mUsageStatsManagerWrapper = new FakeUsageStatsManagerWrapper(mContext);
ResolveInfo systemAppResolveInfo = new ResolveInfo();
ActivityInfo systemActivityInfo = new ActivityInfo();
systemActivityInfo.packageName = ENTITLEMENT_PACKAGE_NAME;
ApplicationInfo systemAppInfo = new ApplicationInfo();
systemAppInfo.flags |= ApplicationInfo.FLAG_SYSTEM;
systemActivityInfo.applicationInfo = systemAppInfo;
systemAppResolveInfo.activityInfo = systemActivityInfo;
ResolveInfo nonSystemResolveInfo = new ResolveInfo();
ActivityInfo nonSystemActivityInfo = new ActivityInfo();
nonSystemActivityInfo.packageName = FAKE_PACKAGE_NAME;
nonSystemActivityInfo.applicationInfo = new ApplicationInfo();
nonSystemResolveInfo.activityInfo = nonSystemActivityInfo;
List<ResolveInfo> resolvers = new ArrayList();
resolvers.add(nonSystemResolveInfo);
resolvers.add(systemAppResolveInfo);
when(mPackageManager.queryBroadcastReceivers(any(Intent.class), eq(PackageManager.MATCH_ALL))).thenReturn(resolvers);
}
Aggregations