@ file : Suppress (" DE PREC ATION ") Ċ Ċ package Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . resource . api Ċ Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . do Throw Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġorg . assertj . core . api . Assertions . assertThat Thrown By Ċ import Ġorg . assertj . core . api . Java 6 Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . mockito . Argument Matchers . any String Ċ import Ġorg . springframework . security . authentication . Testing Authentication Token Ċ import Ġorg . springframework . security . oauth 2 . provider . NoSuch ClientException Ċ import Ġorg . springframework . security . oauth 2 . provider . client . Base Client Details Ċ import Ġorg . springframework . security . oauth 2 . provider . client . Jdbc Client Details Service Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . service . Client Service Ċ import Ġuk . gov . just ice . digital . h mp ps . oauth 2 server . service . Duplicate Clients Exception Ċ Ċ class ĠDuplicate Client Controller Test Ġ{ ĊĊĠ Ġprivate Ġval Ġclient Service : ĠClient Service Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġclient Details Service : ĠJdbc Client Details Service Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġauthentication Ġ= ĠTesting Authentication Token ( ĊĠĠĠ Ġ" duplicate ", ĊĠĠĠ Ġ" pass ", ĊĠĠĠ Ġ" ROLE _ O AUTH _ ADMIN " ĊĠ Ġ) ĊĠ Ġprivate Ġval Ġduplicate Client Controller Ġ= ĠDuplicate Client Controller ( client Service , Ġclient Details Service ) ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Duplicate Ġclient `() Ġ{ ĊĠĠĠ Ġval Ġclient Ġ= ĠBase Client Details ( ĊĠĠĠĠĠ Ġ" client - 1 ", Ġnull , ĊĠĠĠĠĠ Ġ" read , write ", Ġ" client _ credentials ", Ġ" ROLE _" ĊĠĠĠ Ġ) ĊĠĠĠ Ġclient . client Secret Ġ= Ġ" SO ME - RANDOM - STRING " ĊĠĠĠ Ġwhenever ( client Service . duplicate Client ( any String ())). thenReturn ( client ) ĊĠĠĠ Ġval Ġnew Duplicate Client Ġ= Ġduplicate Client Controller . duplicate Client ( authentication , Ġ" client ") ĊĊĠĠĠ ĠassertThat ( new Duplicate Client ). isEqualTo ( Duplicate Client Detail ( client )) ĊĠĠĠ ĠassertThat ( new Duplicate Client . clientId ). isEqualTo (" client - 1 ") ĊĠĠĠ ĠassertThat ( new Duplicate Client . client Secret ). isEqualTo (" SO ME - RANDOM - STRING ") ĊĠĠĠ ĠassertThat ( new Duplicate Client . base 6 4 ClientId ). isEqualTo (" Y 2 xp ZW 5 0 LTE =") ĊĠĠĠ ĠassertThat ( new Duplicate Client . base 6 4 Client Secret ). isEqualTo (" U 0 9 N RS 1 S QU 5 ET 0 0 t U 1 RSS U 5 H ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Duplicate Ġclient Ġfails Ġ- ĠMax ĠD uplicates Ġreached `() Ġ{ ĊĠĠĠ Ġdo Throw ( Duplicate Clients Exception (" cust ard ", Ġ" Max Reached ")). wh enever ( client Service ). duplicate Client ( any String ()) ĊĊĠĠĠ ĠassertThat Thrown By Ġ{ Ġduplicate Client Controller . duplicate Client ( authentication , Ġ" max - client ") Ġ} ĊĠĠĠĠĠ Ġ. isInstanceOf ( Duplicate Clients Exception :: class . java ) ĊĠĠĠĠĠ Ġ. with Fail Message (" Duplicate ĠclientId Ġfailed Ġfor Ġmax - client Ġwith Ġreason : ĠMax Reached ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Duplicate Ġclient Ġfails Ġ- Ġclient Ġnot Ġfound `() Ġ{ ĊĠĠĠ Ġdo Throw ( NoSuch ClientException (" No Ġclient Ġwith Ġrequested Ġid : Ġnon - client ")). wh enever ( client Service ) ĊĠĠĠĠĠ Ġ. duplicate Client ( any String ()) ĊĊĠĠĠ ĠassertThat Thrown By Ġ{ Ġduplicate Client Controller . duplicate Client ( authentication , Ġ" non - client ") Ġ} ĊĠĠĠĠĠ Ġ. isInstanceOf ( NoSuch ClientException :: class . java ) ĊĠĠĠĠĠ Ġ. with Fail Message (" No Ġclient Ġwith Ġrequested Ġid : Ġnon - client ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` Delete Ġclient `() Ġ{ ĊĠĠĠ Ġduplicate Client Controller . delete Client ( authentication , Ġ" client ") ĊĊĠĠĠ Ġverify ( client Details Service ). remove Client Details (" client ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` delete ĠClient ĠRequest Ġ- Ġdelete Ġclient Ġthrows ĠNoSuch ClientException `() Ġ{ ĊĊĠĠĠ Ġval Ġexception Ġ= ĠNoSuch ClientException (" No Ġclient Ġfound Ġwith Ġid Ġ= Ġ") ĊĠĠĠ Ġdo Throw ( exception ). wh enever ( client Details Service ). remove Client Details ( any String ()) ĊĊĠĠĠ ĠassertThat Thrown By Ġ{ Ġduplicate Client Controller . delete Client ( authentication , Ġ" client ") Ġ}. isEqualTo ( exception ) ĊĠ Ġ} Ċ } Ċ