package Ġcom . shop app . ui . blog Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . support . v 7 . widget . Linear LayoutManager Ċ import Ġandroid . support . v 7 . widget . Orientation Helper Ċ import Ġandroid . view . View Ċ import Ġcom . n ha ar man . mockito _ kotlin . mock Ċ import Ġcom . n ha ar man . mockito _ kotlin . times Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Ċ import Ġcom . shop app . Test Shop Application Ċ import Ġcom . shop app . test . Mock Instanti ator Ċ import Ġcom . shop app . ui . base . ui . Fragment Visibility Listener Ċ import Ġcom . shop app . ui . blog . adapter . Blog Adapter Ċ import Ġcom . shop app . ui . const . Constant Ċ import Ġcom . shop app . ui . home . Home Activity Ċ import Ġkotlinx . android . synt hetic . main . fragment _ blog .* Ċ import Ġorg . junit . Assert .* Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . ro bo lectric . Ro bo lectric TestRunner Ċ import Ġorg . ro bo lectric . Runtime Environment Ċ import Ġorg . ro bo lectric . Shadow s . shadow Of Ċ import Ġorg . ro bo lectric . annotation . Config Ċ import Ġorg . ro bo lectric . shadow s . support . v 4 . Support Fragment TestUtil . start Fragment Ċ Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ @ Config ( manifest Ġ= ĠConfig . NONE , Ġapplication Ġ= ĠTest Shop Application :: class ) Ċ class ĠBlog Fragment Test Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠDE COR ATOR _ COUNT Ġ= Ġ 1 ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfragment : ĠBlog Fragment ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcontext : ĠContext ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġfragment Ġ= ĠBlog Fragment () ĊĠĠĠĠĠĠĠ Ġstart Fragment ( fragment , ĠHome Activity :: class . java ) ĊĠĠĠĠĠĠĠ Ġcontext Ġ= ĠRuntime Environment . application . base Context ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Add Decorator On Create () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( DE COR ATOR _ COUNT , Ġfragment . re cyclerView . item Decoration Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Add Linear LayoutManager On Create () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertNotNull ( fragment . re cyclerView . layout Manager ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( fragment . re cyclerView . layout Manager Ġis ĠLinearLayoutManager ) ĊĠĠĠĠĠĠĠ Ġval Ġmanager Ġ= Ġfragment . re cyclerView . layout Manager Ġas ĠLinearLayoutManager ĊĠĠĠĠĠĠĠ ĠassertEquals ( Orientation Helper . VERTICAL , Ġmanager . orientation ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Add Adapter On Create () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertNotNull ( fragment . re cyclerView . adapter ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( fragment . re cyclerView . adapter Ġis ĠBlog Adapter ) ĊĠĠĠĠĠĠĠ Ġval Ġadapter Ġ= Ġfragment . re cyclerView . adapter Ġas ĠBlog Adapter ĊĠĠĠĠĠĠĠ ĠassertEquals ( 0 , Ġadapter . item Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Hide See All On Create () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( View . GONE , Ġfragment . see All . visibility ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Get Articles On Create () Ġ{ ĊĠĠĠĠĠĠĠ Ġverify ( fragment . presenter ). load Articles ( Constant . DEFAULT _ PER _ PAGE _ COUNT , Ġnull ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Load Articles OnLoad Date () Ġ{ ĊĠĠĠĠĠĠĠ Ġfragment . load Data () ĊĠĠĠĠĠĠĠ Ġverify ( fragment . presenter , Ġtimes ( 2 )). load Articles ( Constant . DEFAULT _ PER _ PAGE _ COUNT ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Notify Visibility Listener () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlistener : ĠFragment Visibility Listener Ġ= Ġmock () ĊĠĠĠĠĠĠĠ Ġfragment . visibility Listener Ġ= Ġlistener ĊĊĠĠĠĠĠĠĠ Ġval Ġarticles Count Ġ= Ġ 5 ĊĠĠĠĠĠĠĠ Ġval Ġarticle List Ġ= ĠMock Instanti ator . new List ( Mock Instanti ator . new Article (), Ġarticles Count ) ĊĠĠĠĠĠĠĠ Ġfragment . show Content ( article List ) ĊĠĠĠĠĠĠĠ Ġverify ( listener ). change Visibility ( true ) ĊĊĠĠĠĠĠĠĠ Ġfragment . show Content ( emptyList ()) ĊĠĠĠĠĠĠĠ Ġverify ( listener ). change Visibility ( false ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Show ContentView () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġarticles Count Ġ= Ġ 5 ĊĠĠĠĠĠĠĠ Ġval Ġarticles Ġ= ĠMock Instanti ator . new List ( Mock Instanti ator . new Article (), Ġarticles Count ) ĊĠĠĠĠĠĠĠ Ġfragment . show Content ( articles ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( articles Count , Ġfragment . re cyclerView . adapter . item Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Not Show ContentView () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġarticles Count Ġ= Ġ 0 ĊĠĠĠĠĠĠĠ Ġfragment . show Content ( emptyList ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( articles Count , Ġfragment . re cyclerView . adapter . item Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Show See All View () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġarticles Count Ġ= ĠConstant . DEFAULT _ PER _ PAGE _ COUNT ĊĠĠĠĠĠĠĠ Ġval Ġarticles Ġ= ĠMock Instanti ator . new List ( Mock Instanti ator . new Article (), Ġarticles Count ) ĊĠĠĠĠĠĠĠ Ġfragment . show Content ( articles ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( View . VISIBLE , Ġfragment . see All . visibility ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Hide See All View () Ġ{ ĊĠĠĠĠĠĠĠ Ġfragment . show Content ( emptyList ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( View . GONE , Ġfragment . see All . visibility ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Start Blog Activity When See All Clicked () Ġ{ ĊĠĠĠĠĠĠĠ Ġfragment . see All . perform Click () ĊĠĠĠĠĠĠĠ Ġverify ( fragment . router ). show Full Blog List ( fragment . context ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Start Article Activity When Item Clicked () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġarticle Ġ= ĠMock Instanti ator . new Article () ĊĠĠĠĠĠĠĠ Ġfragment . show Content ( listOf ( article )) ĊĠĠĠĠĠĠĠ Ġfragment . on Item Clicked ( 0 ) ĊĠĠĠĠĠĠĠ Ġverify ( fragment . router ). show Article ( fragment . context , Ġarticle . id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Not Start Article Activity When Item Clicked With Wrong Position () Ġ{ ĊĠĠĠĠĠĠĠ Ġfragment . show Content ( listOf ()) ĊĠĠĠĠĠĠĠ Ġfragment . on Item Clicked ( 0 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġstarted Intent Ġ= Ġshadow Of ( fragment . activity ). next Started Activity ĊĠĠĠĠĠĠĠ ĠassertNull ( started Intent ) ĊĠĠĠ Ġ} Ċ }