package Ġcom . o he u rop a . android . domain Ċ Ċ import Ġcom . github . aj alt . tim ber kt . d Ċ import Ġcom . o he u rop a . android . data . DataManager Ċ import Ġcom . o he u rop a . android . framework . Ro bo electric Test Ċ import Ġcom . o he u rop a . android . model . Coordinate Ċ import Ġio . mock k . every Ċ import Ġio . mock k . mock k Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . subjects . Replay Subject Ċ import Ġorg . junit . Test Ċ import Ġkotlin . test . assertEquals Ċ Ċ /** Ċ Ġ* Ċ Ġ* ĠClass : Ġcom . o he u rop a . android . domain . Beacon Watcher Test Ċ Ġ* ĠProject : ĠOh Eu rop a - Android Ċ Ġ* ĠCreated ĠDate : Ġ 0 8 / 0 3 / 2 0 1 8 Ġ 0 8 : 5 5 Ċ Ġ* Ċ Ġ* Ġ@ author Ġ< a Ġhref =" mailto : e @ el roid . com "> El liot ĠLong </ a > Ċ Ġ* ĠĠĠĠĠĠĠĠ ĠCopyright Ġ( c ) Ġ 2 0 1 8 ĠEl roid ĠLtd . ĠAll Ġrights Ġreserved . Ċ Ġ*/ Ċ class ĠBe acon Watcher Test Ġ: ĠRo bo electric Test () Ġ{ ĊĊ ĉ @ Test Ċ ĉ fun Ġfollow Beacon Location _ given New Closest Beacon _ return New Beacon () Ġ{ ĊĊĉ ĉ val Ġnorth Lat Ġ= Ġ 5 1 . 6 Ċĉ ĉ val Ġmid North Lat Ġ= Ġ 5 1 . 5 Ċĉ ĉ val Ġmid Lat Ġ= Ġ 5 1 . 4 Ċĉ ĉ val Ġeast Lon Ġ= Ġ- 2 . 5 Ċĉ ĉ val Ġmid East Lon Ġ= Ġ- 2 . 6 Ċĉ ĉ val Ġmid Lon Ġ= Ġ- 2 . 7 Ċĉ ĉ val Ġnorth Point Ġ= ĠCoordinate ( north Lat , Ġmid Lon ) Ċĉ ĉ val Ġeast Point Ġ= ĠCoordinate ( mid Lat , Ġeast Lon ) Ċĉ ĉ val Ġstart Loc Ġ= ĠCoordinate ( mid North Lat , Ġmid Lon ) Ċĉ ĉ val Ġend Loc Ġ= ĠCoordinate ( mid Lat , Ġmid East Lon ) ĊĊĉ ĉ val Ġloc Obs Ġ= ĠRe play Subject . create < Coordinate >() Ċĉ ĉ val Ġlocator Ġ= Ġmock k < Location Component >{ Ċĉĉ ĉ every Ġ{ Ġlocation Listener () Ġ} Ġreturns Ġloc Obs Ċĉ ĉ } Ċĉ ĉ val Ġbe acon 1 Ġ= Ġcreate Beacon (" One ", Ġ 1 , Ġnorth Point ) Ċĉ ĉ val Ġbe acon 2 Ġ= Ġcreate Beacon (" Two ", Ġ 2 , Ġeast Point ) ĊĊĉ ĉ val Ġbe acon List Ġ= ĠlistOf ( beacon 1 , Ġbe acon 2 ) Ċĉ ĉ val Ġlist Obs Ġ= ĠObservable . just ( beacon List ) Ċĉĉ ĉ . do On Next Ġ{ Ċĉĉĉ ĉ d Ġ{ Ġ" Output ting Ġbe ac ons :$ it " Ġ} Ċĉĉ ĉ } Ċĉ ĉ val Ġdata Manager Ġ= Ġmock k < DataManager > Ġ{ Ċĉĉ ĉ every Ġ{ Ġfollow Beacon List () Ġ} Ġreturns Ġlist Obs Ċĉ ĉ } ĊĊĉ ĉ val Ġbe acon Watcher Ġ= ĠBe acon Watcher ( data Manager , Ġlocator ) ĊĊĉ ĉ // emit Ġfirst Ġlocation Ċĉ ĉ loc Obs . onNext ( start Loc ) ĊĊĉ ĉ // check Ġthat Ġbe acon 1 Ġis Ġthe Ġclosest Ċĉ ĉ val Ġtest Observer Ġ= Ġbe acon Watcher . follow Beacon Location (). test () Ċĉ ĉ val Ġclosest Beacon 1 Ġ= Ġtest Observer . values ()[ 0 ] Ċĉ ĉ assertEquals ( beacon 1 , Ġclosest Beacon 1 . be ac ons [ 0 ]) ĊĊĉ ĉ // emit Ġend Ġloc Ċĉ ĉ loc Obs . onNext ( end Loc ) Ċĉ ĉ // check Ġthat Ġbe acon 2 Ġis Ġnow Ġclosest Ċĉ ĉ val Ġclosest Beacon 2 Ġ= Ġtest Observer . values ()[ 1 ] Ċĉ ĉ assertEquals ( beacon 2 , Ġclosest Beacon 2 . be ac ons [ 0 ]) Ċ ĉ } Ċ }