package Ġnet . nt world . foundation . test Ċ Ċ import Ġnet . nt world . foundation . Local Bus Resolver Ċ import Ġnet . nt world . foundation . cq rs . Command Ċ import Ġnet . nt world . foundation . cq rs . Command Bus Ċ import Ġnet . nt world . foundation . cq rs . CommandHandler Ċ import Ġnet . nt world . foundation . mock ing . Called With Builder Ċ import Ġnet . nt world . foundation . mock ing . Invoke Data Ċ import Ġnet . nt world . foundation . mock ing . Test Dsl Ċ import Ġnet . nt world . foundation . mock ing . internal . Call Fake Builder Impl Ċ import Ġnet . nt world . foundation . mock ing . internal . Called With Builder Impl Ċ import Ġnet . nt world . foundation . test . internal . Bus Called With Builder Impl Ċ import Ġnet . nt world . foundation . test . internal . Command Bus Call Fake Builder Impl Ċ import Ġkotlin . reflect . K Class Ċ Ċ abstract Ġclass ĠAbstract Mock able Command Bus < T >( ĊĠĠĠ Ġprivate Ġval Ġbus : ĠT Ċ ) Ġ: ĠMock able Bus (), ĠCommand Bus , ĠLocal Bus Resolver < Command , ĠCommand Handler <* >> ĊĠĠĠ Ġwhere ĠT Ġ: ĠCommand Bus , ĠT Ġ: ĠLocal Bus Resolver < Command , ĠCommand Handler <* >> Ġ{ ĊĊĠĠĠ Ġabstract Ġfun Ġguess Command K Class By Instance ( instance : ĠCommand ): ĠK Class < out ĠCommand >? ĊĊĠĠĠ Ġval Ġoriginal Bus : ĠCommand Bus Ġ= Ġbus ĊĠĠĠ Ġval Ġoriginal Process : Ġ( Command , ĠInvoke Data ) Ġ-> ĠUnit Ġ= Ġ{ Ġcommand , Ġ_ Ġ-> ĊĠĠĠĠĠĠĠ Ġbus . process ( command ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠ Ġoverride Ġfun Ġprocess ( command : ĠCommand ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġk Class Ġ= Ġguess Command K Class By Instance ( command ) Ġ?: Ġcommand :: class ĊĠĠĠĠĠĠĠ Ġval Ġmock Ġ= Ġhandler Mocks [ k Class ] Ġas ĠHandler Manual Mock < Command , ĠUnit >? ĊĠĠĠĠĠĠĠ Ġif Ġ( null Ġ=== Ġmock ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġbus . process ( command ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġreal Handler Ġ= Ġresolve ( command ) Ġas ĠCommand Handler < Command >? ĊĠĠĠĠĠĠĠ Ġif Ġ( null Ġ!== Ġreal Handler ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock . set Handle Fallback IfNot Mock ed Ġ{ Ġreal Handler . handle ( command ) Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġmock . handle ( command ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġresolve ( instance : ĠCommand ) Ġ= Ġbus . resolve ( instance ) ĊĊĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠ Ġ@ Test Dsl . Mock ĊĠĠĠ Ġin fix Ġfun Ġ< T Ġ: ĠCommand > Ġwhen Processing ( command : ĠK Class < out ĠT >): ĠCommand Bus Call Fake Builder . Start < T > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstart Ġ= Ġ( init Mock Instance For Handler IfNeeded < Command , ĠUnit >( command ) Ġas ĠHandler Manual Mock < Command , ĠUnit >) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. when Handle Called () ĊĊĠĠĠĠĠĠĠ Ġreturn ĠCommand Bus Call Fake Builder Impl ( start Ġas ĠCall Fake Builder Impl < Unit >) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Dsl . Verify ĊĠĠĠ Ġin fix Ġfun Ġ< T Ġ: ĠCommand > Ġshould Process ( command : ĠK Class < out ĠT >): ĠBus Called With Builder . Start < T > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstart Ġ= Ġinit Mock Instance For Handler IfNeeded < Command , ĠUnit >( command ). expect Handle Called () ĊĊĠĠĠĠĠĠĠ Ġreturn ĠBus Called With Builder Impl ( start Ġas ĠCalled With Builder Impl ) ĊĠĠĠ Ġ} Ċ }