package Ġcom . shake it . core Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . hardware . Sensor Ċ import Ġandroid . hardware . Sensor . TYPE _ AC CEL ERO METER Ċ import Ġandroid . hardware . Sensor Event Ċ import Ġandroid . hardware . Sensor Manager Ċ import Ġcom . n ha ar man . mockito _ kotlin . mock Ċ import Ġcom . n ha ar man . mockito _ kotlin . never Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Ċ import Ġcom . n ha ar man . mockito _ kotlin . wh enever Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ Ċ class ĠSh ake It Life Cycle Listener Test Ġ{ ĊĠĠĠ Ġprivate Ġval Ġmock Sensor Manager Ġ= Ġmock < Sensor Manager >() ĊĠĠĠ Ġprivate Ġval Ġmock Sensor Ġ= Ġmock < Sensor >() ĊĠĠĠ Ġprivate Ġval Ġsh ake It Life Cycle Listener Ġ= ĠSh ake It Life Cycle Listener ( mock Sensor Manager ) ĊĠĠĠ Ġprivate Ġval Ġactivity Ġ= Ġmock < Activity >( extra Interfaces Ġ= ĠarrayOf ( Sh ake Listener :: class )) ĊĠĠĠ Ġprivate Ġval Ġsensor Event Ġ= Ġmock < Sensor Event >() ĊĠĠĠ Ġprivate Ġval Ġvalues Field Ġ= ĠSensor Event :: class . java . getField (" values ") !! ĊĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Sensor Manager . getDefault Sensor ( TYPE _ AC CEL ERO METER )). thenReturn ( mock Sensor ) ĊĠĠĠĠĠĠĠ Ġvalues Field . is Accessible Ġ= Ġtrue ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 5 0 0 ) Ġ// to Ġensure Ġevery Ġsh ake Ġis Ġdetected Ġand Ġnot Ġignored Ġas Ġduplicate Ġsh ake ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Register For Sh ake When Activity Is Res umed () Ġ{ ĊĠĠĠĠĠĠĠ Ġsh ake It Life Cycle Listener . on Activity Res umed ( mock ()) ĊĠĠĠĠĠĠĠ Ġverify ( mock Sensor Manager ). register Listener ( Sh ake Detector , Ġmock Sensor , ĠSensor Manager . SENSOR _ DELAY _ NORMAL ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Un Register For Sh ake When Activity Is Paused () Ġ{ ĊĠĠĠĠĠĠĠ Ġsh ake It Life Cycle Listener . on Activity Paused ( mock ()) ĊĠĠĠĠĠĠĠ Ġverify ( mock Sensor Manager ). unregister Listener ( Sh ake Detector , Ġmock Sensor ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Register Current Activity For Sh ake When Activity Is Sh ake Listener In On Resume () Ġ{ ĊĠĠĠĠĠĠĠ Ġsh ake It Life Cycle Listener . on Activity Res umed ( activity ) ĊĊĠĠĠĠĠĠĠ Ġvalues Field . set ( sensor Event , Ġfloat ArrayOf ( 3 0 F , Ġ 3 0 F , Ġ 3 0 F )) ĊĠĠĠĠĠĠĠ ĠSh ake Detector . on Sensor Changed ( sensor Event ) ĊĠĠĠĠĠĠĠ Ġverify ( activity Ġas ĠSh ake Listener ). on Sh ake () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Un Register Current Activity For Sh ake When Activity Is Sh ake Listener In On Pause () Ġ{ ĊĠĠĠĠĠĠĠ Ġsh ake It Life Cycle Listener . on Activity Res umed ( activity ) ĊĠĠĠĠĠĠĠ Ġsh ake It Life Cycle Listener . on Activity Paused ( activity ) ĊĊĠĠĠĠĠĠĠ Ġvalues Field . set ( sensor Event , Ġfloat ArrayOf ( 3 0 F , Ġ 3 0 F , Ġ 3 0 F )) ĊĠĠĠĠĠĠĠ ĠSh ake Detector . on Sensor Changed ( sensor Event ) ĊĠĠĠĠĠĠĠ Ġverify ( activity Ġas ĠSh ake Listener , Ġnever ()). on Sh ake () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ Ġvalues Field . is Accessible Ġ= Ġfalse ĊĠĠĠ Ġ} Ċ }