/* Ċ Ġ* ĠCopyright ĠÂ© ĠM obi Lab ĠSolutions ĠGmbH Ċ Ġ*/ Ċ Ċ package Ġcom . mob il ab solutions . payment . service Ċ Ċ import Ġcom . mob il ab solutions . payment . data . Merchant Ċ import Ġcom . mob il ab solutions . payment . data . Merchant ApiKey Ċ import Ġcom . mob il ab solutions . payment . data . repository . Merchant ApiKey Repository Ċ import Ġcom . mob il ab solutions . payment . data . repository . Merchant Repository Ċ import Ġcom . mob il ab solutions . payment . model . request . ApiKey Edit Request Model Ċ import Ġcom . mob il ab solutions . payment . model . request . ApiKey Request Model Ċ import Ġcom . mob il ab solutions . server . commons . exception . ApiException Ċ import Ġorg . junit . jupiter . api . Assertions Ċ import Ġorg . junit . jupiter . api . Before All Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . Test Instance Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . mockito . Inject Mocks Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . mockito . Mockito Annotations Ċ import Ġorg . mockito . junit . jupiter . Mockito Extension Ċ import Ġorg . mockito . junit . jupiter . Mockito Settings Ċ import Ġorg . mockito . quality . Strict ness Ċ Ċ /** Ċ Ġ* Ġ@ author Ġ< a Ġhref =" mailto : mo h amed . os man @ mob il ab solutions . com "> M oh amed ĠOs man </ a > Ċ Ġ*/ Ċ @ Extend With ( Mockito Extension :: class ) Ċ @ Mockito Settings ( strict ness Ġ= ĠStrict ness . STRICT _ ST UB S ) Ċ @ Test Instance ( Test Instance . Lifecycle . PER _ CLASS ) Ċ class ĠApi Key Service Test Ġ{ ĊĠĠĠ Ġprivate Ġval Ġmerchant Api Keys Ġ= ĠArrayList < Merchant ApiKey >() ĊĠĠĠ Ġprivate Ġval Ġknown ApiKey Id : ĠLong Ġ= Ġ 1 ĊĠĠĠ Ġprivate Ġval Ġunknown ApiKey Id : ĠLong Ġ= Ġ 3 ĊĠĠĠ Ġprivate Ġval Ġknown Merchant Id Ġ= Ġ" mob il ab " ĊĠĠĠ Ġprivate Ġval Ġunknown Merchant Id Ġ= Ġ" test " ĊĊĠĠĠ Ġ@ Inject Mocks ĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠapiKey Service : ĠApi Key Service ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmerchant ApiKey Repository : ĠMer chant ApiKey Repository ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmerchant Repository : ĠMer chant Repository ĊĊĠĠĠ Ġ@ Before All ĊĠĠĠ Ġfun Ġbefore All () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito Annotations . init Mocks ( this ) ĊĊĠĠĠĠĠĠĠ ĠMockito .` when `( merchant ApiKey Repository . getAll By Merchant Id ( known Merchant Id )). thenReturn ( merchant Api Keys ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( merchant Repository . get Merchant ById ( unknown Merchant Id )). thenReturn ( null ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( merchant Repository . get Merchant ById ( known Merchant Id )). thenReturn ( Mockito . mock ( Merchant :: class . java )) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( merchant ApiKey Repository . getFirst ById ( unknown ApiKey Id )). thenReturn ( null ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( merchant ApiKey Repository . getFirst ById ( known ApiKey Id )). thenReturn ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠMer chant ApiKey ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmerchant Ġ= ĠMer chant () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( merchant ApiKey Repository . edit ApiKey ( null , Ġunknown ApiKey Id )). thenReturn ( 0 ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( merchant ApiKey Repository . edit ApiKey ( null , Ġknown ApiKey Id )). thenReturn ( 1 ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( merchant ApiKey Repository . delete Merchant ApiKey ById ( unknown ApiKey Id )). thenReturn ( 0 ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( merchant ApiKey Repository . delete Merchant ApiKey ById ( known ApiKey Id )). thenReturn ( 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġall Ġapi Ġkey Ġinfo Ġwith Ġwrong Ġmerchant Ġid `() Ġ{ ĊĠĠĠĠĠĠĠ ĠAssertions . assert Throws ( ApiException :: class . java ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠapiKey Service . get Merchant ApiKey Info ( unknown Merchant Id ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġapi Ġkeys Ġsuccessfully `() Ġ{ ĊĠĠĠĠĠĠĠ Ġmerchant Api Keys . add ( Merchant ApiKey ( merchant Ġ= ĠMer chant ())) ĊĠĠĠĠĠĠĠ ĠapiKey Service . get Merchant ApiKey Info ( known Merchant Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` create Ġmerchant Ġapi Ġkey Ġwith Ġwrong Ġmerchant Ġid `() Ġ{ ĊĠĠĠĠĠĠĠ ĠAssertions . assert Throws ( ApiException :: class . java ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠapiKey Service . create Merchant ApiKey ( unknown Merchant Id , ĠMockito . mock ( ApiKey Request Model :: class . java )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` create Ġmerchant Ġapi Ġkey Ġsuccessfully `() Ġ{ ĊĠĠĠĠĠĠĠ ĠapiKey Service . create Merchant ApiKey ( known Merchant Id , ĠApi Key Request Model ( type Ġ= Ġ" SECRET ", Ġname Ġ= Ġ" Key ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġmerchant Ġapi Ġkey Ġinfo Ġwith Ġwrong Ġapi Ġkey Ġid `() Ġ{ ĊĠĠĠĠĠĠĠ ĠAssertions . assert Throws ( ApiException :: class . java ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠapiKey Service . get Merchant ApiKey Info ById ( unknown ApiKey Id ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġmerchant Ġapi Ġkey Ġinfo Ġwith Ġapi Ġkey Ġid Ġsuccessfully `() Ġ{ ĊĠĠĠĠĠĠĠ ĠapiKey Service . get Merchant ApiKey Info ById ( known ApiKey Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` edit Ġmerchant Ġapi Ġkey Ġinfo Ġwith Ġwrong Ġapi Ġkey Ġid `() Ġ{ ĊĠĠĠĠĠĠĠ ĠAssertions . assert Throws ( ApiException :: class . java ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠapiKey Service . edit Merchant ApiKey Info ById ( unknown ApiKey Id , ĠMockito . mock ( ApiKey Edit Request Model :: class . java )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` edit Ġmerchant Ġapi Ġkey Ġinfo Ġwith Ġapi Ġkey Ġid Ġsuccessfully `() Ġ{ ĊĠĠĠĠĠĠĠ ĠapiKey Service . edit Merchant ApiKey Info ById ( known ApiKey Id , ĠMockito . mock ( ApiKey Edit Request Model :: class . java )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` delete Ġmerchant Ġapi Ġkey Ġinfo Ġwith Ġwrong Ġapi Ġkey Ġid `() Ġ{ ĊĠĠĠĠĠĠĠ ĠAssertions . assert Throws ( ApiException :: class . java ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠapiKey Service . delete Merchant ApiKey ById ( unknown ApiKey Id ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` delete Ġmerchant Ġapi Ġkey Ġinfo Ġwith Ġapi Ġkey Ġid Ġsuccessfully `() Ġ{ ĊĠĠĠĠĠĠĠ ĠapiKey Service . delete Merchant ApiKey ById ( known ApiKey Id ) ĊĠĠĠ Ġ} Ċ } Ċ