MediaItemEntityDataMapper { public static List<MediaItemEntity> transformPrograms( Collection<ProgramEntity> programEntityCollection ) throws UnsupportedEncodingException { List<MediaItemEntity> mediaItemList = new ArrayList<>( programEntityCollection.size() ); MediaItemEntity mediaItem; for( ProgramEntity programEntity : programEntityCollection ) { mediaItem = transform( programEntity ); if( null != mediaItem && null != mediaItem.media() ) { Log.i( TAG, "transformPrograms : mediaItemEntity=" + mediaItem.toString() ); mediaItemList.add( mediaItem ); } } return mediaItemList; } private  MediaItemEntityDataMapper(); static MediaItemEntity transform( ProgramEntity programEntity ); static List<MediaItemEntity> transformPrograms( Collection<ProgramEntity> programEntityCollection ); static MediaItemEntity transform( VideoMetadataInfoEntity videoEntity ); static List<MediaItemEntity> transformVideos( Collection<VideoMetadataInfoEntity> videoEntityCollection );  }
@Test public void testTransformUpcoming() throws Exception { try( BufferedReader bufferedReader = new BufferedReader( new InputStreamReader( getClass().getClassLoader().getResourceAsStream( "org/mythtv/android/data/entity/mapper/Dvr_GetUpcomingList.json" ) ) ) ) { String line = null; String message = new String(); final StringBuffer buffer = new StringBuffer( 2048 ); while( ( line = bufferedReader.readLine()) != null ) { message += line; } List<ProgramEntity> programEntities = programEntityJsonMapper.transformProgramEntityCollection( message ); assertThat( programEntities, not(nullValue() ) ); List<MediaItemEntity> mediaItems = MediaItemEntityDataMapper.transformPrograms( programEntities ); assertThat( mediaItems, not( nullValue()) ); assertThat( mediaItems, hasSize(equalTo( 40 ) ) ); for( MediaItemEntity mediaItem : mediaItems ) { assertThat( mediaItem.isValid(), is( true ) ); assertThat( mediaItem.validationErrors(), hasSize( 0 ) ); } } }