package Ġcom . nin chat . sdk . espress o . nin chat media . view Ċ Ċ import Ġandroidx . lifecycle . Lifecycle Ċ import Ġandroidx . test . core . app . Activity Scenario Ċ import Ġandroidx . test . espress o . Esp ress o Ċ 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 .* Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġandroidx . test . filters . Large Test Ċ import Ġandroidx . test . platform . app . Instrumentation Registry Ċ import Ġcom . nin chat . sdk . Nin chat Session Ċ import Ġcom . nin chat . sdk . Nin chat Session Manager Ċ import Ġcom . nin chat . sdk . R Ċ import Ġcom . nin chat . sdk . nin chat media . model . Nin chat File Ċ import Ġcom . nin chat . sdk . nin chat media . presenter . Nin chat Media Presenter Ċ import Ġcom . nin chat . sdk . nin chat media . view . Nin chat Media Activity Ċ import Ġorg . hamcrest . core . IsNot . not Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġjava . util .* Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ @ Large Test Ċ class ĠN in chat Media Presenter Test Ġ{ ĊĠĠĠ Ġval Ġapp Context Ġ= ĠInstrument ation Registry . get Instrumentation (). target Context ĊĠĠĠ Ġval Ġconfiguration Key Ġ= Ġapp Context . getString ( com . nin chat . sdk . R . string . nin chat _ configuration _ key ) ĊĠĠĠ Ġlateinit Ġvar Ġactivity Scenario : ĠActivity Scenario < Nin chat Media Activity > ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġdispose () Ġ{ ĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactivity Scenario . close () ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( err : ĠException ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġprintln ( err ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould _ create _ nin chat _ media _ activity _ with _ photo _ file _ id () Ġ{ ĊĠĠĠĠĠĠĠ ĠN in chat Session . Builder ( app Context , Ġconfiguration Key ). create () ĊĠĠĠĠĠĠĠ Ġval Ġintent Ġ= ĠN in chat Media Presenter . get Launch Intent ( app Context , Ġ" 1 2 3 4 5 "). run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġput Extra (" isDebug ", Ġtrue ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĊĠĠĠĠĠĠĠ Ġ// add Ġa Ġdummy Ġfile ĊĠĠĠĠĠĠĠ Ġval Ġdummy File Ġ= ĠN in chat File ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - message _ id ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - id ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - file - name ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 1 0 2 4 , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" photo /", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSystem . currentTimeMillis (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - sender ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtrue ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġdummy File . url Ġ= Ġ" https :// nin chat . com / asset / welcome / nin chat - logo - 3 9 x 4 4 . png " ĊĠĠĠĠĠĠĠ Ġdummy File . url Expiry Ġ= ĠDate ( Date (). time Ġ+ Ġ( 1 0 0 0 Ġ* Ġ 6 0 Ġ* Ġ 6 0 Ġ* Ġ 2 4 )) ĊĠĠĠĠĠĠĠ ĠN in chat Session Manager . getInstance (). nin chat State . add File (" 1 2 3 4 5 ", Ġdummy File ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġstart Ġactivity ĊĠĠĠĠĠĠĠ Ġactivity Scenario Ġ= ĠActivity Scenario . launch ( intent ) ĊĠĠĠĠĠĠĠ Ġactivity Scenario . on Activity Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġn in chat Media Presenter Ġ= Ġit . get Media Presenter () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 1 2 3 4 5 ", Ġn in chat Media Presenter . nin chat Media Model . file Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( false , Ġn in chat Media Presenter . nin chat Media Model . is Downloaded ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( dummy File , Ġn in chat Media Presenter . nin chat Media Model . getFile ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ name )). check ( matches ( with Text ( dummy File . name ))) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ download )). check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ video )). check ( matches ( not ( is Displayed ()))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould _ close _ activity _ by _ press ing _ back _ button () Ġ{ ĊĠĠĠĠĠĠĠ ĠN in chat Session . Builder ( app Context , Ġconfiguration Key ). create () ĊĠĠĠĠĠĠĠ Ġval Ġintent Ġ= ĠN in chat Media Presenter . get Launch Intent ( app Context , Ġ" 1 2 3 4 5 "). run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġput Extra (" isDebug ", Ġtrue ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ// add Ġa Ġdummy Ġfile ĊĠĠĠĠĠĠĠ Ġval Ġdummy File Ġ= ĠN in chat File ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - message _ id ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - id ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - file - name ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 1 0 2 4 , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" photo /", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSystem . currentTimeMillis (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - sender ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtrue ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġdummy File . url Ġ= Ġ" https :// nin chat . com / asset / welcome / nin chat - logo - 3 9 x 4 4 . png " ĊĠĠĠĠĠĠĠ Ġdummy File . url Expiry Ġ= ĠDate ( Date (). time Ġ+ Ġ( 1 0 0 0 Ġ* Ġ 6 0 Ġ* Ġ 6 0 Ġ* Ġ 2 4 )) ĊĠĠĠĠĠĠĠ ĠN in chat Session Manager . getInstance (). nin chat State . add File (" 1 2 3 4 5 ", Ġdummy File ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġstart Ġactivity ĊĠĠĠĠĠĠĠ Ġactivity Scenario Ġ= ĠActivity Scenario . launch ( intent ) ĊĠĠĠĠĠĠĠ Ġactivity Scenario . on Activity Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġn in chat Media Presenter Ġ= Ġit . get Media Presenter () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 1 2 3 4 5 ", Ġn in chat Media Presenter . nin chat Media Model . file Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( false , Ġn in chat Media Presenter . nin chat Media Model . is Downloaded ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( dummy File , Ġn in chat Media Presenter . nin chat Media Model . getFile ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ name )). check ( matches ( with Text ( dummy File . name ))) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ download )). check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ video )). check ( matches ( not ( is Displayed ()))) ĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠThread . sleep ( 2 0 0 0 ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠE sp ress o . press Back () ĊĠĠĠĠĠĠĠ Ġ} catch Ġ( err : ĠException ){} ĊĠĠĠĠĠĠĠ Ġfinally Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Lifecycle . State . DESTROY ED , Ġactivity Scenario . state ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould _ close _ activity _ by _ press ing _ cross _ button () Ġ{ ĊĠĠĠĠĠĠĠ ĠN in chat Session . Builder ( app Context , Ġconfiguration Key ). create () ĊĠĠĠĠĠĠĠ Ġval Ġintent Ġ= ĠN in chat Media Presenter . get Launch Intent ( app Context , Ġ" 1 2 3 4 5 "). run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġput Extra (" isDebug ", Ġtrue ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ// add Ġa Ġdummy Ġfile ĊĠĠĠĠĠĠĠ Ġval Ġdummy File Ġ= ĠN in chat File ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - message _ id ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - id ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - file - name ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 1 0 2 4 , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" photo /", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSystem . currentTimeMillis (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - sender ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtrue ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġdummy File . url Ġ= Ġ" https :// nin chat . com / asset / welcome / nin chat - logo - 3 9 x 4 4 . png " ĊĠĠĠĠĠĠĠ Ġdummy File . url Expiry Ġ= ĠDate ( Date (). time Ġ+ Ġ( 1 0 0 0 Ġ* Ġ 6 0 Ġ* Ġ 6 0 Ġ* Ġ 2 4 )) ĊĠĠĠĠĠĠĠ ĠN in chat Session Manager . getInstance (). nin chat State . add File (" 1 2 3 4 5 ", Ġdummy File ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġstart Ġactivity ĊĠĠĠĠĠĠĠ Ġactivity Scenario Ġ= ĠActivity Scenario . launch ( intent ) ĊĠĠĠĠĠĠĠ Ġactivity Scenario . on Activity Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġn in chat Media Presenter Ġ= Ġit . get Media Presenter () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 1 2 3 4 5 ", Ġn in chat Media Presenter . nin chat Media Model . file Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( false , Ġn in chat Media Presenter . nin chat Media Model . is Downloaded ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( dummy File , Ġn in chat Media Presenter . nin chat Media Model . getFile ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ name )). check ( matches ( with Text ( dummy File . name ))) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ download )). check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ video )). check ( matches ( not ( is Displayed ()))) ĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠThread . sleep ( 2 0 0 0 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . close _ media _ button )). perform ( click ()) ĊĠĠĠĠĠĠĠ Ġ} catch Ġ( err : ĠException ){} ĊĠĠĠĠĠĠĠ Ġfinally Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Lifecycle . State . DESTROY ED , Ġactivity Scenario . state ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould _ create _ nin chat _ media _ activity _ with _ video _ file _ id () Ġ{ ĊĠĠĠĠĠĠĠ ĠN in chat Session . Builder ( app Context , Ġconfiguration Key ). create () ĊĠĠĠĠĠĠĠ Ġval Ġintent Ġ= ĠN in chat Media Presenter . get Launch Intent ( app Context , Ġ" 1 2 3 4 5 "). run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġput Extra (" isDebug ", Ġtrue ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ// add Ġa Ġdummy Ġfile ĊĠĠĠĠĠĠĠ Ġval Ġdummy File Ġ= ĠN in chat File ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - message _ id ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - id ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - file - name ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 1 0 2 4 , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" video /", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSystem . currentTimeMillis (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - sender ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtrue ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġdummy File . url Ġ= Ġ" http :// mir rors . standalone installer . com / video - sample / TRA 3 1 0 6 . 3 gp " ĊĠĠĠĠĠĠĠ Ġdummy File . url Expiry Ġ= ĠDate ( Date (). time Ġ+ Ġ( 1 0 0 0 Ġ* Ġ 6 0 Ġ* Ġ 6 0 Ġ* Ġ 2 4 )) ĊĠĠĠĠĠĠĠ ĠN in chat Session Manager . getInstance (). nin chat State . add File (" 1 2 3 4 5 ", Ġdummy File ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġstart Ġactivity ĊĠĠĠĠĠĠĠ Ġactivity Scenario Ġ= ĠActivity Scenario . launch ( intent ) ĊĠĠĠĠĠĠĠ Ġactivity Scenario . on Activity Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġn in chat Media Presenter Ġ= Ġit . get Media Presenter () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 1 2 3 4 5 ", Ġn in chat Media Presenter . nin chat Media Model . file Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( false , Ġn in chat Media Presenter . nin chat Media Model . is Downloaded ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( dummy File , Ġn in chat Media Presenter . nin chat Media Model . getFile ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ name )). check ( matches ( with Text ( dummy File . name ))) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ download )). check ( matches ( not ( is Displayed ()))) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ video )). check ( matches ( is Displayed ())) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould _ download _ a _ file _ using _ native _ download _ manager () Ġ{ ĊĠĠĠĠĠĠĠ ĠN in chat Session . Builder ( app Context , Ġconfiguration Key ). create () ĊĠĠĠĠĠĠĠ Ġval Ġintent Ġ= ĠN in chat Media Presenter . get Launch Intent ( app Context , Ġ" 1 2 3 4 5 "). run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġput Extra (" isDebug ", Ġtrue ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ// add Ġa Ġdummy Ġfile ĊĠĠĠĠĠĠĠ Ġval Ġdummy File Ġ= ĠN in chat File ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - message _ id ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - id ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - file - name ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 1 0 2 4 , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" photo /", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSystem . currentTimeMillis (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" test - sender ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtrue ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġdummy File . url Ġ= Ġ" https :// nin chat . com / asset / welcome / nin chat - logo - 3 9 x 4 4 . png " ĊĠĠĠĠĠĠĠ Ġdummy File . url Expiry Ġ= ĠDate ( Date (). time Ġ+ Ġ( 1 0 0 0 Ġ* Ġ 6 0 Ġ* Ġ 6 0 Ġ* Ġ 2 4 )) ĊĠĠĠĠĠĠĠ ĠN in chat Session Manager . getInstance (). nin chat State . add File (" 1 2 3 4 5 ", Ġdummy File ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġstart Ġactivity ĊĠĠĠĠĠĠĠ Ġactivity Scenario Ġ= ĠActivity Scenario . launch ( intent ) ĊĠĠĠĠĠĠĠ Ġactivity Scenario . on Activity Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġn in chat Media Presenter Ġ= Ġit . get Media Presenter () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 1 2 3 4 5 ", Ġn in chat Media Presenter . nin chat Media Model . file Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( false , Ġn in chat Media Presenter . nin chat Media Model . is Downloaded ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( dummy File , Ġn in chat Media Presenter . nin chat Media Model . getFile ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ name )). check ( matches ( with Text ( dummy File . name ))) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ download )). check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ video )). check ( matches ( not ( is Displayed ()))) ĊĠĠĠĠĠĠĠ Ġ// Ġtry Ġto Ġdownload ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ download )). perform ( click ()) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . nin chat _ media _ download )). check ( matches ( not ( is Displayed ()))) ĊĠĠĠ Ġ} Ċ Ċ }