package Ġcom . em rek ose . vide og ames . data . remote Ċ Ċ import Ġcom . em rek ose . vide og ames . data . remote . model . detail . Game Detail Response Ċ import Ġcom . em rek ose . vide og ames . data . remote . model . games . Games Response Ċ import Ġcom . em rek ose . vide og ames . utils . enqueue Response Ċ import Ġcom . google . common . truth . Truth Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġokhttp 3 . mock webserver . Mock WebServer Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġretrofit 2 . Ret rofit Ċ import Ġretrofit 2 . converter . mos hi . M oshi Converter Factory Ċ Ċ class ĠApi Service Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock WebServer : ĠMock WebServer ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġapi Service : ĠApi Service ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock WebServer Ġ= ĠMock WebServer () ĊĊĠĠĠĠĠĠĠ Ġapi Service Ġ= ĠRet rofit . Builder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. baseUrl ( mock WebServer . url ("/ ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Converter Factory ( M oshi Converter Factory . create ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. create ( ApiService :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock WebServer . shutdown () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` fetch Ġlist Ġof Ġgames Ġtest `() Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠGiven ĊĠĠĠĠĠĠĠ Ġmock WebServer . enqueue Response (" list - of - games . json ") ĊĊĠĠĠĠĠĠĠ Ġ// ĠWhen ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġapi Service . getAll Games () ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġmock WebServer . take Request () ĊĊĠĠĠĠĠĠĠ Ġ// ĠThen ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response ). isInstanceOf ( Games Response :: class . java ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . games Results . size ). isEqualTo ( 2 0 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . games Results [ 0 ]. name ). isEqualTo (" Grand ĠThe ft ĠAuto ĠV ") ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( request . path ). isEqualTo ("/ games ") ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( request . method ). isEqualTo (" GET ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` fetch Ġgame Ġdetail Ġtest `() Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠGiven ĊĠĠĠĠĠĠĠ Ġmock WebServer . enqueue Response (" game - details . json ") ĊĊĠĠĠĠĠĠĠ Ġ// ĠWhen ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġapi Service . get Game Details ( 3 4 9 8 ) ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġmock WebServer . take Request () ĊĊĠĠĠĠĠĠĠ Ġ// ĠThen ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response ). isInstanceOf ( Game Detail Response :: class . java ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . name ). isEqualTo (" Grand ĠThe ft ĠAuto ĠV ") ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . met acrit ic ). isEqualTo ( 9 7 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( request . path ). isEqualTo ("/ games / 3 4 9 8 ") ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( request . method ). isEqualTo (" GET ") ĊĠĠĠ Ġ} Ċ }