MediaItemDataStoreFactory { public MediaItemDataStore create( final int id ) { Log.d( TAG, "create : enter" ); if( cache.contains( String.valueOf( id ) ) ) { Log.d( TAG, "create : exit, getting mediaItemEntity from cache" ); return new DiskMediaItemDataStore( this.dvrDataStoreFactory, this.contentDataStoreFactory, cache ); } else { Log.d( TAG, "create : exit, getting mediaItemEntity from master backend" ); return createMasterBackendDataStore(); } } @Inject  MediaItemDataStoreFactory(
            final DvrDataStoreFactory dvrDataStoreFactory,
            final VideoDataStoreFactory videoDataStoreFactory,
            final ContentDataStoreFactory contentDataStoreFactory,
            final SearchDataStoreFactory searchDataStoreFactory,
            final DualCache<MediaItemEntity> cache
    ); MediaItemDataStore create( final int id ); MediaItemDataStore createMasterBackendDataStore();  }
@Test public void testCreateWithCache() { given( mockCache.contains( anyString() ) ).willReturn( true ); MediaItemDataStore mediaItemDataStore = mediaItemDataStoreFactory.create( FAKE_ID ); assertThat( mediaItemDataStore ) .isNotNull() .isInstanceOf( DiskMediaItemDataStore.class ); verify( mockCache, times( 1 ) ).contains( anyString() ); }
@Test public void testCreateWithoutCache() { given( mockCache.contains( anyString() ) ).willReturn( false ); MediaItemDataStore mediaItemDataStore = mediaItemDataStoreFactory.create( FAKE_ID ); assertThat( mediaItemDataStore ) .isNotNull() .isInstanceOf( MasterBackendMediaItemDataStore.class ); verify( mockCache, times( 1 ) ).contains( anyString() ); }