package Ġcom . shop app . ui . order . details Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . view . View Ċ import Ġcom . n ha ar man . mockito _ kotlin .* Ċ import Ġcom . shop app . R Ċ import Ġcom . shop app . Test Shop Application Ċ import Ġcom . shop app . domain . formatter . Number Formatter Ċ import Ġcom . shop app . gateway . entity . Error Ċ import Ġcom . shop app . test . Mock Instanti ator Ċ import Ġkotlinx . android . synt hetic . main . activity _ l ce .* Ċ import Ġkotlinx . android . synt hetic . main . activity _ order _ details .* Ċ 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 _ error . view .* Ċ import Ġkotlinx . android . synt hetic . main . view _ price . view .* Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Assert . assertNull Ċ 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 Ċ import Ġorg . ro bo lectric . annotation . Config Ċ Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ @ Config ( manifest Ġ= ĠConfig . NONE , Ġapplication Ġ= ĠTest Shop Application :: class ) Ċ class ĠOrder Details Activity Test Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠORDER _ ID Ġ= Ġ" order _ id " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġactivity : ĠOrder Details Activity ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcontext : ĠContext ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġformatter Mock : ĠNumber Formatter ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġcontext Ġ= ĠRuntime Environment . application . base Context ĊĠĠĠĠĠĠĠ Ġval Ġintent Ġ= ĠOrder Details Activity . getStart Intent ( context , ĠORDER _ ID ) ĊĠĠĠĠĠĠĠ Ġactivity Ġ= ĠRo bo lectric . build Activity ( Order Details Activity :: class . java , Ġintent ). create (). start (). get () ĊĠĠĠĠĠĠĠ Ġformatter Mock Ġ= Ġmock Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon Ġ{ Ġformat Price ( any (), Ġany ()) Ġ} Ġdo Answer Ġ{ Ġ"${ it . arguments [ 0 ]} Ġ${ it . arguments [ 1 ]} Ġ" Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġactivity . price View . formatter Ġ= Ġformatter Mock ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Set Correct Title () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( context . getString ( R . string . order _ details ), Ġactivity . toolbar . toolbar Title . text ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Load Order When On Create () Ġ{ ĊĠĠĠĠĠĠĠ Ġverify ( activity . presenter ). load Order Details ( ORDER _ ID ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( View . VISIBLE , Ġactivity . l ce Layout . loading View . visibility ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Show ContentView () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsize Ġ= Ġ 5 ĊĠĠĠĠĠĠĠ Ġval Ġorder Ġ= ĠMock Instanti ator . new Order () ĊĠĠĠĠĠĠĠ Ġval Ġlist Ġ= ĠMock Instanti ator . new List ( Mock Instanti ator . new Order Product (), Ġsize ) ĊĠĠĠĠĠĠĠ Ġgiven ( order . order Products ). willReturn ( list ) ĊĠĠĠĠĠĠĠ Ġactivity . show Content ( order ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( size , Ġactivity . re cyclerView . adapter . item Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Show Product () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġorder Ġ= ĠMock Instanti ator . new Order () ĊĠĠĠĠĠĠĠ Ġval Ġorder Product Item Ġ= ĠMock Instanti ator . new Order Product () ĊĠĠĠĠĠĠĠ Ġval Ġproduct Variant Ġ= ĠMock Instanti ator . new Product Variant () ĊĠĠĠĠĠĠĠ Ġgiven ( order Product Item . product Variant ). willReturn ( product Variant ) ĊĠĠĠĠĠĠĠ Ġgiven ( order . order Products ). willReturn ( listOf ( order Product Item )) ĊĠĠĠĠĠĠĠ Ġactivity . show Content ( order ) ĊĠĠĠĠĠĠĠ Ġactivity . on Item Clicked ( 0 ) ĊĠĠĠĠĠĠĠ Ġverify ( activity . router ). show Product ( activity , Ġproduct Variant ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Not Show Product When Order IsNull () Ġ{ ĊĠĠĠĠĠĠĠ Ġactivity . on Item Clicked ( 0 ) ĊĠĠĠĠĠĠĠ ĠassertNull ( Shadow s . shadow Of ( activity . application ). next Started Activity ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould SetDefault Prices () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġorder Ġ= ĠMock Instanti ator . new Order () ĊĠĠĠĠĠĠĠ Ġgiven ( order . subtotal Price ). willReturn ( null ) ĊĠĠĠĠĠĠĠ Ġgiven ( order . total Shipping Price ). willReturn ( null ) ĊĠĠĠĠĠĠĠ Ġactivity . show Content ( order ) ĊĠĠĠĠĠĠĠ ĠassertEquals (" 0 ĠUSD Ġ", Ġactivity . price View . shipping Value . text . toString ()) ĊĠĠĠĠĠĠĠ ĠassertEquals (" 0 ĠUSD Ġ", Ġactivity . price View . subtotal Value . text . toString ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Show Address Section When Address IsNotNull () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġorder Ġ= ĠMock Instanti ator . new Order () ĊĠĠĠĠĠĠĠ Ġactivity . show Content ( order ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( View . VISIBLE , Ġactivity . shipping Address Title . visibility ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( View . VISIBLE , Ġactivity . address ContentView . visibility ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Hide Address Section When Address IsNull () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġorder Ġ= ĠMock Instanti ator . new Order () ĊĠĠĠĠĠĠĠ Ġgiven ( order . address ). willReturn ( null ) ĊĠĠĠĠĠĠĠ Ġactivity . show Content ( order ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( View . GONE , Ġactivity . shipping Address Title . visibility ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( View . GONE , Ġactivity . address ContentView . visibility ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Show NotFoundError With Target When Critical Error Received () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtarget Ġ= Ġcontext . getString ( R . string . order ) ĊĠĠĠĠĠĠĠ Ġactivity . show Error ( Error . Critical ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( View . VISIBLE , Ġactivity . l ce Layout . error View . visibility ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( context . getString ( R . string . Ñģ ould _ not _ find _ with _ placeholder , Ġtarget ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactivity . l ce Layout . error View . errorMessage . text ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ Ġactivity . finish () ĊĠĠĠ Ġ} Ċ }