package Ġcom . one gin i . mobile . sdk Ċ Ċ import Ġcom . google . common . truth . Truth Ċ import Ġcom . google . gson . Gson Ċ import Ġcom . one gin i . mobile . sdk . android . client . One gin i Client Ċ import Ġcom . one gin i . mobile . sdk . android . client . User Client Ċ import Ġcom . one gin i . mobile . sdk . android . handlers . One gin i Implicit Authentication Handler Ċ import Ġcom . one gin i . mobile . sdk . android . handlers . error . One gin i Implicit Token Request Error Ċ import Ġcom . one gin i . mobile . sdk . android . model . entity . UserProfile Ċ import Ġcom . one gin i . mobile . sdk . flutter . One gin i Wrapper Errors Ċ import Ġcom . one gin i . mobile . sdk . flutter . use Cases . Authenticate User Implicit ly UseCase Ċ import Ġio . flutter . plugin . common . MethodCall Ċ import Ġio . flutter . plugin . common . Method Channel Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Argument Matchers Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . mockito . Spy Ċ import Ġorg . mockito . junit . Mockito JUnit Runner Ċ import Ġorg . mockito . kotlin . any Ċ import Ġorg . mockito . kotlin . isNull Ċ import Ġorg . mockito . kotlin . verify Ċ import Ġorg . mockito . kotlin . wh enever Ċ import Ġorg . mockito . kotlin . eq Ċ import Ġorg . mockito . kotlin . argument Captor Ċ Ċ @ RunWith ( Mockito JUnit Runner :: class ) Ċ class ĠAuth enticate User Implicit ly UseCase Tests Ġ{ ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġlateinit Ġvar Ġclient Mock : ĠOne gin i Client ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġlateinit Ġvar Ġone gin i Implicit Token Request Error Mock : ĠOne gin i Implicit Token Request Error ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġlateinit Ġvar Ġuser Client Mock : ĠUser Client ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġlateinit Ġvar Ġcall Mock : ĠMethod Call ĊĊĠĠĠ Ġ@ Spy ĊĠĠĠ Ġlateinit Ġvar Ġresult Spy : ĠMethod Channel . Result ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġattach () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( client Mock . user Client ). thenReturn ( user Client Mock ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġreturn Ġerror Ġwhen Ġthe Ġsdk Ġreturns Ġauthentication Ġerror `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( call Mock . argument < ArrayList < String >> (" scope ")). thenReturn ( null ) ĊĠĠĠĠĠĠĠ Ġwhenever ( user Client Mock . user Profiles ). thenReturn ( set Of ( UserProfile (" Q WER TY "))) ĊĠĠĠĠĠĠĠ Ġwhenever ( one gin i Implicit Token Request Error Mock . error Type ). thenReturn ( One gin i Implicit Token Request Error . GENERAL _ ERROR ) ĊĠĠĠĠĠĠĠ Ġwhenever ( one gin i Implicit Token Request Error Mock . message ). thenReturn (" General Ġerror ") ĊĠĠĠĠĠĠĠ Ġwhenever ( user Client Mock . authenticate User Implicit ly ( eq ( UserProfile (" Q WER TY ")), Ġis Null (), Ġany ())). then Answer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . get Argument < One gin i Implicit Authentication Handler >( 2 ). onError ( one gin i Implicit Token Request Error Mock ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠAuth enticate User Implicit ly UseCase ( client Mock )( call Mock , Ġresult Spy ) ĊĊĠĠĠĠĠĠĠ Ġverify ( result Spy ). error ( one gin i Implicit Token Request Error Mock . error Type . toString (), Ġone gin i Implicit Token Request Error Mock . message , Ġnull ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġreturn Ġerror Ġwhen Ġthere Ġare Ġno Ġregistered Ġusers `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( call Mock . argument < ArrayList < String >> (" scope ")). thenReturn ( null ) ĊĠĠĠĠĠĠĠ Ġwhenever ( user Client Mock . user Profiles ). thenReturn ( set Of ()) ĊĊĠĠĠĠĠĠĠ ĠAuth enticate User Implicit ly UseCase ( client Mock )( call Mock , Ġresult Spy ) ĊĊĠĠĠĠĠĠĠ Ġverify ( result Spy ). error ( One gin i Wrapper Errors . USER _ PROFILE _ IS _ NULL . code , ĠOne gin i Wrapper Errors . USER _ PROFILE _ IS _ NULL . message , Ġnull ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġreturn Ġsuccess Ġwhen Ġthe ĠSDK Ġreturns Ġsuccess `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( call Mock . argument < ArrayList < String >> (" scope ")). thenReturn ( array ListOf (" test ")) ĊĠĠĠĠĠĠĠ Ġwhenever ( user Client Mock . user Profiles ). thenReturn ( set Of ( UserProfile (" Q WER TY "))) ĊĠĠĠĠĠĠĠ Ġwhenever ( user Client Mock . authenticate User Implicit ly ( eq ( UserProfile (" Q WER TY ")), Ġeq ( array Of (" test ")), Ġany ())). then Answer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . get Argument < One gin i Implicit Authentication Handler >( 2 ). on Success ( UserProfile (" Q WER TY ")) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠAuth enticate User Implicit ly UseCase ( client Mock )( call Mock , Ġresult Spy ) ĊĊĠĠĠĠĠĠĠ Ġverify ( result Spy ). success ( eq ( Gson (). toJson ( UserProfile (" Q WER TY ")) )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġscopes Ġparam Ġbe Ġarray Ġof Ġtwo Ġscopes Ġwhen Ġgiven Ġscopes Ġcontains Ġtwo Ġstrings `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( call Mock . argument < ArrayList < String >> (" scope ")). thenReturn ( array ListOf (" read ", Ġ" write ")) ĊĠĠĠĠĠĠĠ Ġwhenever ( user Client Mock . user Profiles ). thenReturn ( set Of ( UserProfile (" Q WER TY "))) ĊĊĠĠĠĠĠĠĠ ĠAuth enticate User Implicit ly UseCase ( client Mock )( call Mock , Ġresult Spy ) ĊĊĠĠĠĠĠĠĠ Ġargument Captor < Array < String >> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠMockito . verify ( user Client Mock ). authenticate User Implicit ly ( eq ( UserProfile (" Q WER TY ")), Ġcapture (), ĠArgument Matchers . any ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTr uth . assertThat ( first Value . size ). isEqualTo ( 2 ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTr uth . assertThat ( first Value ). isEqualTo ( array Of (" read ", Ġ" write ")) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ Ċ }