package Ġat . fl or ians ch uster . control . android counter Ċ Ċ import Ġandroidx . fragment . app . testing . launch Fragment In Container Ċ import Ġandroidx . test . espress o . Esp ress o . on View Ċ import Ġandroidx . test . espress o . action . View Actions . click Ċ import Ġandroidx . test . espress o . assertion . View Assertions . matches Ċ import Ġandroidx . test . espress o . matcher . View Matchers . is Displayed Ċ import Ġandroidx . test . espress o . matcher . View Matchers . with Id Ċ import Ġandroidx . test . espress o . matcher . View Matchers . with Text Ċ import Ġat . fl or ians ch uster . control . Controller Stub Ċ import Ġat . fl or ians ch uster . control . kotlin counter . Counter Action Ċ import Ġat . fl or ians ch uster . control . kotlin counter . Counter State Ċ import Ġat . fl or ians ch uster . control . kotlin counter . create Counter Controller Ċ import Ġat . fl or ians ch uster . control . to Stub Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġkotlin . test . assertEquals Ċ Ċ internal Ġclass ĠCounter View Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġstub : ĠController Stub < Counter Action , ĠCounter State > ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ ĠCounter View . Controller Factory Ġ= Ġ{ Ġscope Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġscope . create Counter Controller (). to Stub (). also Ġ{ Ġstub Ġ= Ġit Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġlaunch Fragment In Container < Counter View >() ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġwhen Press ing Increase Button Increment Action Is Triggered () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . increase Button )). perform ( click ()) ĊĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ ĠassertEquals ( Counter Action . Increment , Ġstub . dis patched Actions . last ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġwhen Press ing De crease Button De crement Action Is Triggered () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . decrease Button )). perform ( click ()) ĊĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ ĠassertEquals ( Counter Action . De crement , Ġstub . dis patched Actions . last ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġwhen State Offers Value It Is Displayed In TextView () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġgiven ĊĠĠĠĠĠĠĠ Ġval Ġtest Value Ġ= Ġ 1 ĊĊĠĠĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠĠĠ Ġstub . emit State ( Counter State ( value Ġ= Ġtest Value )) ĊĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . value TextView )). check ( matches ( with Text ("$ test Value "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġwhen State Offers Loading ProgressBar Is Visible () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠĠĠ Ġstub . emit State ( Counter State ( loading Ġ= Ġtrue )) ĊĊĠĠĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . loading ProgressBar )). check ( matches ( is Displayed ())) ĊĠĠĠ Ġ} Ċ }