package Ġcom . mr k ost ua . math alarm . alarm Settings . option Set Ring tone Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . media . Audio Manager Ċ import Ġandroid . media . MediaPlayer Ċ import Ġandroid . support . test . espress o . Esp ress o . on Data Ċ import Ġandroid . support . test . espress o . Esp ress o . on View Ċ import Ġandroid . support . test . espress o . action . View Actions . click Ċ import Ġandroid . support . test . espress o . assertion . View Assertions Ċ import Ġandroid . support . test . espress o . matcher . View Matchers .* Ċ import Ġandroid . support . test . filters . Medium Test Ċ import Ġandroid . support . test . rule . Activity Test Rule Ċ import Ġandroid . support . test . runner . Android JUnit 4 Ċ import Ġcom . mr k ost ua . math alarm . R Ċ import Ġcom . mr k ost ua . math alarm . al arms . math Alarm . main Alarm . Main Alarm Activity Ċ import Ġcom . mr k ost ua . math alarm . tools . Constant Values Ċ import Ġjunit . framework . Assert .* Ċ import Ġorg . hamcrest . Matchers . all Of Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ Ċ /** Ċ Ġ* Ġ@ author ĠK ost ian ty n ĠP ry sia zh ny i Ġon Ġ 4 / 2 7 / 2 0 1 8 . Ċ Ġ*/ Ċ @ Medium Test Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠMedia Player Helper Test Ġ{ ĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġalarm Main Alarm Activity Test Rule Ġ= ĠActivity Test Rule < Main Alarm Activity >( Main Alarm Activity :: class . java ) ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcontext : ĠContext ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmedia Player : ĠMedia Player ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġcontext Ġ= Ġalarm Main Alarm Activity Test Rule . activity . application Context ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . ib Additional Settings )). perform ( click ()) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . ib Move Forward )). perform ( click ()) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġplay Ring tone () Ġ{ ĊĠĠĠĠĠĠĠ Ġplay Some Ring tone (" loud ") ĊĠĠĠĠĠĠĠ Ġmedia Player Ġ= ĠMedia Player Helper . get MediaPlayer () ĊĠĠĠĠĠĠĠ ĠassertTrue (" media Player Ġis Ġnot Ġplaying ", Ġmedia Player . is Playing ) ĊĠĠĠĠĠĠĠ ĠassertTrue (" media Player Ġis Ġnot Ġlooping ", Ġmedia Player . is Loop ing ) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġplay Ring tone From Uri () Ġ{ ĊĠĠĠĠĠĠĠ Ġplay Some Ring tone (" 5 .") ĊĠĠĠĠĠĠĠ Ġmedia Player Ġ= ĠMedia Player Helper . get MediaPlayer () ĊĠĠĠĠĠĠĠ ĠassertTrue (" media Player Ġis Ġnot Ġplaying ", Ġmedia Player . is Playing ) ĊĠĠĠĠĠĠĠ ĠassertTrue (" media Player Ġis Ġnot Ġlooping ", Ġmedia Player . is Loop ing ) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġstop Ring tone () Ġ{ ĊĠĠĠĠĠĠĠ Ġplay Some Ring tone () ĊĠĠĠĠĠĠĠ Ġmedia Player Ġ= ĠMedia Player Helper . get MediaPlayer () ĊĠĠĠĠĠĠĠ ĠassertTrue (" media Player Ġis Ġnot Ġplaying ", Ġmedia Player . is Playing ) ĊĊĠĠĠĠĠĠĠ Ġon Data ( with Text (" loud ")) ĊĠĠĠĠĠĠĠ Ġon View ( all Of ( with Id ( R . id . ib Play Pause Ring tone ), Ġhas Sibling ( with Text (" loud ")) )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĠĠĠĠĠĠĠ ĠassertFalse (" media Player Ġis Ġplaying ", Ġmedia Player . is Playing ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġplay Multiple Times () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfirst Ring tone Ġ= Ġ" energy " ĊĠĠĠĠĠĠĠ Ġval Ġsecond Ring tone Ġ= Ġ" loud " ĊĠĠĠĠĠĠĠ Ġval Ġthird Ring tone Ġ= Ġ" ring tone _ me chan ic _ clock " ĊĠĠĠĠĠĠĠ Ġplay Some Ring tone ( first Ring tone ) ĊĠĠĠĠĠĠĠ Ġmedia Player Ġ= ĠMedia Player Helper . get MediaPlayer () ĊĠĠĠĠĠĠĠ ĠassertEquals (" playing Ring tone Name Ġis Ġdifferent Ġform Ġdisplaying Ġone ", ĠMedia Player Helper . get Playing Ring tone Name (), Ġfirst Ring tone ) ĊĊĠĠĠĠĠĠĠ Ġplay Some Ring tone ( second Ring tone ) ĊĠĠĠĠĠĠĠ Ġmedia Player Ġ= ĠMedia Player Helper . get MediaPlayer () ĊĠĠĠĠĠĠĠ ĠassertEquals (" playing Ring tone Name Ġis Ġdifferent Ġform Ġexpected ", ĠMedia Player Helper . get Playing Ring tone Name (), Ġsecond Ring tone ) ĊĊĠĠĠĠĠĠĠ Ġplay Some Ring tone ( third Ring tone ) ĊĠĠĠĠĠĠĠ Ġmedia Player Ġ= ĠMedia Player Helper . get MediaPlayer () ĊĠĠĠĠĠĠĠ ĠassertEquals (" playing Ring tone Name Ġis Ġdifferent Ġform Ġexpected ", ĠMedia Player Helper . get Playing Ring tone Name (), Ġthird Ring tone ) ĊĠĠĠĠĠĠĠ Ġassert Not Same (" playing Ring tone Name Ġis Ġdifferent Ġform Ġprevious ", ĠMedia Player Helper . get Playing Ring tone Name (), Ġsecond Ring tone ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* Ġalso Ġchecks Ġplaying Ġring tone Ġwith ĠAudio Stream Ġas ĠST REAM _ ALARM ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġplay Deep Wake Up Ring tone Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . ib Move Forward )). perform ( click ()) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . ib Move Forward )). perform ( click ()) ĊĠĠĠĠĠĠĠ Ġon View ( all Of ( with Id ( R . id . ib Sleep Icon ), Ġhas Sibling ( with Text ( context . getString ( R . string . deep Sleep Option Title ))))) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( View Assertions . matches ( is Displayed ())) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . ib Play Pause Ring tone )). perform ( click ()) ĊĠĠĠĠĠĠĠ Ġmedia Player Ġ= ĠMedia Player Helper . get MediaPlayer () ĊĠĠĠĠĠĠĠ Ġval Ġaudio Manager Ġ= Ġcontext . getSystem Service ( Context . AUDIO _ SERVICE ) Ġas ĠAudio Manager ĊĠĠĠĠĠĠĠ Ġval Ġmax Volume Ġ= Ġaudio Manager . get Stream Max Volume ( Audio Manager . STREAM _ ALARM ) ĊĠĠĠĠĠĠĠ Ġfor Ġ( i Ġin Ġ 1 Ġuntil Ġmax Volume ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals (" stream Volume Ġis Ġdifferent Ġform Ġexpected ", Ġi , Ġaudio Manager . get Stream Volume ( Audio Manager . STREAM _ ALARM )) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue (" ring tone Ġis Ġnot Ġplaying Ġ", Ġmedia Player . is Playing ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠThread . sleep ( Constant Values . DE EP _ WAKE _ UP _ VOLUME _ ADJ UST MENT _ MILLISECONDS ) ĊĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġplay Some Ring tone ( some Ring tone : ĠString Ġ= Ġ" energy ") Ġ{ ĊĠĠĠĠĠĠĠ Ġon Data ( with Text ( some Ring tone )) ĊĠĠĠĠĠĠĠ Ġon View ( all Of ( with Id ( R . id . ib Play Pause Ring tone ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġhas Sibling ( with Text ( some Ring tone )))) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( click ()) ĊĠĠĠ Ġ} Ċ }