package Ġcom . s ama . connection . infrastructure Ċ Ċ import Ġcom . s ama . common . Base Persistence IT Ċ import Ġcom . s ama . connection . domain . User Connection Ċ import Ġcom . s ama . users . infrastructure . jpa . User Entity Ċ import Ġcom . s ama . users . infrastructure . jpa . User Jpa Repository Ċ import Ġcom . s ama . users . infrastructure . to UserId Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . After Each Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . test . context . Context Configuration Ċ Ċ @ Context Configuration ( classes Ġ= Ġ[ Jdbc User Connection Repository :: class ]) Ċ class ĠJdbc User Connection Repository IT Ġ: ĠBase Persistence IT < Jdbc User Connection Repository >() Ġ{ ĊĊĠĠĠ Ġ@ Autowired ĊĠĠĠ Ġlateinit Ġvar Ġuser Repository : ĠUser Jpa Repository ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġuser One : ĠUser Entity ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġuser Two : ĠUser Entity ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġuser Three : ĠUser Entity ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġuser One Ġ= Ġuser Repository . save ( User Entity (" one @ me ets ama . com ")) ĊĠĠĠĠĠĠĠ Ġuser Two Ġ= Ġuser Repository . save ( User Entity (" two @ me ets ama . com ")) ĊĠĠĠĠĠĠĠ Ġuser Three Ġ= Ġuser Repository . save ( User Entity (" three @ me ets ama . com ")) ĊĠĠĠĠĠĠĠ Ġuser Repository . flush () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After Each ĊĠĠĠ Ġfun Ġcleanup () Ġ{ ĊĠĠĠĠĠĠĠ Ġuser Repository . delete All () ĊĠĠĠĠĠĠĠ Ġuser Repository . flush () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` save Ġand Ġfind Ġconnected Ġuser Ġids `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġuser Connection 1 Ġ= ĠUser Connection ( user One . id !!. to UserId (), Ġuser Two . id !!. to UserId ()) ĊĠĠĠĠĠĠĠ Ġval Ġuser Connection 2 Ġ= ĠUser Connection ( user Three . id !!. to UserId (), Ġuser One . id !!. to UserId ()) ĊĊĠĠĠĠĠĠĠ Ġunder Test . save ( user Connection 1 ) ĊĠĠĠĠĠĠĠ Ġunder Test . save ( user Connection 2 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( under Test . find Connected User Ids ( user One . id !!. to UserId ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains Exactly In Any Order ( user Two . id !!. to UserId (), Ġuser Three . id !!. to UserId ()) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( under Test . find Connected User Ids ( user Two . id !!. to UserId ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains Exactly In Any Order ( user One . id !!. to UserId ()) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( under Test . find Connected User Ids ( user Three . id !!. to UserId ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains Exactly In Any Order ( user One . id !!. to UserId ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` save Ġand Ġcheck Ġif Ġconnection Ġexists `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġuser Connection 1 Ġ= ĠUser Connection ( user One . id !!. to UserId (), Ġuser Two . id !!. to UserId ()) ĊĊĠĠĠĠĠĠĠ Ġunder Test . save ( user Connection 1 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( under Test . exists ( user One . id !!. to UserId (), Ġuser Two . id !!. to UserId ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( under Test . exists ( user One . id !!. to UserId (), Ġuser Three . id !!. to UserId ())). isFalse () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdelete () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġuser Connection 1 Ġ= ĠUser Connection ( user One . id !!. to UserId (), Ġuser Two . id !!. to UserId ()) ĊĠĠĠĠĠĠĠ Ġval Ġuser Connection 2 Ġ= ĠUser Connection ( user One . id !!. to UserId (), Ġuser Three . id !!. to UserId ()) ĊĊĠĠĠĠĠĠĠ Ġunder Test . save ( user Connection 1 ) ĊĠĠĠĠĠĠĠ Ġunder Test . save ( user Connection 2 ) ĊĠĠĠĠĠĠĠ Ġunder Test . delete ( user Connection 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġconnected User Ids Ġ= Ġunder Test . find Connected User Ids ( user One . id !!. to UserId ()) ĊĠĠĠĠĠĠĠ ĠassertThat ( connected User Ids ). contains Exactly ( user Three . id !!. to UserId ()) ĊĠĠĠ Ġ} Ċ }