package Ġde . inst aton ne . backend . services Ċ Ċ import Ġde . inst aton ne . backend . core . repositories . UserRepository Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . assertj . core . api . Assertions . assertThat Thrown By Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . boot . test . context . SpringBootTest Ċ import Ġorg . springframework . transaction . annotation . Transactional Ċ Ċ @ SpringBootTest Ċ @ Transactional Ċ class ĠUserService Test Ġ@ Autowired Ġconstructor ( ĊĠĠĠĠĠĠĠ Ġvar ĠuserService : ĠUserService , ĊĠĠĠĠĠĠĠ Ġvar Ġuser Repository : ĠUser Repository Ċ ) Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġassert Test Isolation () Ġ{ ĊĠĠĠĠĠĠĠ Ġ@ Suppress (" Use Property Access Syntax ") ĊĠĠĠĠĠĠĠ ĠassertThat ( user Repository . exists ById ("* test - id ")). isFalse () ĊĠĠĠĠĠĠĠ Ġ// Ġthis Ġuser Ġis Ġnormally Ġcreated Ġin ĠDB Test Init . kt , ĊĠĠĠĠĠĠĠ Ġ// Ġbut Ġshould Ġnot Ġbe Ġcreated Ġfor Ġtest Ġcases Ġdue Ġto Ġthe Ġactive Ġ' test ' Ġprofile ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfollow Creates Bid irectional Binding () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġuser 1 Ġ= ĠuserService . createUser ("* 1 ", Ġ"* first - user ") ĊĠĠĠĠĠĠĠ Ġval Ġuser 2 Ġ= ĠuserService . createUser ("* 2 ", Ġ"* second - user ") ĊĠĠĠĠĠĠĠ ĠuserService . follow ( user 1 , Ġuser 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġuser 1 R Ġ= Ġuser Repository . findById ( user 1 . id ). get () ĊĠĠĠĠĠĠĠ Ġval Ġuser 2 R Ġ= Ġuser Repository . findById ( user 2 . id ). get () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( user 1 R . following ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains ( user 2 R ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( user 2 R . followers ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains ( user 1 R ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġun following Remov es Bindings () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġuser 1 Ġ= ĠuserService . createUser ("* 1 ", Ġ"* first - user ") ĊĠĠĠĠĠĠĠ Ġval Ġuser 2 Ġ= ĠuserService . createUser ("* 2 ", Ġ"* second - user ") ĊĊĠĠĠĠĠĠĠ ĠuserService . follow ( user 1 , Ġuser 2 ) ĊĠĠĠĠĠĠĠ ĠuserService . un follow ( user 1 , Ġuser 2 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġuser 1 R Ġ= Ġuser Repository . findById ( user 1 . id ). get () ĊĠĠĠĠĠĠĠ Ġval Ġuser 2 R Ġ= Ġuser Repository . findById ( user 2 . id ). get () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( user 1 R . following ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. does Not Contain ( user 2 R ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( user 2 R . followers ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. does Not Contain ( user 1 R ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcreating Two Users With Same Id Is Pro hibited () Ġ{ ĊĠĠĠĠĠĠĠ ĠuserService . createUser ("* 1 ", Ġ"* first - user ") ĊĠĠĠĠĠĠĠ ĠassertThat Thrown By Ġ{ ĠuserService . createUser ("* 1 ", Ġ"* first - double - user ") Ġ}. has Message Containing (" id ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcreating Two Users With Same Username Is Pro hibited () Ġ{ ĊĠĠĠĠĠĠĠ ĠuserService . createUser ("* 1 ", Ġ"* first - user ") ĊĠĠĠĠĠĠĠ ĠassertThat Thrown By Ġ{ ĠuserService . createUser ("* 2 ", Ġ"* first - user ") Ġ}. has Message Containing (" username ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsearch Is Case Ins ensitive () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġusername Ġ= ĠuserService . createUser ("* 1 ", Ġ" username ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( userService . search By Username (" Username ")). contains ( username ) ĊĠĠĠĠĠĠĠ ĠassertThat ( userService . search By Username (" u Ser NA me ")). contains ( username ) ĊĠĠĠĠĠĠĠ ĠassertThat ( userService . search By Username (" username ")). contains ( username ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( userService . search By Username (" cake ")). does Not Contain ( username ) ĊĠĠĠ Ġ} Ċ }