package Ġorg . simple . clin ic . qr scan Ċ Ċ import Ġcom . n ha ar man . mockito _ kotlin . any Ċ 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 Ġio . reactivex . Comp letable Ċ import Ġio . reactivex . subjects . Publish Subject Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . simple . clin ic . patient . Patient Repository Ċ import Ġorg . simple . clin ic . util . Runtime Permission Result Ċ import Ġorg . simple . clin ic . util . V ibr ator Ċ import Ġorg . simple . clin ic . widgets . Ui Event Ċ Ċ class ĠA ad ha ar Scan Screen Controller Test Ġ{ ĊĊĠ Ġprivate Ġval Ġui Events : ĠPublish Subject < Ui Event > Ġ= ĠPublish Subject . create () ĊĊĠ Ġprivate Ġval Ġscreen Ġ= Ġmock < A ad ha ar Scan Screen >() ĊĠ Ġprivate Ġval Ġa ad ha ar Qr Code Parser Ġ= Ġmock < A ad ha ar Qr Code Parser >() ĊĠ Ġprivate Ġval Ġvi br ator Ġ= Ġmock < V ibr ator >() ĊĠ Ġprivate Ġval Ġrepository Ġ= Ġmock < Patient Repository >() ĊĠ Ġprivate Ġval Ġcontroller : ĠA ad ha ar Scan Screen Controller Ġ= ĠA ad ha ar Scan Screen Controller ( aad ha ar Qr Code Parser , Ġvi br ator , Ġrepository ) ĊĊĠ Ġ@ Before ĊĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠ Ġui Events ĊĠĠĠĠĠĠĠ Ġ. compose ( controller ) ĊĠĠĠĠĠĠĠ Ġ. subscribe Ġ{ Ġui Change Ġ-> Ġui Change ( screen ) Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġa ad ha ar Ġscan Ġis Ġclicked Ġbut Ġcamera Ġpermission Ġisn 't Ġgranted Ġthen Ġrequest Ġfor Ġit Ġand Ġenable Ġscan Ġonce Ġit 's Ġis Ġgranted `() Ġ{ ĊĠĠĠ Ġui Events . onNext ( Camera Permission Changed ( Runtime Permission Result . DEN IED )) ĊĠĠĠ Ġui Events . onNext ( A ad ha ar Scan Clicked ()) ĊĠĠĠ ĠMockito . verify ( screen ). request Camera Permission () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` toggle ĠA ad ha ar Ġscanner Ġwith Ġcamera Ġpermission Ġtoggle s `() Ġ{ ĊĠĠĠ Ġui Events . onNext ( Camera Permission Changed ( Runtime Permission Result . GRAN TED )) ĊĠĠĠ Ġui Events . onNext ( Camera Permission Changed ( Runtime Permission Result . DEN IED )) ĊĠĠĠ Ġui Events . onNext ( Camera Permission Changed ( Runtime Permission Result . GRAN TED )) ĊĠĠĠ Ġui Events . onNext ( Camera Permission Changed ( Runtime Permission Result . NE VER _ ASK _ AG AIN )) ĊĊĠĠĠ ĠMockito . verify ( screen , ĠMockito . times ( 2 )). set A ad ha ar Scanner Enabled ( true ) ĊĠĠĠ ĠMockito . verify ( screen , ĠMockito . times ( 2 )). set A ad ha ar Scanner Enabled ( false ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġan Ġa ad ha ar Ġqr Ġcode Ġis Ġidentified Ġthen Ġplay Ġa Ġshort Ġvi br ation `() Ġ{ ĊĠĠĠ Ġval Ġa ad ha ar Qr Data Ġ= Ġmock < A ad ha ar Qr Data >() ĊĠĠĠ Ġwhenever ( aad ha ar Qr Code Parser . parse (" qr - code ")). thenReturn ( aad ha ar Qr Data ) ĊĠĠĠ Ġwhenever ( repository . save O ngo ing Entry ( any ())). thenReturn ( Comp letable . complete ()) ĊĊĠĠĠ Ġui Events . onNext ( Qr Sc anned (" qr - code ")) ĊĊĠĠĠ Ġverify ( vi br ator ). vi br ate ( any ()) ĊĠ Ġ} ĊĊĠ Ġ// ĠTODO : ĠUncomment Ġwhen Ġworking Ġon ĠA ad ha ar . ĠThis Ġtest Ġis Ġbreaking ĠCI . Ċ // Ġ Ġ@ Test Ċ // Ġ Ġfun Ġ` when Ġan Ġa ad ha ar Ġqr Ġcode Ġis Ġidentified Ġthen Ġstart Ġa Ġnew Ġpatient Ġflow Ġwith Ġpre - filled Ġvalues `() Ġ{ Ċ // ĠĠĠ Ġval Ġa ad ha ar Qr Data Ġ= ĠA ad ha ar Qr Data ( Ċ // ĠĠĠĠĠĠĠ ĠfullName Ġ= Ġ" S aket ĠN ar ay an ", Ċ // ĠĠĠĠĠĠĠ Ġgender Ġ= ĠGender . M ALE , Ċ // ĠĠĠĠĠĠĠ Ġdate OfBirth Ġ= Ġ" 1 2 / 0 4 / 1 9 9 3 ", Ċ // ĠĠĠĠĠĠĠ Ġv illage Or Town Or City Ġ= Ġ" H arm u ", Ċ // ĠĠĠĠĠĠĠ Ġdistrict Ġ= Ġ" R anch i ", Ċ // ĠĠĠĠĠĠĠ Ġstate Ġ= Ġ" Jh ark hand ") Ċ // Ċ // ĠĠĠ Ġwhenever ( aad ha ar Qr Code Parser . parse (" qr - code ")). thenReturn ( aad ha ar Qr Data ) Ċ // ĠĠĠ Ġwhenever ( repository . save O ngo ing Entry ( any ())). thenReturn ( Comp letable . complete ()) Ċ // Ċ // ĠĠĠ Ġui Events . onNext ( Qr Sc anned (" qr - code ")) Ċ // Ċ // ĠĠĠ Ġargument Captor < O ngo ing Patient Entry >(). apply Ġ{ Ċ // ĠĠĠĠĠ Ġverify ( repository ). save O ngo ing Entry ( capture ()) Ċ // Ċ // ĠĠĠĠĠ Ġassert ( first Value Ġ== ĠO ngo ing Patient Entry ( Ċ // ĠĠĠĠĠĠĠĠĠ Ġpersonal Details Ġ= ĠO ngo ing Patient Entry . Personal Details ( Ċ // ĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠfullName Ġ= Ġa ad ha ar Qr Data . fullName !! , Ċ // ĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdate OfBirth Ġ= Ġa ad ha ar Qr Data . date OfBirth !! , Ċ // ĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġage Ġ= Ġnull , Ċ // ĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġgender Ġ= Ġa ad ha ar Qr Data . gender ), Ċ // ĠĠĠĠĠĠĠĠĠ Ġaddress Ġ= ĠO ngo ing Patient Entry . Address ( Ċ // ĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcol ony Or V illage Ġ= Ġa ad ha ar Qr Data . v illage Or Town Or City !! , Ċ // ĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdistrict Ġ= Ġa ad ha ar Qr Data . district !! , Ċ // ĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstate Ġ= Ġa ad ha ar Qr Data . state !! ) Ċ // ĠĠĠĠĠ Ġ)) Ċ // ĠĠĠ Ġ} Ċ // ĠĠĠ Ġverify ( screen ). open New Patient Entry Screen () Ċ // Ġ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` non - aad ha ar Ġqr Ġcodes Ġshould Ġbe Ġignored `() Ġ{ ĊĠĠĠ Ġwhenever ( aad ha ar Qr Code Parser . parse (" invalid - qr - code ")). thenReturn ( Unknown Qr ()) ĊĠĠĠ Ġwhenever ( repository . save O ngo ing Entry ( any ())). thenReturn ( Comp letable . complete ()) ĊĊĠĠĠ Ġui Events . onNext ( Qr Sc anned (" invalid - qr - code ")) ĊĊĠĠĠ Ġverify ( repository , Ġnever ()). save O ngo ing Entry ( any ()) ĊĠĠĠ Ġverify ( screen , Ġnever ()). open New Patient Entry Screen () ĊĠ Ġ} Ċ } Ċ