package Ġcom . just clean . task . network Ċ Ċ import Ġcom . just clean . task . Main Cor outines Rule Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . sky do ves . sand wich . ApiResponse Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . hamcrest . Core Matchers Ċ import Ġorg . hamcrest . Matcher Assert Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġjava . io . IOException Ċ Ċ /** Ċ Ġ* ĠCreated Ġby Ġ@ mo h ame de br ah im 9 6 Ġon Ġ 1 2 / 5 / 2 0 . Ċ Ġ*/ Ċ @ Experimental Cor outines Api Ċ class ĠPost Service Test Ġ: ĠApi Abstract < Post Service >() Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġservice : ĠPost Service ĊĠĠĠ Ġprivate Ġval Ġclient : ĠPost Client Ġ= Ġmock () ĊĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġcor outines Rule Ġ= ĠMain Cor outines Rule () ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġinit Service () Ġ{ ĊĠĠĠĠĠĠĠ Ġservice Ġ= Ġcreate Service ( Post Service :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Throws ( IOException :: class ) ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfetch Pokemon List From Network Test () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġ// enqueue Response ("/ Pokemon Response . json ") ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġservice . fetch Post List () ĊĠĠĠĠĠĠĠ Ġval Ġresponse Body Ġ= Ġrequire NotNull (( response Ġas ĠApiResponse . Success ). data ) ĊĠĠĠĠĠĠĠ Ġmock WebServer . take Request () ĊĊĠĠĠĠĠĠĠ Ġclient . fetch Post List () ĊĠĠĠĠĠĠĠ ĠMatcher Assert . assertThat ( response Body [ 0 ]. id , ĠCore Matchers .` is `( 1 0 )) ĊĠĠĠĠĠĠĠ ĠMatcher Assert . assertThat ( response Body [ 0 ]. title , ĠCore Matchers .` is ` (" Post Ġtitle Ġtest ")) ĊĠĠĠĠĠĠĠ ĠMatcher Assert . assertThat ( response Body [ 0 ]. body , ĠCore Matchers .` is ` (" Post Ġbody Ġtest ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Throws ( IOException :: class ) ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfetch Pokemon Info From Network Test () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġ// enqueue Response ("/ Bul bas aur . json ") ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġservice . fetch Post Comment ( 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Body Ġ= Ġrequire NotNull (( response Ġas ĠApiResponse . Success ). data ) ĊĠĠĠĠĠĠĠ Ġmock WebServer . take Request () ĊĠĠĠĠĠĠĠ Ġclient . fetch Post Comment ( id Ġ= Ġ 1 0 ) ĊĠĠĠĠĠĠĠ ĠMatcher Assert . assertThat ( response Body [ 0 ]. id , ĠCore Matchers .` is `( 1 0 )) ĊĠĠĠĠĠĠĠ ĠMatcher Assert . assertThat ( response Body [ 0 ]. name , ĠCore Matchers .` is ` (" name Ġcomment Ġtest ")) ĊĠĠĠĠĠĠĠ ĠMatcher Assert . assertThat ( response Body [ 0 ]. body , ĠCore Matchers .` is ` (" email Ġcomment Ġtest ")) ĊĠĠĠĠĠĠĠ ĠMatcher Assert . assertThat ( response Body [ 0 ]. email , ĠCore Matchers .` is ` (" body Ġcomment Ġtest ")) ĊĠĠĠ Ġ} Ċ }