package Ġcom . shop app . ui . cart Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . support . v 7 . widget . Linear LayoutManager Ċ import Ġandroid . support . v 7 . widget . Orientation Helper Ċ import Ġandroid . support . v 7 . widget . RecyclerView Ċ import Ġandroid . view . View Ċ import Ġcom . n ha ar man . mockito _ kotlin . given Ċ import Ġcom . n ha ar man . mockito _ kotlin . mock Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Ċ import Ġcom . shop app . R Ċ import Ġcom . shop app . Test Shop Application Ċ import Ġcom . shop app . test . Mock Instanti ator Ċ import Ġcom . shop app . ui . cart . adapter . Cart Adapter Ċ import Ġkotlinx . android . synt hetic . main . activity _ cart .* Ċ import Ġkotlinx . android . synt hetic . main . activity _ l ce .* Ċ import Ġkotlinx . android . synt hetic . main . layout _ l ce .* Ċ import Ġkotlinx . android . synt hetic . main . layout _ l ce . view .* Ċ import Ġkotlinx . android . synt hetic . main . view _ base _ toolbar . view .* Ċ import Ġkotlinx . android . synt hetic . main . view _ l ce _ empty . view .* Ċ import Ġorg . junit . After Ċ 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 Ċ 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 Ċ Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ @ Config ( manifest Ġ= ĠConfig . NONE , Ġapplication Ġ= ĠTest Shop Application :: class ) Ċ class ĠCart Activity Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġactivity : ĠCart Activity ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcontext : ĠContext ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġactivity Ġ= ĠRo bo lectric . setup Activity ( Cart Activity :: class . java ) ĊĠĠĠĠĠĠĠ Ġcontext Ġ= ĠRuntime Environment . application . base Context ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Set Title On Create () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( context . getString ( R . string . my _ cart ), Ġactivity . toolbar . toolbar Title . text ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Add Linear LayoutManager On Create () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertNotNull ( activity . re cyclerView . layout Manager ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( activity . re cyclerView . layout Manager Ġis ĠLinearLayoutManager ) ĊĠĠĠĠĠĠĠ Ġval Ġmanager Ġ= Ġactivity . re cyclerView . layout Manager Ġas ĠLinearLayoutManager ĊĠĠĠĠĠĠĠ ĠassertEquals ( Orientation Helper . VERTICAL , Ġmanager . orientation ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Add Adapter On Create () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertNotNull ( activity . re cyclerView . adapter ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( activity . re cyclerView . adapter Ġis ĠCart Adapter ) ĊĠĠĠĠĠĠĠ Ġval Ġadapter Ġ= Ġactivity . re cyclerView . adapter Ġas ĠCart Adapter ĊĠĠĠĠĠĠĠ ĠassertEquals ( 0 , Ġadapter . item Count ) ĊĠĠĠĠĠĠĠ Ġshadow Of ( activity . re cyclerView ). on Touch Listener ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Load Products On Create () Ġ{ ĊĠĠĠĠĠĠĠ Ġverify ( activity . presenter ). load Cart Items () ĊĠĠĠĠĠĠĠ ĠassertEquals ( View . VISIBLE , Ġactivity . l ce Layout . loading View . visibility ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Show Products List () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcount Ġ= Ġ 5 ĊĠĠĠĠĠĠĠ Ġval Ġproducts Ġ= ĠMock Instanti ator . new List ( Mock Instanti ator . new Cart Product (), Ġcount ) ĊĠĠĠĠĠĠĠ Ġactivity . show Content ( products ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( View . GONE , Ġactivity . empty View . visibility ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( count , Ġactivity . re cyclerView . adapter . item Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Start Checkout () Ġ{ ĊĠĠĠĠĠĠĠ Ġactivity . checkout Button . perform Click () ĊĠĠĠĠĠĠĠ Ġverify ( activity . router ). show Checkout ( activity ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Start Home () Ġ{ ĊĠĠĠĠĠĠĠ Ġactivity . on Empty Button Clicked () ĊĠĠĠĠĠĠĠ Ġverify ( activity . router ). show Home ( activity , Ġtrue ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Show Product Details () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġproducts Ġ= ĠMock Instanti ator . new List ( Mock Instanti ator . new Cart Product (), Ġ 3 ) ĊĠĠĠĠĠĠĠ Ġactivity . show Content ( products ) ĊĠĠĠĠĠĠĠ Ġactivity . on Item Clicked ( 0 ) ĊĠĠĠĠĠĠĠ Ġverify ( activity . router ). show Product ( activity , Ġproducts [ 0 ]. product Variant ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Remove Item () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġproduct Variant Id Ġ= Ġ" product Variant Id " ĊĠĠĠĠĠĠĠ Ġactivity . on Remove Button Clicked ( product Variant Id ) ĊĠĠĠĠĠĠĠ Ġverify ( activity . presenter ). remove Product ( product Variant Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Change Variant Quantity () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġproduct Variant Id Ġ= Ġ" product Variant Id " ĊĠĠĠĠĠĠĠ Ġval Ġquantity Ġ= Ġ 2 ĊĠĠĠĠĠĠĠ Ġactivity . on Quantity Changed ( product Variant Id , Ġquantity ) ĊĠĠĠĠĠĠĠ Ġverify ( activity . presenter ). change Product Quantity ( product Variant Id , Ġquantity ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Show Empty State () Ġ{ ĊĠĠĠĠĠĠĠ Ġactivity . show Empty State () ĊĠĠĠĠĠĠĠ Ġval Ġid Ġ= Ġshadow Of ( activity . empty View . empty Image . drawable ). created From Res Id ĊĠĠĠĠĠĠĠ ĠassertEquals ( R . drawable . ic _ cart _ empty , Ġid ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( context . getString ( R . string . empty _ cart _ message ), Ġactivity . empty View . empty Message . text ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( context . getString ( R . string . start _ shopping ), Ġactivity . empty View . empty Button . text ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( View . VISIBLE , Ġactivity . empty View . empty Button . visibility ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Remove Product When On Item Sw ip ed () Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠviewHolder : ĠRecyclerView . ViewHolder Ġ= Ġmock () ĊĠĠĠĠĠĠĠ Ġgiven ( view Holder . adapter Position ). willReturn ( 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġproducts Ġ= ĠMock Instanti ator . new List ( Mock Instanti ator . new Cart Product ()) ĊĠĠĠĠĠĠĠ Ġactivity . show Content ( products ) ĊĠĠĠĠĠĠĠ Ġactivity . on Item Sw ip ed ( view Holder , Ġ 0 ) ĊĊĠĠĠĠĠĠĠ Ġverify ( activity . presenter ). remove Product ( products . first (). product Variant . productId ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ Ġactivity . finish () ĊĠĠĠ Ġ} Ċ }