Search in sources :

Example 1 with MockResources

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());
}
Also used : MediaBrowserCompat(android.support.v4.media.MediaBrowserCompat) MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) MockResources(android.test.mock.MockResources) Test(org.junit.Test)

Example 2 with MockResources

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 "";
        }
    };
}
Also used : SimpleMusicProviderSource(com.example.android.uamp.utils.SimpleMusicProviderSource) NonNull(android.support.annotation.NonNull) MockResources(android.test.mock.MockResources) Before(org.junit.Before)

Example 3 with MockResources

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);
}
Also used : IntentFilter(android.content.IntentFilter) ActivityInfo(android.content.pm.ActivityInfo) ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) BroadcastReceiver(android.content.BroadcastReceiver) ResultReceiver(android.os.ResultReceiver) MockResources(android.test.mock.MockResources) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo)

Aggregations

MockResources (android.test.mock.MockResources)3 PendingIntent (android.app.PendingIntent)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 ActivityInfo (android.content.pm.ActivityInfo)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 ResolveInfo (android.content.pm.ResolveInfo)1 ResultReceiver (android.os.ResultReceiver)1 NonNull (android.support.annotation.NonNull)1 MediaBrowserCompat (android.support.v4.media.MediaBrowserCompat)1 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)1 SimpleMusicProviderSource (com.example.android.uamp.utils.SimpleMusicProviderSource)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.Test)1