package Ġio . horizontal systems . bank wallet . modules . pin Ċ Ċ import Ġcom . n ha ar man . mockito _ kotlin .* Ċ import Ġio . horizontal systems . bank wallet . core . I KeyStore Safe Execute Ċ import Ġio . horizontal systems . bank wallet . core . IP in Manager Ċ import Ġio . horizontal systems . bank wallet . core . managers . Auth Manager Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Captor Ċ import Ġorg . mockito . Mockito Ċ Ċ class ĠPin Interactor Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġdelegate Ġ= ĠMockito . mock ( Pin Module . IP in Interactor Delegate :: class . java ) ĊĠĠĠ Ġprivate Ġval Ġpin Manager Ġ= ĠMockito . mock ( IP in Manager :: class . java ) ĊĠĠĠ Ġprivate Ġval Ġauth Manager Ġ= ĠMockito . mock ( Auth Manager :: class . java ) ĊĠĠĠ Ġprivate Ġval Ġkeystore Safe Execute Ġ= ĠMockito . mock ( I KeyStore Safe Execute :: class . java ) ĊĠĠĠ Ġprivate Ġvar Ġinter actor Ġ= ĠPin Interactor ( pin Manager , Ġauth Manager , Ġkeystore Safe Execute ) ĊĊĠĠĠ Ġ@ Captor Ġprivate Ġval Ġaction Runnable Captor : ĠK Argument Captor < Runnable > Ġ= Ġargument Captor () ĊĠĠĠ Ġ@ Captor Ġprivate Ġval Ġsuccess Runnable Captor : ĠK Argument Captor < Runnable > Ġ= Ġargument Captor () ĊĠĠĠ Ġ@ Captor Ġprivate Ġval Ġfailure Runnable Captor : ĠK Argument Captor < Runnable > Ġ= Ġargument Captor () ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġinter actor . delegate Ġ= Ġdelegate ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ Ġverify No More Interactions ( delegate ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġvalidate _ success () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpin Ġ= Ġ" 0 0 0 0 " ĊĠĠĠĠĠĠĠ Ġinter actor . set ( pin ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( inter actor . validate ( pin )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġvalidate _ failure () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpin Ġ= Ġ" 0 0 0 0 " ĊĠĠĠĠĠĠĠ Ġval Ġpin 2 Ġ= Ġ" 1 1 1 1 " ĊĠĠĠĠĠĠĠ Ġinter actor . set ( pin ) ĊĠĠĠĠĠĠĠ ĠAssert . assertFalse ( inter actor . validate ( pin 2 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsave _ success Save () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpin Ġ= Ġ" 0 0 0 0 " ĊĠĠĠĠĠĠĠ Ġinter actor . save ( pin ) ĊĊĠĠĠĠĠĠĠ Ġverify ( keystore Safe Execute ). safe Execute ( action Runnable Captor . capture (), Ġsuccess Runnable Captor . capture (), Ġfailure Runnable Captor . capture ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġaction Runnable Ġ= Ġaction Runnable Captor . first Value ĊĠĠĠĠĠĠĠ Ġval Ġsuccess Runnable Ġ= Ġsuccess Runnable Captor . first Value ĊĊĠĠĠĠĠĠĠ Ġaction Runnable . run () ĊĠĠĠĠĠĠĠ Ġsuccess Runnable . run () ĊĊĠĠĠĠĠĠĠ Ġverify ( pin Manager ). store ( pin ) ĊĠĠĠĠĠĠĠ Ġverify ( delegate ). did Save Pin () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsave _ fail To Save () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpin Ġ= Ġ" 0 0 0 0 " ĊĠĠĠĠĠĠĠ Ġinter actor . save ( pin ) ĊĊĠĠĠĠĠĠĠ Ġverify ( keystore Safe Execute ). safe Execute ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaction Runnable Captor . capture (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsuccess Runnable Captor . capture (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfailure Runnable Captor . capture ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġaction Runnable Ġ= Ġaction Runnable Captor . first Value ĊĠĠĠĠĠĠĠ Ġval Ġfailure Runnable Ġ= Ġfailure Runnable Captor . first Value ĊĊĠĠĠĠĠĠĠ Ġaction Runnable . run () ĊĠĠĠĠĠĠĠ Ġfailure Runnable . run () ĊĊĠĠĠĠĠĠĠ Ġverify ( pin Manager ). store ( pin ) ĊĠĠĠĠĠĠĠ Ġverify ( delegate ). did Fail To Save Pin () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġunlock _ success () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpin Ġ= Ġ" 0 0 0 0 " ĊĠĠĠĠĠĠĠ Ġwhenever ( pin Manager . validate ( pin )). thenReturn ( true ) ĊĠĠĠĠĠĠĠ Ġval ĠisValid Ġ= Ġinter actor . unlock ( pin ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( isValid ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġunlock _ failure () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpin Ġ= Ġ" 0 0 0 0 " ĊĊĠĠĠĠĠĠĠ Ġwhenever ( pin Manager . validate ( pin )). thenReturn ( false ) ĊĊĠĠĠĠĠĠĠ Ġinter actor . unlock ( pin ) ĊĊĠĠĠĠĠĠĠ Ġval ĠisValid Ġ= Ġinter actor . unlock ( pin ) ĊĠĠĠĠĠĠĠ ĠAssert . assertFalse ( isValid ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġstart Adapters () Ġ{ ĊĠĠĠĠĠĠĠ Ġinter actor . start Adapters () ĊĊĠĠĠĠĠĠĠ Ġverify ( keystore Safe Execute ). safe Execute ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaction Runnable Captor . capture (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsuccess Runnable Captor . capture (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfailure Runnable Captor . capture () ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġaction Runnable Ġ= Ġaction Runnable Captor . first Value ĊĠĠĠĠĠĠĠ Ġval Ġsuccess Runnable Ġ= Ġsuccess Runnable Captor . first Value ĊĊĠĠĠĠĠĠĠ Ġaction Runnable . run () ĊĠĠĠĠĠĠĠ Ġsuccess Runnable . run () ĊĊĠĠĠĠĠĠĠ Ġverify ( auth Manager ). safe Load () ĊĠĠĠĠĠĠĠ Ġverify ( delegate ). did Started Adapters () ĊĠĠĠ Ġ} Ċ } Ċ