package Ġcom . github . ash ut osh g ng wr . no ice . fragment Ċ Ċ import Ġandroidx . fragment . app . testing . Fragment Scenario Ċ 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 . action . View Actions . scrollTo Ċ 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 Ġcom . github . ash ut osh g ng wr . no ice . Esp ress o X Ċ import Ġcom . github . ash ut osh g ng wr . no ice . R Ċ import Ġcom . github . ash ut osh g ng wr . no ice . Retry Test Rule Ċ import Ġcom . github . ash ut osh g ng wr . no ice . Wake Up Timer Manager Ċ import Ġcom . github . ash ut osh g ng wr . no ice . sound . Preset Ċ import Ġio . mock k .* Ċ import Ġorg . hamcrest . Matchers . not Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Assert . assertTrue Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠW ake Up Timer Fragment Test Ġ{ ĊĊĠ Ġ@ Rule ĊĠ Ġ@ Jvm Field ĊĠ Ġval Ġretry Test Rule Ġ= ĠRetry Test Rule ( 5 ) ĊĊĠ Ġprivate Ġlateinit Ġvar Ġfragment Scenario : ĠFragment Scenario < Wake Up Timer Fragment > ĊĊĠ Ġ@ Before ĊĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠ Ġmock k Object ( Preset . Companion ) ĊĠĠĠ Ġmock k Object ( Wake Up Timer Manager ) ĊĠĠĠ Ġevery Ġ{ ĠW ake Up Timer Manager . set ( any (), Ġany ()) Ġ} Ġreturns ĠUnit ĊĠĠĠ Ġfragment Scenario Ġ= Ġlaunch Fragment In Container < Wake Up Timer Fragment >( null , ĠR . style . Theme _ App ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Initial Layout _ when Timer IsNot Pre Scheduled () Ġ{ ĊĠĠĠ Ġon View ( with Id ( R . id . countdown _ view )) ĊĠĠĠĠĠ Ġ. check ( matches ( with Text (" 0 0 h Ġ 0 0 m Ġ 0 0 s "))) ĊĊĠĠĠ Ġon View ( with Id ( R . id . button _ select _ preset )) ĊĠĠĠĠĠ Ġ. check ( matches ( isEnabled ())) ĊĠĠĠĠĠ Ġ. check ( matches ( with Text ( R . string . select _ preset ))) ĊĊĠĠĠ Ġon View ( with Id ( R . id . duration _ picker )) ĊĠĠĠĠĠ Ġ. check ( matches ( not ( isEnabled ()))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Initial Layout _ when Timer Is Pre Scheduled () Ġ{ ĊĠĠĠ Ġevery Ġ{ ĠP reset . find ByName ( any (), Ġ" test ") Ġ} Ġreturns Ġmock k () ĊĠĠĠ Ġevery Ġ{ ĠW ake Up Timer Manager . get ( any ()) Ġ} Ġreturns Ġmock k Ġ{ ĊĠĠĠĠĠ Ġevery Ġ{ Ġpre setName Ġ} Ġreturns Ġ" test " ĊĠĠĠĠĠ Ġevery Ġ{ Ġat Millis Ġ} Ġreturns ĠSystem . currentTimeMillis () Ġ+ Ġ 1 0 0 0 0 L ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfragment Scenario . re create () ĊĠĠĠ Ġon View ( with Id ( R . id . countdown _ view )) ĊĠĠĠĠĠ Ġ. check ( matches ( not ( with Text (" 0 0 h Ġ 0 0 m Ġ 0 0 s ")) )) ĊĊĠĠĠ Ġon View ( with Id ( R . id . button _ select _ preset )) ĊĠĠĠĠĠ Ġ. check ( matches ( isEnabled ())) ĊĠĠĠĠĠ Ġ. check ( matches ( with Text (" test "))) ĊĊĠĠĠ Ġon View ( with Id ( R . id . duration _ picker )) ĊĠĠĠĠĠ Ġ. check ( matches ( isEnabled ())) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Initial Layout _ when Timer Is Pre Scheduled _ and Preset Is Deleted From Storage () Ġ{ ĊĠĠĠ Ġevery Ġ{ ĠP reset . find ByName ( any (), Ġ" test ") Ġ} Ġreturns Ġnull ĊĠĠĠ Ġevery Ġ{ ĠW ake Up Timer Manager . get ( any ()) Ġ} Ġreturns Ġmock k Ġ{ ĊĠĠĠĠĠ Ġevery Ġ{ Ġpre setName Ġ} Ġreturns Ġ" test " ĊĠĠĠĠĠ Ġevery Ġ{ Ġat Millis Ġ} Ġreturns ĠSystem . currentTimeMillis () Ġ+ Ġ 1 0 0 0 0 L ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfragment Scenario . re create () ĊĠĠĠ Ġon View ( with Id ( R . id . countdown _ view )) ĊĠĠĠĠĠ Ġ. check ( matches ( with Text (" 0 0 h Ġ 0 0 m Ġ 0 0 s "))) ĊĊĠĠĠ Ġon View ( with Id ( R . id . button _ select _ preset )) ĊĠĠĠĠĠ Ġ. check ( matches ( isEnabled ())) ĊĠĠĠĠĠ Ġ. check ( matches ( with Text ( R . string . select _ preset ))) ĊĊĠĠĠ Ġon View ( with Id ( R . id . duration _ picker )) ĊĠĠĠĠĠ Ġ. check ( matches ( not ( isEnabled ()))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Set Timer () Ġ{ ĊĠĠĠ Ġevery Ġ{ ĠP reset . read All From User Preferences ( any ()) Ġ} Ġreturns ĠarrayOf ( ĊĠĠĠĠĠ Ġmock k ( relax ed Ġ= Ġtrue ) Ġ{ Ġevery Ġ{ Ġname Ġ} Ġreturns Ġ" test - 1 " Ġ}, ĊĠĠĠĠĠ Ġmock k ( relax ed Ġ= Ġtrue ) Ġ{ Ġevery Ġ{ Ġname Ġ} Ġreturns Ġ" test - 2 " Ġ} ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġon View ( with Id ( R . id . button _ select _ preset )) ĊĠĠĠĠĠ Ġ. check ( matches ( with Text ( R . string . select _ preset ))) ĊĠĠĠĠĠ Ġ. perform ( click ()) ĊĊĠĠĠ ĠE sp ress o X . waitFor View ( with Id ( android . R . id . list ), Ġ 1 0 0 , Ġ 5 ) ĊĠĠĠĠĠ Ġ. check ( matches ( with Child ( with Text (" test - 1 ")) )) ĊĠĠĠĠĠ Ġ. check ( matches ( with Child ( with Text (" test - 2 ")) )) ĊĊĠĠĠ Ġon View ( with Text (" test - 1 ")) ĊĠĠĠĠĠ Ġ. perform ( click ()) ĊĊĠĠĠ Ġon View ( with Id ( R . id . button _ select _ preset )) ĊĠĠĠĠĠ Ġ. check ( matches ( with Text (" test - 1 "))) ĊĊĠĠĠ Ġverify ( exact ly Ġ= Ġ 0 ) Ġ{ ĠW ake Up Timer Manager . set ( any (), Ġany ()) Ġ} ĊĠĠĠ Ġon View ( with Id ( R . id . duration _ picker )) ĊĠĠĠĠĠ Ġ. check ( matches ( isEnabled ())) ĊĠĠĠĠĠ Ġ. perform ( Esp ress o X . add Duration To Picker ( 1 0 L )) ĊĊĠĠĠ Ġval Ġtimer Slot Ġ= Ġslot < Wake Up Timer Manager . Timer >() ĊĠĠĠ Ġverify ( exact ly Ġ= Ġ 1 ) Ġ{ ĠW ake Up Timer Manager . set ( any (), Ġcapture ( timer Slot )) Ġ} ĊĠĠĠ ĠassertEquals (" test - 1 ", Ġtimer Slot . captured . pre setName ) ĊĠĠĠ Ġval Ġtime Range Ġ= ĠSystem . currentTimeMillis () Ġuntil ĠSystem . currentTimeMillis () Ġ+ Ġ 1 0 0 0 0 L ĊĠĠĠ ĠassertTrue ( timer Slot . captured . at Millis Ġin Ġtime Range ) ĊĊĠĠĠ Ġon View ( Esp ress o X . with Duration Picker Reset Button ( with Id ( R . id . duration _ picker ))) ĊĠĠĠĠĠ Ġ. check ( matches ( isEnabled ())) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Cancel Timer () Ġ{ ĊĠĠĠ Ġevery Ġ{ ĠP reset . find ByName ( any (), Ġ" test ") Ġ} Ġreturns Ġmock k () ĊĠĠĠ Ġevery Ġ{ ĠW ake Up Timer Manager . get ( any ()) Ġ} Ġreturns Ġmock k Ġ{ ĊĠĠĠĠĠ Ġevery Ġ{ Ġpre setName Ġ} Ġreturns Ġ" test " ĊĠĠĠĠĠ Ġevery Ġ{ Ġat Millis Ġ} Ġreturns ĠSystem . currentTimeMillis () Ġ+ Ġ 1 0 0 0 0 L ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfragment Scenario . re create () ĊĠĠĠ Ġclear Mocks ( Wake Up Timer Manager ) ĊĠĠĠ Ġon View ( Esp ress o X . with Duration Picker Reset Button ( with Id ( R . id . duration _ picker ))) ĊĠĠĠĠĠ Ġ. check ( matches ( isEnabled ())) ĊĠĠĠĠĠ Ġ. perform ( scrollTo (), Ġclick ()) ĊĊĠĠĠ Ġverify ( exact ly Ġ= Ġ 1 ) Ġ{ ĠW ake Up Timer Manager . cancel ( any ()) Ġ} ĊĠ Ġ} Ċ } Ċ