/* Ċ Ġ* ĠCopyright Ġ 2 0 2 0 ĠGoogle ĠLLC Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttps :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ package Ġcom . android . tv . reference . shared . parser Ċ Ċ import Ġcom . android . tv . reference . parser . Video Parser Ċ import Ġcom . android . tv . reference . shared . datamodel . Video Type Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġcom . squareup . mos hi . Json DataException Ċ import Ġorg . junit . Assert . assert Throws Ċ import Ġorg . junit . Test Ċ Ċ class ĠVideo Parser UnitTest Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġload Videos FromJson _ is Correct () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġvideo List Ġ= ĠVideo Parser . load Videos FromJson ( VALID _ JSON ) ĊĠĠĠĠĠĠĠ ĠassertThat ( video List ). has Size ( 3 ) ĊĠĠĠĠĠĠĠ Ġvideo List . forEach Indexed Ġ{ Ġindex , Ġvideo Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġtype Ġ= ĠCONTENT _ TYPES [ index ] ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( video . id ). isEqualTo ("${ type }_ id ") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( video . name ). isEqualTo ("$ type Ġname ") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( video . description ). isEqualTo (" Description Ġfor Ġ$ type ") ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġuri Base Ġ= Ġ" https :// at v - reference - app . firebase app . com / content /$ type " ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( video . uri ). isEqualTo ( uri Base ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( video . video Uri ). isEqualTo ("$ uri Base / video . mp 4 ") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( video . thumbnail Uri ). isEqualTo ("$ uri Base / thumbnail . jpg ") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( video . background Image Uri ). isEqualTo ("$ uri Base / background . jpg ") ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( video . category ). isEqualTo ("${ type } s ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġexpected Enum Ġ= Ġwhen Ġ( type ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" clip " Ġ-> ĠVideo Type . CLIP ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" episode " Ġ-> ĠVideo Type . E PI SO DE ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" movie " Ġ-> ĠVideo Type . MOV IE ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġthrow ĠRuntimeException (" Invalid Ġtype : Ġ$ type ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( video . video Type ). isEqualTo ( expected Enum ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġload Videos FromJson _ input Malformed () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThrows ( Json DataException :: class . java ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠVideo Parser . load Videos FromJson ( MAL FOR MED _ JSON ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfind Video FromJson _ video Found () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġvideo Ġ= ĠVideo Parser . find Video FromJson ( VALID _ JSON , Ġ" movie _ id ") ĊĠĠĠĠĠĠĠ ĠassertThat ( video ). isNotNull () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfind Video FromJson _ video NotFound () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġvideo Ġ= ĠVideo Parser . find Video FromJson ( VALID _ JSON , Ġ" Video Ġ 9 9 9 ") ĊĠĠĠĠĠĠĠ ĠassertThat ( video ). isNull () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfind Video FromJson _ input Malformed () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThrows ( Json DataException :: class . java ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠVideo Parser . find Video FromJson ( MAL FOR MED _ JSON , Ġ" Video Ġ 1 ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠCONTENT _ TYPES Ġ= ĠarrayOf (" clip ", Ġ" episode ", Ġ" movie ") ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠVALID _ JSON Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ""" { Ċ " content ": Ġ[ ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġ" id ": Ġ" clip _ id ", ĊĠĠĠĠĠĠĠ Ġ" name ": Ġ" clip Ġname ", ĊĠĠĠĠĠĠĠ Ġ" description ": Ġ" Description Ġfor Ġclip ", ĊĠĠĠĠĠĠĠ Ġ" uri ": Ġ" https :// at v - reference - app . firebase app . com / content / clip ", ĊĠĠĠĠĠĠĠ Ġ" video Uri ": Ġ" https :// at v - reference - app . firebase app . com / content / clip / video . mp 4 ", ĊĠĠĠĠĠĠĠ Ġ" thumbnail Uri ": Ġ" https :// at v - reference - app . firebase app . com / content / clip / thumbnail . jpg ", ĊĠĠĠĠĠĠĠ Ġ" background Uri ": Ġ" https :// at v - reference - app . firebase app . com / content / clip / background . jpg ", ĊĠĠĠĠĠĠĠ Ġ" category ": Ġ" cli ps ", ĊĠĠĠĠĠĠĠ Ġ" video Type ": Ġ" clip ", ĊĠĠĠĠĠĠĠ Ġ" series Uri ": Ġ" https :// at v - reference - app . firebase app . com / content / clip / series ", ĊĠĠĠĠĠĠĠ Ġ" season Uri ": Ġ"", ĊĠĠĠĠĠĠĠ Ġ" season Number ": Ġ"", ĊĠĠĠĠĠĠĠ Ġ" episode Number ": Ġ"", ĊĠĠĠĠĠĠĠ Ġ" duration ": Ġ" PT 0 0 H 0 0 M " ĊĠĠĠ Ġ}, ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġ" id ": Ġ" episode _ id ", ĊĠĠĠĠĠĠĠ Ġ" name ": Ġ" episode Ġname ", ĊĠĠĠĠĠĠĠ Ġ" description ": Ġ" Description Ġfor Ġepisode ", ĊĠĠĠĠĠĠĠ Ġ" uri ": Ġ" https :// at v - reference - app . firebase app . com / content / episode ", ĊĠĠĠĠĠĠĠ Ġ" video Uri ": Ġ" https :// at v - reference - app . firebase app . com / content / episode / video . mp 4 ", ĊĠĠĠĠĠĠĠ Ġ" thumbnail Uri ": Ġ" https :// at v - reference - app . firebase app . com / content / episode / thumbnail . jpg ", ĊĠĠĠĠĠĠĠ Ġ" background Uri ": Ġ" https :// at v - reference - app . firebase app . com / content / episode / background . jpg ", ĊĠĠĠĠĠĠĠ Ġ" category ": Ġ" episodes ", ĊĠĠĠĠĠĠĠ Ġ" video Type ": Ġ" episode ", ĊĠĠĠĠĠĠĠ Ġ" series Uri ": Ġ" https :// at v - reference - app . firebase app . com / content / episode / series ", ĊĠĠĠĠĠĠĠ Ġ" season Uri ": Ġ" https :// at v - reference - app . firebase app . com / content / episode / season ", ĊĠĠĠĠĠĠĠ Ġ" season Number ": Ġ" 1 ", ĊĠĠĠĠĠĠĠ Ġ" episode Number ": Ġ" 1 ", ĊĠĠĠĠĠĠĠ Ġ" duration ": Ġ" PT 0 0 H 0 0 M " ĊĠĠĠ Ġ}, ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġ" id ": Ġ" movie _ id ", ĊĠĠĠĠĠĠĠ Ġ" name ": Ġ" movie Ġname ", ĊĠĠĠĠĠĠĠ Ġ" description ": Ġ" Description Ġfor Ġmovie ", ĊĠĠĠĠĠĠĠ Ġ" uri ": Ġ" https :// at v - reference - app . firebase app . com / content / movie ", ĊĠĠĠĠĠĠĠ Ġ" video Uri ": Ġ" https :// at v - reference - app . firebase app . com / content / movie / video . mp 4 ", ĊĠĠĠĠĠĠĠ Ġ" thumbnail Uri ": Ġ" https :// at v - reference - app . firebase app . com / content / movie / thumbnail . jpg ", ĊĠĠĠĠĠĠĠ Ġ" background Uri ": Ġ" https :// at v - reference - app . firebase app . com / content / movie / background . jpg ", ĊĠĠĠĠĠĠĠ Ġ" category ": Ġ" movies ", ĊĠĠĠĠĠĠĠ Ġ" video Type ": Ġ" movie ", ĊĠĠĠĠĠĠĠ Ġ" series Uri ": Ġ" https :// at v - reference - app . firebase app . com / content / movie / series ", ĊĠĠĠĠĠĠĠ Ġ" season Uri ": Ġ"", ĊĠĠĠĠĠĠĠ Ġ" season Number ": Ġ"", ĊĠĠĠĠĠĠĠ Ġ" episode Number ": Ġ"", ĊĠĠĠĠĠĠĠ Ġ" duration ": Ġ" PT 0 0 H 0 0 M " ĊĠĠĠ Ġ} Ċ ] Ċ } """ ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠM AL FOR MED _ JSON Ġ= ĠVALID _ JSON . substring ( 1 0 ) ĊĠĠĠ Ġ} Ċ } Ċ