package Ġcom . cle vert ap . android . x ps Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġcom . cle vert ap . android . sdk . Cle ver Tap API Ċ import Ġcom . cle vert ap . android . sdk . Constants Ċ import Ġcom . cle vert ap . android . shared . test . Base TestCase Ċ import Ġcom . cle vert ap . android . shared . test . Test Application Ċ import Ġcom . cle vert ap . android . x ps . X ps Constants . FAILED _ WITH _ EXCEPTION Ċ import Ġcom . cle vert ap . android . x ps . X ps Constants . OTHER _ COMMAND Ċ import Ġcom . cle vert ap . android . x ps . X ps Constants . TOKEN _ SUCCESS Ċ import Ġcom . cle vert ap . android . x ps . X ps Test Constants . Companion . MI _ TOKEN Ċ import Ġcom . xia omi . mip ush . sdk . ErrorCode . ERROR _ SERVICE _ UN AVAILABLE Ċ import Ġcom . xia omi . mip ush . sdk . ErrorCode . SUCCESS Ċ import Ġcom . xia omi . mip ush . sdk . Mi Push Client . COMMAND _ REGISTER Ċ import Ġcom . xia omi . mip ush . sdk . Mi Push Client . COMMAND _ UN SET _ ACCOUNT Ċ import Ġcom . xia omi . mip ush . sdk . Mi Push Command Message Ċ import Ġcom . xia omi . mip ush . sdk . Mi Push Message Ċ import Ġorg . junit .* Ċ import Ġorg . junit . runner .* Ċ import Ġorg . mockito . Mockito .* Ċ import Ġorg . ro bo lectric . Ro bo lectric TestRunner Ċ import Ġorg . ro bo lectric . annotation . Config Ċ Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ @ Config ( sdk Ġ= Ġ[ 2 8 ], Ġapplication Ġ= ĠTest Application :: class ) Ċ class ĠX ia omi MessageHandler Test Ġ: ĠBase TestCase () Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġhandler : ĠX ia omi MessageHandler Impl ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġparser : ĠIX ia omi Notification Parser ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġoverride Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . setUp () ĊĠĠĠĠĠĠĠ Ġparser Ġ= Ġmock ( X ia omi Notification Parser :: class . java ) ĊĠĠĠĠĠĠĠ Ġhandler Ġ= ĠX ia omi MessageHandler Impl ( parser ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Create Notification _ Null _ Message () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġis Success Ġ= Ġhandler . create Notification ( application , Ġnull ) ĊĠĠĠĠĠĠĠ ĠAssert . assertFalse ( is Success ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Create Notification _ Invalid _ Message _ Throws _ Exception () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbundle Ġ= ĠBundle () ĊĠĠĠĠĠĠĠ Ġ` when `( parser . to Bundle ( any ( Mi Push Message :: class . java ))). thenReturn ( bundle ) ĊĠĠĠĠĠĠĠ Ġmock Static ( Cle ver Tap API :: class . java ). use Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` when `( Cle ver Tap API . create Notification ( application , Ġbundle )). then Throw ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠRuntimeException (" Something Ġwent Ġwrong ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġis Success Ġ= Ġhandler . create Notification ( application , ĠMi Push Message ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertFalse ( is Success ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Create Notification _ Valid _ Message () Ġ{ ĊĠĠĠĠĠĠĠ Ġ` when `( parser . to Bundle ( any ( Mi Push Message :: class . java ))). thenReturn ( Bundle ()) ĊĠĠĠĠĠĠĠ Ġval Ġis Success Ġ= Ġhandler . create Notification ( application , ĠMi Push Message ()) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( is Success ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Create Notification _ Valid _ Message _ With _ Account _ ID () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbundle Ġ= ĠBundle () ĊĠĠĠĠĠĠĠ Ġbundle . putString ( Constants . WZ RK _ AC CT _ ID _ KEY , Ġ" Some ĠValue ") ĊĠĠĠĠĠĠĠ Ġ` when `( parser . to Bundle ( any ( Mi Push Message :: class . java ))). thenReturn ( bundle ) ĊĠĠĠĠĠĠĠ Ġval Ġis Success Ġ= Ġhandler . create Notification ( application , ĠMi Push Message ()) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( is Success ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest On Receive Pass Through Message _ Other _ Command () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġmock ( Mi Push Command Message :: class . java ) ĊĠĠĠĠĠĠĠ Ġ` when `( message . command ). thenReturn ( COMMAND _ UN SET _ ACCOUNT ) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġhandler . on Receive Register Result ( application , Ġmessage ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( result , ĠOTHER _ COMMAND ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest On Receive Pass Through Message _ Token _ Success () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġmock ( Mi Push Command Message :: class . java ) ĊĠĠĠĠĠĠĠ Ġ` when `( message . command ). thenReturn ( COMMAND _ REGISTER ) ĊĠĠĠĠĠĠĠ Ġ` when `( message . result Code ). thenReturn ( SUCCESS . to Long ()) ĊĠĠĠĠĠĠĠ Ġ` when `( message . command Arguments ). thenReturn ( listOf ( MI _ TOKEN )) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġhandler . on Receive Register Result ( application , Ġmessage ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( result , ĠTOKEN _ SUCCESS ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest On Receive Pass Through Message _ Invalid _ Token () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġmock ( Mi Push Command Message :: class . java ) ĊĠĠĠĠĠĠĠ Ġ` when `( message . command ). thenReturn ( COMMAND _ REGISTER ) ĊĠĠĠĠĠĠĠ Ġ` when `( message . result Code ). thenReturn ( SUCCESS . to Long ()) ĊĠĠĠĠĠĠĠ Ġ` when `( message . command Arguments ). thenReturn ( emptyList ()) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġhandler . on Receive Register Result ( application , Ġmessage ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( result , ĠX ps Constants . INVALID _ TOKEN ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest On Receive Pass Through Message _ Token _ Failure () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġmock ( Mi Push Command Message :: class . java ) ĊĠĠĠĠĠĠĠ Ġ` when `( message . command ). thenReturn ( COMMAND _ REGISTER ) ĊĠĠĠĠĠĠĠ Ġ` when `( message . result Code ). thenReturn ( ERROR _ SERVICE _ UN AVAILABLE . to Long ()) ĊĠĠĠĠĠĠĠ Ġ` when `( message . command Arguments ). thenReturn ( emptyList ()) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġhandler . on Receive Register Result ( application , Ġmessage ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( result , ĠX ps Constants . TOKEN _ FAILURE ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest On Receive Pass Through Message _ Failed _ Exception () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġmock ( Mi Push Command Message :: class . java ) ĊĠĠĠĠĠĠĠ Ġ` when `( message . command ). thenReturn ( COMMAND _ REGISTER ) ĊĠĠĠĠĠĠĠ Ġ` when `( message . result Code ). thenReturn ( SUCCESS . to Long ()) ĊĠĠĠĠĠĠĠ Ġ` when `( message . command Arguments ). then Throw ( RuntimeException (" Something Ġwent Ġwrong ")) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġhandler . on Receive Register Result ( application , Ġmessage ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( result , ĠFAILED _ WITH _ EXCEPTION ) ĊĠĠĠ Ġ} Ċ }